From 2373bd54fb8f1c3c5bb8e84de7f8a85ed1128057 Mon Sep 17 00:00:00 2001 From: Shijiang Wei Date: Tue, 10 May 2016 17:47:44 +0800 Subject: [PATCH] add go version and git commit sha1 to version string Signed-off-by: Shijiang Wei --- build | 8 +++++++- confd.go | 3 ++- version.go | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/build b/build index 1c8391369..6927af673 100755 --- a/build +++ b/build @@ -2,4 +2,10 @@ echo "Building confd..." mkdir -p bin -go build -o bin/confd . + +GIT_COMMIT=$(git rev-parse --short HEAD) +if [ -n "$(git status --porcelain --untracked-files=no)" ]; then + GIT_COMMIT=${GIT_COMMIT}-dirty +fi + +go build -ldflags "-X main.GitCommit=$GIT_COMMIT" -o bin/confd . diff --git a/confd.go b/confd.go index edf2a0c25..cfb8e50a8 100644 --- a/confd.go +++ b/confd.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/signal" + "runtime" "syscall" "github.com/kelseyhightower/confd/backends" @@ -15,7 +16,7 @@ import ( func main() { flag.Parse() if printVersion { - fmt.Printf("confd %s\n", Version) + fmt.Printf("confd %s (Git commit: %s, Go version: %s)\n", Version, GitCommit, runtime.Version()) os.Exit(0) } if err := initConfig(); err != nil { diff --git a/version.go b/version.go index dfaa8e950..792c46b0f 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,6 @@ package main const Version = "0.12.0-dev" + +// We want to replace this variable at build time with "-ldflags -X main.GitCommit=xxx", where const is not supported. +var GitCommit = ""