Skip to content

Commit c057e89

Browse files
Merge pull request #356 from sensu/alpha
Add prerelease flag for specifying alpha/beta/RC builds
2 parents c8aaca1 + cb9ca23 commit c057e89

8 files changed

Lines changed: 29 additions & 8 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $(shell mkdir -p out)
2323
# FPM
2424
##
2525
VERSION=$(shell cat version/version.txt)
26+
PRERELEASE=$(shell cat version/prerelease.txt)
2627
ITERATION=$(shell cat version/iteration.txt)
2728
ARCHITECTURE=$(GOARCH)
2829
DESCRIPTION="A monitoring framework that aims to be simple, malleable, and scalable."
@@ -34,7 +35,7 @@ URL="https://sensuapp.org"
3435
BIN_SOURCE_DIR=target/$(GOOS)-$(GOARCH)
3536

3637
FPM_FLAGS = \
37-
--version $(VERSION) \
38+
--version $(VERSION)-$(PRERELEASE) \
3839
--iteration $(ITERATION) \
3940
--url $(URL) \
4041
--license $(LICENSE) \

agent/cmd/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func newVersionCommand() *cobra.Command {
5858
Short: "Show the sensu-agent version information",
5959
Run: func(cmd *cobra.Command, args []string) {
6060
fmt.Printf("sensu-agent version %s, build %s, built %s\n",
61-
version.Version,
61+
version.Semver(),
6262
version.BuildSHA,
6363
version.BuildDate,
6464
)

backend/cmd/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func newVersionCommand() *cobra.Command {
5555
Short: "Show the sensu-backend version information",
5656
Run: func(cmd *cobra.Command, args []string) {
5757
fmt.Printf("sensu-backend version %s, build %s, built %s\n",
58-
version.Version,
58+
version.Semver(),
5959
version.BuildSHA,
6060
version.BuildDate,
6161
)

build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ build_binary () {
7878
local outfile="target/${goos}-${goarch}/${cmd_name}"
7979

8080
local version=$(cat version/version.txt)
81-
local iteration=$(cat version/iteration.txt)
81+
local prerelease=$(cat version/prerelease.txt)
8282
local build_date=$(date +"%Y-%m-%dT%H:%M:%S%z")
8383
local build_sha=$(git rev-parse HEAD)
8484

8585
local version_pkg="github.com/sensu/sensu-go/version"
86-
local ldflags="-X $version_pkg.Version=${version}"
87-
local ldflags+=" -X $version_pkg.Iteration=${iteration}"
86+
local ldflags=" -X $version_pkg.Version=${version}"
87+
local ldflags+=" -X $version_pkg.PreReleaseIdentifier=${prerelease}"
8888
local ldflags+=" -X $version_pkg.BuildDate=${build_date}"
8989
local ldflags+=" -X $version_pkg.BuildSHA=${build_sha}"
9090

cli/cmd/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func newVersionCommand() *cobra.Command {
6363
Short: "Show the sensu-ctl version information",
6464
Run: func(cmd *cobra.Command, args []string) {
6565
fmt.Printf("sensu-ctl version %s, build %s, built %s\n",
66-
version.Version,
66+
version.Semver(),
6767
version.BuildSHA,
6868
version.BuildDate,
6969
)

version/prerelease.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alpha.1

version/version.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,28 @@ var (
44
// Version stores the version of the current build (e.g. 2.0.0)
55
Version string
66

7+
// PreReleaseIdentifier stores the pre-release identifier of the current build (eg. beta-2)
8+
PreReleaseIdentifier string
9+
710
// BuildDate stores the timestamp of the build (e.g. 2017-07-31T13:11:15-0700)
811
BuildDate string
912

1013
// BuildSHA stores the git sha of the build (e.g. 8673bed0a9705083987b9ecbbc1cc0758df13dd2)
1114
BuildSHA string
1215
)
16+
17+
// Semver returns full semantic versioning compatible identifier.
18+
// Format: VERSION-PRERELEASE+METADATA
19+
func Semver() string {
20+
version := Version
21+
if PreReleaseIdentifier != "" {
22+
version = version + "-" + PreReleaseIdentifier
23+
}
24+
25+
gitSHA := BuildSHA
26+
if len(gitSHA) > 7 {
27+
gitSHA = gitSHA[:7]
28+
}
29+
30+
return version + "#" + gitSHA
31+
}

version/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0p1
1+
2.0.0

0 commit comments

Comments
 (0)