Skip to content

Commit a84cfd5

Browse files
committed
version is based on git state or BUILD_VERSION
Git version to be calculated by 'git describe --tags --always' and add '-unsupported' when the local workspace has an uncommitted change. the rules are: * BUILD_VERSION will override any calculated version if set as env/make cli variable * if current commit is tagged, use just the tag * else <tag>-<num commits since>-g<commit id> release target will use CURRENT_VERSION to make it simple to set in the release branch Signed-off-by: Chris Plock <[email protected]>
1 parent ebd8dc8 commit a84cfd5

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

Makefile

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# make BUILD_VERSION=1.2.3 [compile-with-docker] will set netplugin -version output
2-
# make BUILD_VERSION=1.2.3 tar will set the tar filename
3-
# default naming will otherwise be value of version/CURRENT_VERSION
1+
# BUILD_VERSION will affect archive filenames as well as -version
2+
# default version will be based on $(git describe --tags --always)
43

54

65
.PHONY: all all-CI build clean default unit-test release tar checks go-version gofmt-src \
@@ -14,11 +13,7 @@ TO_BUILD := ./netplugin/ ./netmaster/ ./netctl/netctl/ ./mgmtfn/k8splugin/contiv
1413
HOST_GOBIN := `if [ -n "$$(go env GOBIN)" ]; then go env GOBIN; else dirname $$(which go); fi`
1514
HOST_GOROOT := `go env GOROOT`
1615
NAME := netplugin
17-
# We are using date based versioning, so for consistent version during a build
18-
# we evaluate and set the value of version once in a file and use it in 'tar'
19-
# and 'release' targets.
20-
VERSION_FILE := $(NAME)-version
21-
VERSION := `cat $(VERSION_FILE)`
16+
VERSION := $(shell scripts/getGitVersion.sh)
2217
TAR_EXT := tar.bz2
2318
NETPLUGIN_CONTAINER_TAG := $(shell ./scripts/getGitCommit.sh)
2419
TAR_FILENAME := $(NAME)-$(VERSION).$(TAR_EXT)
@@ -342,11 +337,12 @@ tar: compile-with-docker
342337

343338
clean-tar:
344339
@rm -f $(TAR_LOC)/*.$(TAR_EXT)
345-
@rm -f ${VERSION_FILE}
346340

347341
# GITHUB_USER and GITHUB_TOKEN are needed be set to run github-release
348-
release: tar
342+
release-built-version: tar
349343
TAR_FILENAME=$(TAR_FILENAME) TAR_FILE=$(TAR_FILE) \
350344
OLD_VERSION=${OLD_VERSION} BUILD_VERSION=${BUILD_VERSION} \
351345
NIGHTLY_RELEASE=${NIGHTLY_RELEASE} scripts/release.sh
352346
@make clean-tar
347+
release:
348+
@make release-built-version BUILD_VERSION=$(shell cat version/CURRENT_VERSION)

RELEASE.md

+3-15
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,9 @@ You'll find a few examples below:
3838

3939
Please keep in mind that the release notes can be updated on GitHub manually.
4040

41-
BUILD_VERSION can be used to override the version specified in
42-
version/CURRENT_VERSION. This variable should be used to avoid changing
43-
the version for every single beta/rc release.
44-
45-
BUILD_VERSION shouln't be used to override the version for actual
41+
BUILD_VERSION will not override the version for actual
4642
releases (1.0, 1.0.1, 1.1.0 and so on).
4743

48-
Automated nightly releases use the version from version/CURRENT_VERSION.
49-
These nightly releases also append a timestamp to the version found in
50-
that file.
51-
5244
The release process can be found below.
5345

5446
1. Check out the right branch and the right commit. This is necessary
@@ -61,20 +53,16 @@ release isn't made from the HEAD of master.
6153
git push origin 1.0.1
6254
```
6355

64-
3. Write down the BUILD_VERSION or update version/CURRENT_VERSION. This
65-
will be needed for the next steps. Please refer to the explanation
66-
related to BUILD_VERSION and version/CURRENT_VERSION above.
56+
3. Update version/CURRENT_VERSION. This will be needed for the next steps.
6757

6858
4. Make sure GITHUB_USER and GITHUB_TOKEN variables are exported in your environment.
6959

7060
5. Make the release to GitHub.
7161
```
72-
# BUILD_VERSION is used to override version/CURRENT_VERSION
73-
OLD_VERSION=1.1.0-beta.1 BUILD_VERSION=1.1.0-beta.2 make release
62+
OLD_VERSION=1.1.0-beta.1 make release
7463
```
7564

7665
```
77-
# version/CURRENT_VERSION is used for a new stable release
7866
# version/CURRENT_VERSION is 1.1.1
7967
OLD_VERSION=1.1.0 make release
8068
```

scripts/build.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
set -euxo pipefail
44

55
BUILD_TIME=$(date -u +%m-%d-%Y.%H-%M-%S.UTC)
6-
VERSION=$(cat version/CURRENT_VERSION | tr -d '\n')
6+
VERSION=$(scripts/getGitVersion.sh)
77
PKG_NAME=github.com/contiv/netplugin/version
88

9-
# BUILD_VERSION overrides the version from CURRENT_VERSION
9+
# BUILD_VERSION overrides the git calculated version
1010
if [ -n "$BUILD_VERSION" ]; then
1111
VERSION=$BUILD_VERSION
1212
fi
@@ -19,7 +19,8 @@ fi
1919

2020
GIT_COMMIT=$(./scripts/getGitCommit.sh)
2121

22-
echo $BUILD_VERSION >$VERSION_FILE
22+
# TODO(chrisplo): remove when contiv/install no longer needs
23+
echo $BUILD_VERSION > netplugin-version
2324

2425
GOGC=1500 go install -v \
2526
-ldflags "-X $PKG_NAME.version=$BUILD_VERSION \

scripts/getGitVersion.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
if command -v git &>/dev/null && git rev-parse &>/dev/null; then
6+
GIT_COMMIT=$(git describe --tags --always)
7+
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
8+
GIT_COMMIT="$GIT_COMMIT-unsupported"
9+
fi
10+
echo $GIT_COMMIT
11+
exit 0
12+
fi
13+
echo >&2 'error: unable to determine the git revision'
14+
exit 1

0 commit comments

Comments
 (0)