From 9264aa6293e95c48b51983c60d825521aca064b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=94=AE=E5=86=AC?= Date: Mon, 11 May 2020 20:23:53 +0800 Subject: [PATCH] Version management (#141) * Provide a better version management approach * Fix typo --- control | 7 +++++-- src/modules/collector/collector.go | 13 +++++++------ src/modules/index/index.go | 10 +++++++--- src/modules/judge/judge.go | 10 +++++++--- src/modules/monapi/monapi.go | 8 +++++++- src/modules/transfer/transfer.go | 10 +++++++--- src/modules/tsdb/tsdb.go | 10 +++++++--- 7 files changed, 47 insertions(+), 21 deletions(-) diff --git a/control b/control index 4a1e97d0..665495b8 100755 --- a/control +++ b/control @@ -1,5 +1,8 @@ #!/bin/bash +# release version +version=1.3.3 + CWD=$(cd $(dirname $0)/; pwd) cd $CWD @@ -136,13 +139,13 @@ status() build_one() { mod=$1 - go build -mod=vendor -o n9e-${mod} --tags "md5" src/modules/${mod}/${mod}.go + go build -ldflags "-X main.version=${version} -X main.buildTime=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitHash=`git rev-parse HEAD`" -mod=vendor -o n9e-${mod} --tags "md5" src/modules/${mod}/${mod}.go } build_docker() { mod=$1 - go build -mod=vendor -o bin/n9e-${mod} --tags "md5" src/modules/${mod}/${mod}.go + go build -ldflags "-X main.version=${version} -X main.buildTime=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitHash=`git rev-parse HEAD`" -mod=vendor -o bin/n9e-${mod} --tags "md5" src/modules/${mod}/${mod}.go } build() diff --git a/src/modules/collector/collector.go b/src/modules/collector/collector.go index 425edb46..2271656b 100644 --- a/src/modules/collector/collector.go +++ b/src/modules/collector/collector.go @@ -28,15 +28,14 @@ import ( "github.com/toolkits/pkg/runner" ) -// changelog: -// 1: init project -// 2: mount ignore refactor -const version = 2 - var ( vers *bool help *bool conf *string + + version = "No Version Provided" + gitHash = "No GitHash Provided" + buildTime = "No BuildTime Provided" ) func init() { @@ -46,7 +45,9 @@ func init() { flag.Parse() if *vers { - fmt.Println("version:", version) + fmt.Println("Version:", version) + fmt.Println("Git Commit Hash:", gitHash) + fmt.Println("UTC Build Time:", buildTime) os.Exit(0) } diff --git a/src/modules/index/index.go b/src/modules/index/index.go index 73f8c7e5..28a4930c 100644 --- a/src/modules/index/index.go +++ b/src/modules/index/index.go @@ -23,12 +23,14 @@ import ( "github.com/toolkits/pkg/runner" ) -const version = 1 - var ( vers *bool help *bool conf *string + + version = "No Version Provided" + gitHash = "No GitHash Provided" + buildTime = "No BuildTime Provided" ) func init() { @@ -38,7 +40,9 @@ func init() { flag.Parse() if *vers { - fmt.Println("version:", version) + fmt.Println("Version:", version) + fmt.Println("Git Commit Hash:", gitHash) + fmt.Println("UTC Build Time:", buildTime) os.Exit(0) } diff --git a/src/modules/judge/judge.go b/src/modules/judge/judge.go index 6468bf04..26bcebca 100644 --- a/src/modules/judge/judge.go +++ b/src/modules/judge/judge.go @@ -27,12 +27,14 @@ import ( "github.com/didi/nightingale/src/toolkits/stats" ) -const version = 1 - var ( vers *bool help *bool conf *string + + version = "No Version Provided" + gitHash = "No GitHash Provided" + buildTime = "No BuildTime Provided" ) func init() { @@ -42,7 +44,9 @@ func init() { flag.Parse() if *vers { - fmt.Println("version:", version) + fmt.Println("Version:", version) + fmt.Println("Git Commit Hash:", gitHash) + fmt.Println("UTC Build Time:", buildTime) os.Exit(0) } diff --git a/src/modules/monapi/monapi.go b/src/modules/monapi/monapi.go index f7a0516d..7f6409f4 100644 --- a/src/modules/monapi/monapi.go +++ b/src/modules/monapi/monapi.go @@ -28,6 +28,10 @@ var ( vers *bool help *bool conf *string + + version = "No Version Provided" + gitHash = "No GitHash Provided" + buildTime = "No BuildTime Provided" ) func init() { @@ -37,7 +41,9 @@ func init() { flag.Parse() if *vers { - fmt.Println("version:", config.Version) + fmt.Println("Version:", version) + fmt.Println("Git Commit Hash:", gitHash) + fmt.Println("UTC Build Time:", buildTime) os.Exit(0) } diff --git a/src/modules/transfer/transfer.go b/src/modules/transfer/transfer.go index a292e230..6b9f46de 100644 --- a/src/modules/transfer/transfer.go +++ b/src/modules/transfer/transfer.go @@ -22,12 +22,14 @@ import ( "github.com/toolkits/pkg/runner" ) -const version = 1 - var ( vers *bool help *bool conf *string + + version = "No Version Provided" + gitHash = "No GitHash Provided" + buildTime = "No BuildTime Provided" ) func init() { @@ -37,7 +39,9 @@ func init() { flag.Parse() if *vers { - fmt.Println("version:", version) + fmt.Println("Version:", version) + fmt.Println("Git Commit Hash:", gitHash) + fmt.Println("UTC Build Time:", buildTime) os.Exit(0) } diff --git a/src/modules/tsdb/tsdb.go b/src/modules/tsdb/tsdb.go index fb3e39a2..cc6ad6ad 100644 --- a/src/modules/tsdb/tsdb.go +++ b/src/modules/tsdb/tsdb.go @@ -23,12 +23,14 @@ import ( "github.com/toolkits/pkg/runner" ) -const version = 1 - var ( vers *bool help *bool conf *string + + version = "No Version Provided" + gitHash = "No GitHash Provided" + buildTime = "No BuildTime Provided" ) func init() { @@ -38,7 +40,9 @@ func init() { flag.Parse() if *vers { - fmt.Println("version:", version) + fmt.Println("Version:", version) + fmt.Println("Git Commit Hash:", gitHash) + fmt.Println("UTC Build Time:", buildTime) os.Exit(0) }