From 3a4413870fd72b4f8902c9e119783be3a47d943c Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 7 Dec 2023 15:22:17 +0100 Subject: [PATCH] Include git commit in version Signed-off-by: Tim Vaillancourt --- build.sh | 5 ++++- go/cmd/gh-ost/main.go | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index b75891553..ea83ce5b6 100755 --- a/build.sh +++ b/build.sh @@ -55,11 +55,14 @@ main() { RELEASE_VERSION=$(cat RELEASE_VERSION) fi + if [ -z "${GIT_COMMIT}" ]; then + GIT_COMMIT=$(git rev-parse HEAD) + fi buildpath=/tmp/gh-ost-release target=gh-ost timestamp=$(date "+%Y%m%d%H%M%S") - ldflags="-X main.AppVersion=${RELEASE_VERSION}" + ldflags="-X main.AppVersion=${RELEASE_VERSION} -X main.GitCommit=${GIT_COMMIT}" mkdir -p ${buildpath} rm -rf ${buildpath:?}/* diff --git a/go/cmd/gh-ost/main.go b/go/cmd/gh-ost/main.go index 926223293..dae57b414 100644 --- a/go/cmd/gh-ost/main.go +++ b/go/cmd/gh-ost/main.go @@ -22,7 +22,7 @@ import ( "golang.org/x/term" ) -var AppVersion string +var AppVersion, GitCommit string // acceptSignals registers for OS signals func acceptSignals(migrationContext *base.MigrationContext) { @@ -165,7 +165,7 @@ func main() { if appVersion == "" { appVersion = "unversioned" } - fmt.Println(appVersion) + fmt.Printf("gh-ost version: %s, git commit: %s", appVersion, GitCommit) return } @@ -308,7 +308,7 @@ func main() { migrationContext.Log.Errore(err) } - log.Infof("starting gh-ost %+v", AppVersion) + log.Infof("starting gh-ost %+v (git commit: %s)", AppVersion, GitCommit) acceptSignals(migrationContext) migrator := logic.NewMigrator(migrationContext, AppVersion)