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

version is based on git state or BUILD_VERSION #1042

Merged
merged 5 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
34 changes: 13 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# make BUILD_VERSION=1.2.3 [compile-with-docker] will set netplugin -version output
# make BUILD_VERSION=1.2.3 tar will set the tar filename
# default naming will otherwise be value of version/CURRENT_VERSION
# BUILD_VERSION will affect archive filenames as well as -version
# default version will be based on $(git describe --tags --always)


.PHONY: all all-CI build clean default unit-test release tar checks go-version gofmt-src \
Expand All @@ -14,13 +13,9 @@ TO_BUILD := ./netplugin/ ./netmaster/ ./netctl/netctl/ ./mgmtfn/k8splugin/contiv
HOST_GOBIN := `if [ -n "$$(go env GOBIN)" ]; then go env GOBIN; else dirname $$(which go); fi`
HOST_GOROOT := `go env GOROOT`
NAME := netplugin
# We are using date based versioning, so for consistent version during a build
# we evaluate and set the value of version once in a file and use it in 'tar'
# and 'release' targets.
VERSION_FILE := $(NAME)-version
VERSION := `cat $(VERSION_FILE)`
VERSION := $(shell scripts/getGitVersion.sh)
TAR_EXT := tar.bz2
NETPLUGIN_CONTAINER_TAG := $(shell ./scripts/getGitCommit.sh)
NETPLUGIN_CONTAINER_TAG := $(shell ./scripts/getGitVersion.sh)
TAR_FILENAME := $(NAME)-$(VERSION).$(TAR_EXT)
TAR_LOC := .
TAR_FILE := $(TAR_LOC)/$(TAR_FILENAME)
Expand Down Expand Up @@ -97,17 +92,16 @@ checks-with-docker:

compile:
cd $(GOPATH)/src/github.com/contiv/netplugin && \
NIGHTLY_RELEASE=${NIGHTLY_RELEASE} BUILD_VERSION=${BUILD_VERSION} \
TO_BUILD="${TO_BUILD}" VERSION_FILE=${VERSION_FILE} \
scripts/build.sh
NIGHTLY_RELEASE=${NIGHTLY_RELEASE} TO_BUILD="${TO_BUILD}" \
BUILD_VERSION=$(VERSION) scripts/build.sh

# fully prepares code for pushing to branch, includes building binaries
run-build: deps checks clean compile

compile-with-docker:
docker build \
--build-arg NIGHTLY_RELEASE=${NIGHTLY_RELEASE} \
--build-arg BUILD_VERSION=${BUILD_VERSION} \
--build-arg NIGHTLY_RELEASE=$(NIGHTLY_RELEASE) \
--build-arg BUILD_VERSION=$(VERSION) \
-t netplugin-build:$(NETPLUGIN_CONTAINER_TAG) .

build-docker-image: start
Expand Down Expand Up @@ -328,11 +322,8 @@ host-plugin-release:

# build tarball
tar: compile-with-docker
@# $(TAR_FILE) depends on local file netplugin-version (exists in image),
@# but it is evaluated after we have extracted that file to local disk
docker rm netplugin-build || :
c_id=$$(docker create --name netplugin-build netplugin-build:$(NETPLUGIN_CONTAINER_TAG)) && \
docker cp $${c_id}:/go/src/github.com/contiv/netplugin/netplugin-version ./ && \
for f in netplugin netmaster netctl contivk8s netcontiv; do \
docker cp $${c_id}:/go/bin/$$f bin/$$f; done && \
docker rm $${c_id}
Expand All @@ -342,11 +333,12 @@ tar: compile-with-docker

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

# GITHUB_USER and GITHUB_TOKEN are needed be set to run github-release
release: tar
TAR_FILENAME=$(TAR_FILENAME) TAR_FILE=$(TAR_FILE) \
OLD_VERSION=${OLD_VERSION} BUILD_VERSION=${BUILD_VERSION} \
release-built-version: tar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this meant to be release-built-version or does it refer to the built version of netplugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a helper for release target, the release target sets BUILD_VERSION so that version is externally set instead of through scripts/getGitVersion.sh

Though I see I have BUILD_VERSION duplicated in the release target, should be able to remove one, will update

TAR_FILENAME=$(TAR_FILENAME) TAR_FILE=$(TAR_FILE) OLD_VERSION=${OLD_VERSION} \
NIGHTLY_RELEASE=${NIGHTLY_RELEASE} scripts/release.sh
@make clean-tar
release: export BUILD_VERSION=$(shell cat version/CURRENT_VERSION)
Copy link
Contributor

@unclejack unclejack Nov 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong. There are two release targets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

release:
@make release-built-version BUILD_VERSION=$(shell cat version/CURRENT_VERSION)
18 changes: 3 additions & 15 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,9 @@ You'll find a few examples below:

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

BUILD_VERSION can be used to override the version specified in
version/CURRENT_VERSION. This variable should be used to avoid changing
the version for every single beta/rc release.

BUILD_VERSION shouln't be used to override the version for actual
BUILD_VERSION will not override the version for actual
releases (1.0, 1.0.1, 1.1.0 and so on).

Automated nightly releases use the version from version/CURRENT_VERSION.
These nightly releases also append a timestamp to the version found in
that file.

The release process can be found below.

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

3. Write down the BUILD_VERSION or update version/CURRENT_VERSION. This
will be needed for the next steps. Please refer to the explanation
related to BUILD_VERSION and version/CURRENT_VERSION above.
3. Update version/CURRENT_VERSION. This will be needed for the next steps.

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

5. Make the release to GitHub.
```
# BUILD_VERSION is used to override version/CURRENT_VERSION
OLD_VERSION=1.1.0-beta.1 BUILD_VERSION=1.1.0-beta.2 make release
OLD_VERSION=1.1.0-beta.1 make release
```

```
# version/CURRENT_VERSION is used for a new stable release
# version/CURRENT_VERSION is 1.1.1
OLD_VERSION=1.1.0 make release
```
Expand Down
20 changes: 2 additions & 18 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,12 @@

set -euxo pipefail

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

# BUILD_VERSION overrides the version from CURRENT_VERSION
if [ -n "$BUILD_VERSION" ]; then
VERSION=$BUILD_VERSION
fi

if [ -z "$NIGHTLY_RELEASE" ]; then
BUILD_VERSION="$VERSION"
else
BUILD_VERSION="$VERSION-$BUILD_TIME"
fi

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

echo $BUILD_VERSION >$VERSION_FILE

PKG_NAME=github.com/contiv/netplugin/version
GOGC=1500 go install -v \
-ldflags "-X $PKG_NAME.version=$BUILD_VERSION \
-X $PKG_NAME.buildTime=$BUILD_TIME \
-X $PKG_NAME.buildTime=$(date -u +%m-%d-%Y.%H-%M-%S.UTC) \
-X $PKG_NAME.gitCommit=$GIT_COMMIT \
-s -w" \
$TO_BUILD
32 changes: 32 additions & 0 deletions scripts/getGitVersion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -euo pipefail

BUILD_VERSION=${BUILD_VERSION:-}
NIGHTLY_RELEASE=${NIGHTLY_RELEASE:-}

# calculate version
if command -v git &>/dev/null && git rev-parse &>/dev/null; then
GIT_COMMIT=$(git describe --tags --always 2>/dev/null || echo unknown)
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
GIT_COMMIT="$GIT_COMMIT-unsupported"
fi
VERSION=$GIT_COMMIT
else
echo >&2 'error: unable to determine the git revision'
exit 1
fi

# BUILD_VERSION overrides the git calculated version
if [ -n "$BUILD_VERSION" ]; then
VERSION=$BUILD_VERSION
fi

if [ -z "$NIGHTLY_RELEASE" ]; then
VERSION="$VERSION"
else
BUILD_TIME=$(date -u +%m-%d-%Y.%H-%M-%S.UTC)
VERSION="$VERSION-$BUILD_TIME"
fi

echo $VERSION