diff --git a/Makefile b/Makefile index 4742e82..a7467f9 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ .PHONY: build build-alpine clean test help default docker-build BIN_NAME=bashhub-server - -VERSION := $(shell grep "const Version " version/version.go | sed -E 's/.*"(.+)"$$/\1/') +VERSION=$(shell git tag | sort --version-sort -r | head -1) GIT_COMMIT=$(shell git rev-parse HEAD) GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true) BUILD_DATE=$(shell date '+%Y-%m-%d-%H:%M:%S') @@ -27,7 +26,7 @@ help: build: @echo "building ${BIN_NAME} ${VERSION}" @echo "GOPATH=${GOPATH}" - go build -ldflags "-X github.com/nicksherron/bashhub-server/cmd.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/nicksherron/bashhub-server/cmd.BuildDate=${BUILD_DATE}" -o bin/${BIN_NAME} + go build -ldflags "-X github.com/nicksherron/bashhub-server/cmd.Version=${VERSION} -X github.com/nicksherron/bashhub-server/cmd.GitCommit=${GIT_COMMIT} -X github.com/nicksherron/bashhub-server/cmd.BuildDate=${BUILD_DATE}" -o bin/${BIN_NAME} get-deps: dep ensure diff --git a/cmd/version.go b/cmd/version.go index f766b3a..fed640c 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -25,7 +25,7 @@ import ( // versionCmd represents the version command var ( - Build string + GitCommit string BuildDate string Version string OsArch = fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH) @@ -36,7 +36,7 @@ var ( Short: "Print the version number and build info", Run: func(cmd *cobra.Command, args []string) { fmt.Println("Build Date:", BuildDate) - fmt.Println("Git Commit:", Build) + fmt.Println("Git Commit:", GitCommit) fmt.Println("Version:", Version) fmt.Println("Go Version:", GoVersion) fmt.Println("OS / Arch:", OsArch)