Skip to content

Commit

Permalink
Merge pull request kelseyhightower#445 from mountkin/version-enhancement
Browse files Browse the repository at this point in the history
add go version and git commit sha1 to version string
  • Loading branch information
okushchenko committed Oct 9, 2017
2 parents 8f05281 + 2373bd5 commit 6da4394
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
3 changes: 2 additions & 1 deletion confd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"

"github.com/kelseyhightower/confd/backends"
Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package main

const Version = "0.14.0-dev"

// We want to replace this variable at build time with "-ldflags -X main.GitCommit=xxx", where const is not supported.
var GitCommit = ""

0 comments on commit 6da4394

Please sign in to comment.