From a4c546f47d8063618ecb3c91e6bf4061ce86f7d2 Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@monax.io> Date: Fri, 30 Mar 2018 12:55:06 +0100 Subject: [PATCH] Add commit version to binary Signed-off-by: Silas Davis <silas@monax.io> --- Makefile | 3 ++- cmd/burrow/main.go | 2 +- project/history.go | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ba7048e3..1ae718c5 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ SHELL := /bin/bash REPO := $(shell pwd) GOFILES_NOVENDOR := $(shell go list -f "{{.Dir}}" ./...) PACKAGES_NOVENDOR := $(shell go list ./...) +COMMIT := $(shell git rev-parse --short HEAD) # Bosmarmot integration testing BOSMARMOT_PROJECT := github.com/monax/bosmarmot BOSMARMOT_GOPATH := ${REPO}/.gopath_bos @@ -99,7 +100,7 @@ build_race: check build_race_db build_race_client # build burrow .PHONY: build_db build_db: - go build -o ${REPO}/bin/burrow ./cmd/burrow + go build -ldflags "-X github.com/hyperledger/burrow/project.commit=${COMMIT}" -o ${REPO}/bin/burrow ./cmd/burrow # build burrow-client .PHONY: build_client diff --git a/cmd/burrow/main.go b/cmd/burrow/main.go index d7d56f08..61c270ae 100644 --- a/cmd/burrow/main.go +++ b/cmd/burrow/main.go @@ -34,7 +34,7 @@ func main() { burrow.Action = func() { if *versionOpt { - fmt.Println(project.History.CurrentVersion().String()) + fmt.Println(project.FullVersion()) os.Exit(0) } // We need to reflect on whether this obscures where values are coming from diff --git a/project/history.go b/project/history.go index 96fb36e6..d4d1b5ae 100644 --- a/project/history.go +++ b/project/history.go @@ -4,6 +4,23 @@ import ( "github.com/monax/relic" ) +// Can be used to set the commit hash version of the binary at build time with: +// `go build -ldflags "-X github.com/hyperledger/burrow/project.commit=$(git rev-parse --short HEAD)" ./cmd/burrow` + +var commit = "" + +func Commit() string { + return commit +} + +func FullVersion() string { + version := History.CurrentVersion().String() + if commit != "" { + return version + "+commit." + commit + } + return version +} + // The releases described by version string and changes, newest release first. // The current release is taken to be the first release in the slice, and its // version determines the single authoritative version for the next release. -- GitLab