From 7048532bc4adcc017739fae358fd6b6c44b63ebd Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 1 Oct 2020 16:09:11 +0100 Subject: [PATCH] Update version imprinting (#1462) * Add version tag constant * Update build imprinting --- build.sh | 12 +++++++++--- internal/version.go | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 34e4b115..f790077e 100755 --- a/build.sh +++ b/build.sh @@ -3,10 +3,16 @@ # Put installed packages into ./bin export GOBIN=$PWD/`dirname $0`/bin -export BRANCH=`(git symbolic-ref --short HEAD | cut -d'/' -f 3 )|| ""` -export BUILD=`git rev-parse --short HEAD || ""` +if [ -d ".git" ] +then + export BUILD=`git rev-parse --short HEAD || ""` + export BRANCH=`(git symbolic-ref --short HEAD | tr -d \/ ) || ""` + [[ $BRANCH == "master" ]] && export BRANCH="" -export FLAGS="-X github.com/matrix-org/dendrite/internal.branch=$BRANCH -X github.com/matrix-org/dendrite/internal.build=$BUILD" + export FLAGS="-X github.com/matrix-org/dendrite/internal.branch=$BRANCH -X github.com/matrix-org/dendrite/internal.build=$BUILD" +else + export FLAGS="" +fi go install -trimpath -ldflags "$FLAGS" -v $PWD/`dirname $0`/cmd/... diff --git a/internal/version.go b/internal/version.go index 851a0938..718273e7 100644 --- a/internal/version.go +++ b/internal/version.go @@ -12,10 +12,11 @@ const ( VersionMajor = 0 VersionMinor = 0 VersionPatch = 0 + VersionTag = "" // example: "rc1" ) func VersionString() string { - version := fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch) + version := fmt.Sprintf("%d.%d.%d%s", VersionMajor, VersionMinor, VersionPatch, VersionTag) if branch != "" { version += fmt.Sprintf("-%s", branch) }