Skip to content

Commit bcc2920

Browse files
author
Zhao Xiaojie
authored
Merge pull request #55 from LinuxSuRen/version
Add support to print version of app
2 parents 914ebab + c20085a commit bcc2920

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ NAME := jcli
22
CGO_ENABLED = 0
33
GO := go
44
BUILD_TARGET = build
5-
BUILDFLAGS =
5+
COMMIT := $(shell git rev-parse --short HEAD)
6+
VERSION := dev-$(shell git describe --tags $(shell git rev-list --tags --max-count=1))
7+
BUILDFLAGS = -ldflags "-X github.com/linuxsuren/jenkins-cli/app.version=$(VERSION) -X github.com/linuxsuren/jenkins-cli/app.commit=$(COMMIT)"
68
COVERED_MAIN_SRC_FILE=./main
79

810
darwin: ## Build for OSX

app/cmd/root.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ var rootCmd = &cobra.Command{
3030
}
3131

3232
if rootOptions.Version {
33-
fmt.Printf("Version: v%.2f.%d%s", app.CurrentVersion.Number,
34-
app.CurrentVersion.PatchLevel,
35-
app.CurrentVersion.Suffix)
33+
fmt.Printf("Version: %s\n", app.GetVersion())
34+
fmt.Printf("Commit: %s\n", app.GetCommit())
3635
}
3736
},
3837
}

app/version.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package app
22

3-
// Version represents the Jenkins CLI build version.
4-
type Version struct {
5-
// Major and minor version.
6-
Number float32
3+
var (
4+
version string
5+
commit string
6+
)
77

8-
// Increment this for bug releases
9-
PatchLevel int
8+
func GetVersion() string {
9+
return version
10+
}
1011

11-
// JCLI Suffix is the suffix used in the Jenkins CLI version string.
12-
// It will be blank for release versions.
13-
Suffix string
12+
func GetCommit() string {
13+
return commit
1414
}

app/version_current.go

-9
This file was deleted.

release.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ echo "Updating $VERSION to $NEW_TAG"
1515
# NEEDS_TAG=`git describe --contains $GIT_COMMIT`
1616

1717
if [[ -z "${NEEDS_TAG}" ]]; then
18-
make release
18+
make release VERSION=${NEW_TAG}
1919
hub release create -c -a release/jcli-darwin-amd64.tar.gz \
2020
-a release/jcli-linux-amd64.tar.gz \
2121
-a release/jcli-windows-386.tar.gz ${NEW_TAG}

0 commit comments

Comments
 (0)