提交 c20085a8 编写于 作者: LinuxSuRen's avatar LinuxSuRen

Add support to print version of app

上级 6afad2e1
...@@ -2,7 +2,9 @@ NAME := jcli ...@@ -2,7 +2,9 @@ NAME := jcli
CGO_ENABLED = 0 CGO_ENABLED = 0
GO := go GO := go
BUILD_TARGET = build BUILD_TARGET = build
BUILDFLAGS = COMMIT := $(shell git rev-parse --short HEAD)
VERSION := dev-$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
BUILDFLAGS = -ldflags "-X github.com/linuxsuren/jenkins-cli/app.version=$(VERSION) -X github.com/linuxsuren/jenkins-cli/app.commit=$(COMMIT)"
COVERED_MAIN_SRC_FILE=./main COVERED_MAIN_SRC_FILE=./main
darwin: ## Build for OSX darwin: ## Build for OSX
......
...@@ -30,9 +30,8 @@ var rootCmd = &cobra.Command{ ...@@ -30,9 +30,8 @@ var rootCmd = &cobra.Command{
} }
if rootOptions.Version { if rootOptions.Version {
fmt.Printf("Version: v%.2f.%d%s", app.CurrentVersion.Number, fmt.Printf("Version: %s\n", app.GetVersion())
app.CurrentVersion.PatchLevel, fmt.Printf("Commit: %s\n", app.GetCommit())
app.CurrentVersion.Suffix)
} }
}, },
} }
......
package app package app
// Version represents the Jenkins CLI build version. var (
type Version struct { version string
// Major and minor version. commit string
Number float32 )
// Increment this for bug releases func GetVersion() string {
PatchLevel int return version
}
// JCLI Suffix is the suffix used in the Jenkins CLI version string. func GetCommit() string {
// It will be blank for release versions. return commit
Suffix string
} }
package app
// CurrentVersion represents the current build version.
// This should be the only one.
var CurrentVersion = Version{
Number: 0.0,
PatchLevel: 9,
Suffix: "-DEV",
}
...@@ -15,7 +15,7 @@ echo "Updating $VERSION to $NEW_TAG" ...@@ -15,7 +15,7 @@ echo "Updating $VERSION to $NEW_TAG"
# NEEDS_TAG=`git describe --contains $GIT_COMMIT` # NEEDS_TAG=`git describe --contains $GIT_COMMIT`
if [[ -z "${NEEDS_TAG}" ]]; then if [[ -z "${NEEDS_TAG}" ]]; then
make release make release VERSION=${NEW_TAG}
hub release create -c -a release/jcli-darwin-amd64.tar.gz \ hub release create -c -a release/jcli-darwin-amd64.tar.gz \
-a release/jcli-linux-amd64.tar.gz \ -a release/jcli-linux-amd64.tar.gz \
-a release/jcli-windows-386.tar.gz ${NEW_TAG} -a release/jcli-windows-386.tar.gz ${NEW_TAG}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册