diff --git a/Makefile b/Makefile index 79135a1d26f1dd05808f078785b39e756021b593..41b3d177c32a87f79defe28b7c3a7f6856de6234 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,9 @@ NAME := jcli CGO_ENABLED = 0 GO := go 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 darwin: ## Build for OSX diff --git a/app/cmd/root.go b/app/cmd/root.go index 543df7400bc87d5c9e21fae2acc2f0aceeb409ab..e1fad23d9300832c867cd117137b99aadba7ebf9 100644 --- a/app/cmd/root.go +++ b/app/cmd/root.go @@ -30,9 +30,8 @@ var rootCmd = &cobra.Command{ } if rootOptions.Version { - fmt.Printf("Version: v%.2f.%d%s", app.CurrentVersion.Number, - app.CurrentVersion.PatchLevel, - app.CurrentVersion.Suffix) + fmt.Printf("Version: %s\n", app.GetVersion()) + fmt.Printf("Commit: %s\n", app.GetCommit()) } }, } diff --git a/app/version.go b/app/version.go index 83ea23b32934b3e5c57773708e33c655406067d3..6941cc77689e5b5cca04ce4ace65e9e98f27b09c 100644 --- a/app/version.go +++ b/app/version.go @@ -1,14 +1,14 @@ package app -// Version represents the Jenkins CLI build version. -type Version struct { - // Major and minor version. - Number float32 +var ( + version string + commit string +) - // Increment this for bug releases - PatchLevel int +func GetVersion() string { + return version +} - // JCLI Suffix is the suffix used in the Jenkins CLI version string. - // It will be blank for release versions. - Suffix string +func GetCommit() string { + return commit } diff --git a/app/version_current.go b/app/version_current.go deleted file mode 100644 index aacda66e383f33847d8226eb975387cb62a4186f..0000000000000000000000000000000000000000 --- a/app/version_current.go +++ /dev/null @@ -1,9 +0,0 @@ -package app - -// CurrentVersion represents the current build version. -// This should be the only one. -var CurrentVersion = Version{ - Number: 0.0, - PatchLevel: 9, - Suffix: "-DEV", -} diff --git a/release.sh b/release.sh index 9a9c68b58082c9233cb88673d1cf1c6695dc5fbc..46e4189150ac40d4e7bf212646770dc1457dd77c 100755 --- a/release.sh +++ b/release.sh @@ -15,7 +15,7 @@ echo "Updating $VERSION to $NEW_TAG" # NEEDS_TAG=`git describe --contains $GIT_COMMIT` if [[ -z "${NEEDS_TAG}" ]]; then - make release + make release VERSION=${NEW_TAG} hub release create -c -a release/jcli-darwin-amd64.tar.gz \ -a release/jcli-linux-amd64.tar.gz \ -a release/jcli-windows-386.tar.gz ${NEW_TAG}