diff --git a/Makefile b/Makefile index 5a24d90c..1aa96136 100644 --- a/Makefile +++ b/Makefile @@ -18,15 +18,16 @@ RELEASE_DARWIN_AMD64 = $(RELEASE_ROOT)/darwin-amd64/$(PROJECT) RELEASE_DARWIN_ARM64 = $(RELEASE_ROOT)/darwin-arm64/$(PROJECT) RELEASE_WINDOWS_AMD64 = $(RELEASE_ROOT)/windows-amd64/$(PROJECT) -BUILD_VERSION := $(shell git describe --tags --always | cut -f 1 -f 2 -d "-") -BUILD_DATE := $(shell date +'%Y-%m-%d %H:%M:%S') +BUILD_VERSION := $(shell git describe --tags --always) +BUILD_DATE := $(shell date +'%Y-%m-%d %H:%M:%S %Z') SHA_SHORT := $(shell git rev-parse --short HEAD) -TAGS = "" MOD_NAME = github.com/rocboss/paopao-ce LDFLAGS = -X "${MOD_NAME}/pkg/version.version=${BUILD_VERSION}" \ -X "${MOD_NAME}/pkg/version.buildDate=${BUILD_DATE}" \ - -X "${MOD_NAME}/pkg/version.commitID=${SHA_SHORT}" -w -s + -X "${MOD_NAME}/pkg/version.commitID=${SHA_SHORT}" \ + -X "${MOD_NAME}/pkg/version.buildTags=${TAGS}" \ + -w -s all: fmt build diff --git a/build-image.sh b/build-image.sh index dba722d3..f30affde 100755 --- a/build-image.sh +++ b/build-image.sh @@ -2,7 +2,7 @@ # eg.1 : sh build-image.sh # eg.2, set image: sh build-image.sh bitbus/paopao-ce -VERSION=`git describe --tags --always | cut -f1 -f2 -d "-"` # eg.: 0.2.5 +VERSION=`git describe --tags --always | cut -f1,2 -d "-"` # eg.: 0.2.5 IMAGE="bitbus/paopao-ce" if [ -n "$1" ]; then diff --git a/pkg/version/version.go b/pkg/version/version.go index ce30181c..5a4dbcf5 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -8,25 +8,35 @@ import ( "fmt" ) -var version, commitID, buildDate string +const ( + series = "v0.5.0-dev" +) + +var ( + version = "unknown" + commitID = "unknown" + buildDate = "unknown" + buildTags = "unknown" +) type BuildInfo struct { + Series string `json:"series"` Version string `json:"version"` Sum string `json:"sum"` BuildDate string `json:"build_date"` + BuildTags string `json:"build_tags"` } func VersionInfo() string { - return fmt.Sprintf("paopao %s (build:%s %s)", version, commitID, buildDate) + return fmt.Sprintf("paopao %s (build:%s %s)", series, commitID, buildDate) } func ReadBuildInfo() *BuildInfo { - if version == "" { - version = "unknow" - } return &BuildInfo{ + Series: series, Version: version, Sum: commitID, BuildDate: buildDate, + BuildTags: buildTags, } }