Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to print version of app #55

Merged
merged 1 commit into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions app/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
},
}
Expand Down
18 changes: 9 additions & 9 deletions app/version.go
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 0 additions & 9 deletions app/version_current.go

This file was deleted.

2 changes: 1 addition & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down