From 3a1e1bcd79bb5bbe76c572e41be73fbdb458fe41 Mon Sep 17 00:00:00 2001 From: Quanzheng Long Date: Tue, 6 Apr 2021 20:31:23 -0700 Subject: [PATCH] Expose server version tag to be set during build time --- cmd/server/cadence/cadence.go | 4 ++-- cmd/server/main.go | 3 ++- scripts/go-build-ldflags.sh | 9 ++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/server/cadence/cadence.go b/cmd/server/cadence/cadence.go index 668c1ac3578..601a7e922ef 100644 --- a/cmd/server/cadence/cadence.go +++ b/cmd/server/cadence/cadence.go @@ -158,12 +158,12 @@ func constructPathIfNeed(dir string, file string) string { } // BuildCLI is the main entry point for the cadence server -func BuildCLI() *cli.App { +func BuildCLI(version string, revision string) *cli.App { app := cli.NewApp() app.Name = "cadence" app.Usage = "Cadence server" - app.Version = "0.0.1" + app.Version = version + "-" + revision app.Flags = []cli.Flag{ cli.StringFlag{ diff --git a/cmd/server/main.go b/cmd/server/main.go index 79421161d72..75b95a7c998 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -24,12 +24,13 @@ import ( "os" "github.com/uber/cadence/cmd/server/cadence" + "github.com/uber/cadence/common/metrics" _ "github.com/uber/cadence/common/persistence/sql/sqlplugin/mysql" // needed to load mysql plugin _ "github.com/uber/cadence/common/persistence/sql/sqlplugin/postgres" // needed to load postgres plugin ) // main entry point for the cadence server func main() { - app := cadence.BuildCLI() + app := cadence.BuildCLI(metrics.Version, metrics.Revision) app.Run(os.Args) } diff --git a/scripts/go-build-ldflags.sh b/scripts/go-build-ldflags.sh index 6840b216255..5a1f882242b 100755 --- a/scripts/go-build-ldflags.sh +++ b/scripts/go-build-ldflags.sh @@ -9,10 +9,17 @@ fi export GIT_REVISION=$(git rev-parse --short HEAD) export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) -export GIT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo unknown) export BUILD_DATE=$(date '+%F-%T') # outputs something in this format 2017-08-21-18:58:45 export BUILD_TS_UNIX=$(date '+%s') # second since epoch export BASE_PACKAGE=github.com/uber/cadence/common/metrics +if [ -z ${SERVER_VERSION} ]; then + # If not set SERVER_VERSION, then use the most recent tag. + export GIT_VERSION=$(git describe --tags --abbrev=0 --dirty 2>/dev/null || echo unknown) +else + # If passing a version explicitly, then use it + export GIT_VERSION=${SERVER_VERSION} +fi + if [ "$MODE" = "LDFLAG" ]; then LD_FLAGS="-X ${BASE_PACKAGE}.Revision=${GIT_REVISION} \