diff --git a/build.sh b/build.sh index 2a84b54..cc18f7c 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,9 @@ #!/bin/sh +VersionPath="github.com/zhaojh329/rttys/version" +GitCommit=$(git log --pretty=format:"%h" -1) +BuildTime=$(date +%FT%T%z) + generate() { local os="$1" local arch="$2" @@ -14,7 +18,7 @@ generate() { bin="rttys.exe" } - GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -ldflags='-s -w' -o output/$dir/$bin + GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -ldflags="-s -w -X $VersionPath.gitCommit=$GitCommit -X $VersionPath.buildTime=$BuildTime" -o output/$dir/$bin cd output diff --git a/main.go b/main.go index 90ce02d..38b656a 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ import ( "time" "github.com/kylelemons/go-gypsy/yaml" + "github.com/zhaojh329/rttys/version" "github.com/howeyc/gopass" "github.com/rifflock/lfshook" @@ -63,8 +64,12 @@ func main() { os.Exit(1) } - log.Infof("go version: %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH) - log.Info("rttys version:", rttys_version()) + log.Info("Go Version: ", runtime.Version()) + log.Info("Go OS/Arch: ", runtime.GOOS, "/", runtime.GOARCH) + + log.Info("Rttys Version: ", version.Version()) + log.Info("Git Commit: ", version.GitCommit()) + log.Info("Build Time: ", version.BuildTime()) br := newBroker() go br.run() diff --git a/version.go b/version.go deleted file mode 100644 index 7338c37..0000000 --- a/version.go +++ /dev/null @@ -1,13 +0,0 @@ -package main - -import "fmt" - -const ( - RTTYS_VERSION_MAJOR = 2 - RTTYS_VERSION_MINOR = 10 - RTTYS_VERSION_PATCH = 0 -) - -func rttys_version() string { - return fmt.Sprintf("%d.%d.%d", RTTYS_VERSION_MAJOR, RTTYS_VERSION_MINOR, RTTYS_VERSION_PATCH) -} diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..5bed2fe --- /dev/null +++ b/version/version.go @@ -0,0 +1,20 @@ +package version + +const version = "2.10.0" + +var ( + gitCommit = "" + buildTime = "" +) + +func Version() string { + return version +} + +func GitCommit() string { + return gitCommit +} + +func BuildTime() string { + return buildTime +}