generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled semvar versioning of git tag. Local builds.
- Loading branch information
Stephen James
committed
Oct 24, 2023
1 parent
758627a
commit e18134f
Showing
4 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
.DEFAULT_GOAL := help | ||
include .config | ||
export | ||
|
||
REGISTRY := ghcr.io | ||
GITHUB_OWNER := $$(git config remote.origin.url | cut -d : -f 2 | cut -d / -f 1) | ||
NAME := ${GITHUB_OWNER}/nvvs/terraform | ||
TAG := $$(git log -1 --pretty=%h) | ||
IMG := ${NAME}:${TAG} | ||
LATEST := ${NAME}:latest | ||
|
||
CURRENT_VERSION := $$(git describe --abbrev=0) | ||
CURRENT_NUMBER := $$(echo $(CURRENT_VERSION) | cut -d "v" -f 2) | ||
|
||
ifeq ($(SEMVAR),patch) | ||
NEXT_NUMBER := $$(./semver/increment_version.sh -p $(CURRENT_NUMBER)) | ||
else ifeq ($(SEMVAR),minor) | ||
NEXT_NUMBER := $$(./semver/increment_version.sh -m $(CURRENT_NUMBER)) | ||
else ifeq ($(SEMVAR),major) | ||
NEXT_NUMBER := $$(./semver/increment_version.sh -M $(CURRENT_NUMBER)) | ||
endif | ||
|
||
NEXT_VERSION := "v$(NEXT_NUMBER)" | ||
|
||
.PHONY: debug | ||
debug: ## debug | ||
echo ${version} | ||
@echo $(NEXT_NUMBER) | ||
|
||
.PHONY: tag | ||
tag: ## Tag git repo | ||
git tag -a ${version} -m "Bump ${version}" | ||
git push origin main --follow-tags | ||
.PHONY: current_version | ||
current_version: ## Get current version eg v3.4.1 | ||
@echo $(CURRENT_VERSION) | ||
@echo $(CURRENT_NUMBER) | ||
|
||
.PHONY: preview_version | ||
preview_version: ## increment version eg v3.4.1 > v3.5.0. Use SEMVAR=[ patch | minor | major ] | ||
@echo "CURRENT_VERSION := $(CURRENT_VERSION)" | ||
@echo " $(SEMVAR) := $(NEXT_VERSION)" | ||
|
||
.PHONY: tag | ||
build: ## Build Docker image | ||
echo "[${version}]" | ||
docker build --tag ghcr.io/${GITHUB_OWNER}/nvvs/terraform:${version} . | ||
tag: ## Tag branch in git repo with next version number. Use SEMVAR=[ patch | minor | major ] | ||
@echo "tagging with $(NEXT_VERSION)" | ||
@git tag -a "$(NEXT_VERSION)" -m "Bump from $(CURRENT_VERSION) to $(NEXT_VERSION)" | ||
@git push origin main --follow-tags | ||
|
||
.PHONY: build | ||
build: ## Build & tag Docker image | ||
docker build --tag ${IMG} . | ||
docker tag ${IMG} ${LATEST} | ||
|
||
help: | ||
@grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Fritz Mahnke | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
bash-semver | ||
=========== | ||
|
||
Increment semantic versioning strings in shell scripts. | ||
|
||
```shell | ||
$ ./increment_version.sh | ||
usage: increment_version.sh [-Mmp] major.minor.patch | ||
|
||
$ ./increment_version.sh -p 0.0.0 | ||
0.0.1 | ||
|
||
$ ./increment_version.sh -m 0.0.3 | ||
0.1.0 | ||
|
||
$ ./increment_version.sh -M 1.1.15 | ||
2.0.0 | ||
|
||
$ ./increment_version.sh -Mmp 2.3.4 | ||
3.1.1 | ||
``` | ||
|
||
Sourced from https://github.com/fmahnke/shell-semver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Increment a version string using Semantic Versioning (SemVer) terminology. | ||
|
||
# Parse command line options. | ||
|
||
while getopts ":Mmp" Option | ||
do | ||
case $Option in | ||
M ) major=true;; | ||
m ) minor=true;; | ||
p ) patch=true;; | ||
esac | ||
done | ||
|
||
shift $(($OPTIND - 1)) | ||
|
||
version=$1 | ||
|
||
# Build array from version string. | ||
|
||
a=( ${version//./ } ) | ||
|
||
# If version string is missing or has the wrong number of members, show usage message. | ||
|
||
if [ ${#a[@]} -ne 3 ] | ||
then | ||
echo "usage: $(basename $0) [-Mmp] major.minor.patch" | ||
exit 1 | ||
fi | ||
|
||
# Increment version numbers as requested. | ||
|
||
if [ ! -z $major ] | ||
then | ||
((a[0]++)) | ||
a[1]=0 | ||
a[2]=0 | ||
fi | ||
|
||
if [ ! -z $minor ] | ||
then | ||
((a[1]++)) | ||
a[2]=0 | ||
fi | ||
|
||
if [ ! -z $patch ] | ||
then | ||
((a[2]++)) | ||
fi | ||
|
||
echo "${a[0]}.${a[1]}.${a[2]}" | ||
|