diff --git a/Makefile b/Makefile index aff6d531c..4c73e6ab7 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,7 @@ GIT_BRANCH_CLEAN := $(shell echo $(GIT_BRANCH) | sed -e "s/[^[:alnum:]]/-/g") RUNC_IMAGE := runc_dev$(if $(GIT_BRANCH_CLEAN),:$(GIT_BRANCH_CLEAN)) PROJECT := github.com/opencontainers/runc BUILDTAGS ?= seccomp -COMMIT_NO := $(shell git rev-parse HEAD 2> /dev/null || true) -COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),"$(COMMIT_NO)-dirty","$(COMMIT_NO)") +COMMIT ?= $(shell git describe --dirty --long --always) VERSION := $(shell cat ./VERSION) # TODO: rm -mod=vendor once go 1.13 is unsupported diff --git a/main.go b/main.go index 328ea30c7..ba5e3c828 100644 --- a/main.go +++ b/main.go @@ -15,9 +15,9 @@ import ( "github.com/urfave/cli" ) -// version will be populated by the Makefile, read from -// VERSION file of the source code. -var version = "" +// version must be set from the contents of VERSION file by go build's +// -X main.version= option in the Makefile. +var version = "unknown" // gitCommit will be the hash that the binary was built from // and will be populated by the Makefile @@ -55,10 +55,8 @@ func main() { app.Name = "runc" app.Usage = usage - var v []string - if version != "" { - v = append(v, version) - } + v := []string{version} + if gitCommit != "" { v = append(v, "commit: "+gitCommit) }