diff --git a/build/release/Jenkinsfile.tag b/build/release/Jenkinsfile.tag new file mode 100644 index 000000000..fa8606eef --- /dev/null +++ b/build/release/Jenkinsfile.tag @@ -0,0 +1,29 @@ +// Rook build for Jenkins Pipelines + +pipeline { + agent any + + parameters { + string(name: 'version', defaultValue: '', description: 'The version you are releasing, for example, v0.5.0') + string(name: 'commit', defaultValue: '', description: 'Optional commit hash for this release, for example, 56b65dba917e50132b0a540ae6ff4c5bbfda2db6. If empty the latest commit hash will be used.') + } + + stages { + stage('Tag Release') { + environment { + GITHUB = credentials('rook-github') + } + steps { + // github credentials are not setup to push over https in jenkins. add the github token to the url + sh "git config remote.origin.url https://${GITHUB_USR}:${GITHUB_PSW}@\$(git config --get remote.origin.url | sed -e 's/https:\\/\\///')" + sh "build/run make -j\$(nproc) -C build/release tag VERSION=${params.version} COMMIT_HASH=${params.commit}" + } + } + } + + post { + always { + deleteDir() + } + } +} diff --git a/build/release/Makefile b/build/release/Makefile index bcf59246e..9cd325623 100644 --- a/build/release/Makefile +++ b/build/release/Makefile @@ -28,6 +28,12 @@ ifeq ($(origin BRANCH_NAME), undefined) BRANCH_NAME := $(shell git branch | grep \* | cut -d ' ' -f2) endif +ifeq ($(COMMIT_HASH),) +override COMMIT_HASH := $(shell git rev-parse HEAD) +endif + +REMOTE_NAME ?= origin + PLATFORMS ?= $(ALL_PLATFORMS) ifneq ($(filter master release-%,$(BRANCH_NAME)),) @@ -70,6 +76,28 @@ clean: $(addprefix clean.,$(FLAVORS)) ; # catch all for unimplemented targets / flavors %: ; @: +# ==================================================================================== +# tagging a release + +VERSION_REGEX := ^v\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)$$ +VERSION_VALID := $(shell echo "$(VERSION)" | grep -q '$(VERSION_REGEX)' && echo 1 || echo 0) +VERSION_MAJOR := $(shell echo "$(VERSION)" | sed -e 's/$(VERSION_REGEX)/\1/') +VERSION_MINOR := $(shell echo "$(VERSION)" | sed -e 's/$(VERSION_REGEX)/\2/') +VERSION_PATCH := $(shell echo "$(VERSION)" | sed -e 's/$(VERSION_REGEX)/\3/') + +tag: +ifneq ($(VERSION_VALID),1) + $(error invalid version $(VERSION). must be a semantic version with v[Major].[Minor].[Patch] only) +endif + @echo === tagging commit hash $(COMMIT_HASH) with v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) + @git tag -f -m "release $(VERSION)" v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) $(COMMIT_HASH) + @git push $(REMOTE_NAME) v$(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) + @set -e; if ! git ls-remote --heads $(REMOTE_NAME) | grep -q refs/heads/release-$(VERSION_MAJOR).$(VERSION_MINOR); then \ + echo === creating new release branch release-$(VERSION_MAJOR).$(VERSION_MINOR) ;\ + git branch -f release-$(VERSION_MAJOR).$(VERSION_MINOR) $(COMMIT_HASH) ;\ + git push $(REMOTE_NAME) release-$(VERSION_MAJOR).$(VERSION_MINOR) ;\ + fi + # ==================================================================================== # output