Skip to content

Commit 6745e75

Browse files
fix(version): move all version logic to git (#167)
1 parent dfe19e0 commit 6745e75

5 files changed

Lines changed: 24 additions & 25 deletions

File tree

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ parallel(
144144
}
145145

146146
make 'bootstrap'
147-
env.VERSION = git_commit.take(7)
147+
env.REVISION = git_commit.take(7)
148148
make 'build-revision'
149149

150150
upload_artifacts()

Makefile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ else
88
GOOS=linux
99
endif
1010

11+
# The latest git tag on branch
12+
GIT_TAG := $(shell git describe --abbrev=0 --tags)
13+
# If the latest commit is tagged
14+
TAGGED_COMMIT := $(shell git tag -l --contains HEAD)
15+
REVISION ?= $(shell git rev-parse --short HEAD)
16+
17+
ifdef TAGGED_COMMIT
18+
VERSION ?= ${GIT_TAG}
19+
else
20+
VERSION ?= ${GIT_TAG}-${REVISION}
21+
endif
22+
1123
BUILD_OS ?=linux darwin windows
1224
BUILD_ARCH ?=amd64 386
1325

@@ -18,13 +30,9 @@ DEV_ENV_PREFIX_CGO_ENABLED := docker run --rm -e CGO_ENABLED=1 -v ${CURDIR}:${DE
1830
DEV_ENV_CMD := ${DEV_ENV_PREFIX} ${DEV_ENV_IMAGE}
1931
DIST_DIR := _dist
2032

21-
GO_LDFLAGS = -ldflags "-s -X ${repo_path}/version.BuildVersion=${VERSION}"
33+
GO_LDFLAGS = -ldflags "-s -X ${repo_path}/version.Version=${VERSION}"
2234
GOTEST = go test --race
2335

24-
# The tag of the commit
25-
GIT_TAG := $(shell git tag -l --contains HEAD)
26-
VERSION ?= $(shell git rev-parse --short HEAD)
27-
2836
# UID and GID of local user
2937
UID := $(shell id -u)
3038
GID := $(shell id -g)
@@ -51,10 +59,10 @@ build-latest:
5159
${DEV_ENV_CMD} gox -verbose -parallel=3 ${GO_LDFLAGS} -os="${BUILD_OS}" -arch="${BUILD_ARCH}" -output="$(DIST_DIR)/deis-latest-{{.OS}}-{{.Arch}}" .
5260

5361
build-revision:
54-
ifdef GIT_TAG
62+
ifdef TAGGED_COMMIT
5563
${DEV_ENV_CMD} gox -verbose -parallel=3 ${GO_LDFLAGS} -os="${BUILD_OS}" -arch="${BUILD_ARCH}" -output="$(DIST_DIR)/${GIT_TAG}/deis-${GIT_TAG}-{{.OS}}-{{.Arch}}" .
5664
else
57-
${DEV_ENV_CMD} gox -verbose -parallel=3 ${GO_LDFLAGS} -os="${BUILD_OS}" -arch="${BUILD_ARCH}" -output="$(DIST_DIR)/${VERSION}/deis-${VERSION}-{{.OS}}-{{.Arch}}" .
65+
${DEV_ENV_CMD} gox -verbose -parallel=3 ${GO_LDFLAGS} -os="${BUILD_OS}" -arch="${BUILD_ARCH}" -output="$(DIST_DIR)/${REVISION}/deis-${REVISION}-{{.OS}}-{{.Arch}}" .
5866
endif
5967

6068
build-all: build-latest build-revision

parser/version.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ Use 'deis help [command]' to learn more.
2020
return err
2121
}
2222

23-
v := version.Version
24-
if version.BuildVersion != "" {
25-
v = fmt.Sprintf("%s-%s", version.Version, version.BuildVersion)
26-
}
27-
fmt.Println(v)
23+
fmt.Println(version.Version)
2824

2925
return nil
3026
}

settings/settings.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ import (
1111
"github.com/deis/workflow-cli/version"
1212
)
1313

14-
const (
15-
// UserAgent is the user agent used by the CLI
16-
UserAgent = "Deis Client v" + version.Version
14+
// DefaultResponseLimit is the default number of responses to return on requests that can
15+
// be limited.
16+
const DefaultResponseLimit = 100
1717

18-
// DefaultResponseLimit is the default number of responses to return on requests that can
19-
// be limited.
20-
DefaultResponseLimit = 100
21-
)
18+
// UserAgent is the user agent used by the CLI
19+
var UserAgent = "Deis Client v" + version.Version
2220

2321
type settingsFile struct {
2422
Username string `json:"username"`

version/version.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package version
22

3-
// Version identifies this Deis product revision.
4-
const Version = "2.3.0"
5-
6-
// BuildVersion is the git revision of the build.
3+
// Version identifies the Deis product revision.
74
// Note: This value is overwritten by the linker during build
8-
var BuildVersion = ""
5+
var Version = "unknown version (override me)"

0 commit comments

Comments
 (0)