From 9dd20346018f8c8f8f78eeb881a3f42a2af371ee Mon Sep 17 00:00:00 2001 From: James Phillips Date: Fri, 1 Sep 2017 14:24:59 -0700 Subject: [PATCH 1/2] Add prerelease flag for specifying alpha/beta/RC builds --- agent/cmd/start.go | 2 +- backend/cmd/start.go | 2 +- build.sh | 6 +++--- cli/cmd/start.go | 2 +- version/prerelease.txt | 1 + version/version.go | 19 +++++++++++++++++++ version/version.txt | 2 +- 7 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 version/prerelease.txt diff --git a/agent/cmd/start.go b/agent/cmd/start.go index edb81adb3f..6d6aff4604 100644 --- a/agent/cmd/start.go +++ b/agent/cmd/start.go @@ -58,7 +58,7 @@ func newVersionCommand() *cobra.Command { Short: "Show the sensu-agent version information", Run: func(cmd *cobra.Command, args []string) { fmt.Printf("sensu-agent version %s, build %s, built %s\n", - version.Version, + version.Semver(), version.BuildSHA, version.BuildDate, ) diff --git a/backend/cmd/start.go b/backend/cmd/start.go index 9b2dc5e5a0..398870a1a4 100644 --- a/backend/cmd/start.go +++ b/backend/cmd/start.go @@ -55,7 +55,7 @@ func newVersionCommand() *cobra.Command { Short: "Show the sensu-backend version information", Run: func(cmd *cobra.Command, args []string) { fmt.Printf("sensu-backend version %s, build %s, built %s\n", - version.Version, + version.Semver(), version.BuildSHA, version.BuildDate, ) diff --git a/build.sh b/build.sh index 1d8d0eb8b1..a3ad5359a5 100755 --- a/build.sh +++ b/build.sh @@ -78,13 +78,13 @@ build_binary () { local outfile="target/${goos}-${goarch}/${cmd_name}" local version=$(cat version/version.txt) - local iteration=$(cat version/iteration.txt) + local prerelease=$(cat version/prerelease.txt) local build_date=$(date +"%Y-%m-%dT%H:%M:%S%z") local build_sha=$(git rev-parse HEAD) local version_pkg="github.com/sensu/sensu-go/version" - local ldflags="-X $version_pkg.Version=${version}" - local ldflags+=" -X $version_pkg.Iteration=${iteration}" + local ldflags=" -X $version_pkg.Version=${version}" + local ldflags+=" -X $version_pkg.PreReleaseIdentifier=${prerelease}" local ldflags+=" -X $version_pkg.BuildDate=${build_date}" local ldflags+=" -X $version_pkg.BuildSHA=${build_sha}" diff --git a/cli/cmd/start.go b/cli/cmd/start.go index 1afe61dd97..65a3592e07 100644 --- a/cli/cmd/start.go +++ b/cli/cmd/start.go @@ -63,7 +63,7 @@ func newVersionCommand() *cobra.Command { Short: "Show the sensu-ctl version information", Run: func(cmd *cobra.Command, args []string) { fmt.Printf("sensu-ctl version %s, build %s, built %s\n", - version.Version, + version.Semver(), version.BuildSHA, version.BuildDate, ) diff --git a/version/prerelease.txt b/version/prerelease.txt new file mode 100644 index 0000000000..26d9eb97b6 --- /dev/null +++ b/version/prerelease.txt @@ -0,0 +1 @@ +alpha.1 diff --git a/version/version.go b/version/version.go index a0bb355deb..3b3959bb5a 100644 --- a/version/version.go +++ b/version/version.go @@ -4,9 +4,28 @@ var ( // Version stores the version of the current build (e.g. 2.0.0) Version string + // PreReleaseIdentifier stores the pre-release identifier of the current build (eg. beta-2) + PreReleaseIdentifier string + // BuildDate stores the timestamp of the build (e.g. 2017-07-31T13:11:15-0700) BuildDate string // BuildSHA stores the git sha of the build (e.g. 8673bed0a9705083987b9ecbbc1cc0758df13dd2) BuildSHA string ) + +// Semver returns full semantic versioning compatible identifier. +// Format: VERSION-PRERELEASE+METADATA +func Semver() string { + version := Version + if PreReleaseIdentifier != "" { + version = version + "-" + PreReleaseIdentifier + } + + gitSHA := BuildSHA + if len(gitSHA) > 7 { + gitSHA = gitSHA[:7] + } + + return version + "#" + gitSHA +} diff --git a/version/version.txt b/version/version.txt index dad1dc7ed9..227cea2156 100644 --- a/version/version.txt +++ b/version/version.txt @@ -1 +1 @@ -2.0.0p1 +2.0.0 From cb9ca239c362d8787956ac21cbfb57383bcbf7bd Mon Sep 17 00:00:00 2001 From: James Phillips Date: Fri, 1 Sep 2017 14:43:28 -0700 Subject: [PATCH 2/2] reference prerelease identifier in Makefile --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2c2193639b..9e1cd5d269 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ $(shell mkdir -p out) # FPM ## VERSION=$(shell cat version/version.txt) +PRERELEASE=$(shell cat version/prerelease.txt) ITERATION=$(shell cat version/iteration.txt) ARCHITECTURE=$(GOARCH) DESCRIPTION="A monitoring framework that aims to be simple, malleable, and scalable." @@ -34,7 +35,7 @@ URL="https://sensuapp.org" BIN_SOURCE_DIR=target/$(GOOS)-$(GOARCH) FPM_FLAGS = \ - --version $(VERSION) \ + --version $(VERSION)-$(PRERELEASE) \ --iteration $(ITERATION) \ --url $(URL) \ --license $(LICENSE) \