Files
gonic/_do_bump_version
2020-07-24 15:10:25 +01:00

70 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# safety checks
if [[ $# -ne 1 ]]; then
echo "usage: $0 <major|minor|patch>" >&2
exit 1
fi
if [[ "$(git rev-parse --abbrev-ref HEAD)" != 'master' ]]; then
echo "not on the master branch" >&2
exit 1
fi
# get latest and check if clean
git pull
if [[ -n "$(git status --porcelain)" ]]; then
echo "working directory is dirty" >&2
exit 1
fi
# get the current verison from last git tag into array and
# inc the provided part
semver_expression='s/^v([0-9]+)\.([0-9]+)\.([0-9]+).*$/\1 \2 \3/'
version=( $(git describe --tags | sed -E -e "$semver_expression" ) )
case "$1" in
major)
((version[0]++))
version[1]=0
version[2]=0
;;
minor)
((version[1]++))
version[2]=0
;;
patch)
((version[2]++))
;;
*)
echo 'please provide a valid version in increment' >&2
exit 1
esac
new_version="v${version[0]}.${version[1]}.${version[2]}"
# write version to go
mkdir version >/dev/null 2>&1
cat > version/version.go << EOL
// generated by \`_do_bump_version\` script in project root
// $(date)
// DO NOT EDIT
package version
const NAME = "gonic"
const NAME_UPPER = "GONIC"
const NAME_EMBED = "gonicembed"
const VERSION = "$new_version"
EOL
./_do_gen_handler_tests
# create and tag single commit with a change to the version file
git commit --all --file - << EOL
bump to $new_version
generated by \`_do_bump_version\` script in project root
EOL
git tag "$new_version"
echo "commited and tagged"
echo "remember to push tags"