Created
June 10, 2019 00:02
-
-
Save Sigafoos/578c4ad0d9e082317fe8460ec828fc42 to your computer and use it in GitHub Desktop.
bump the semver tag of a git repo (using go 1.12+ style v4.1.3 tags)
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
#!/bin/bash | |
bump=$1 | |
if [ -z $bump ]; then | |
echo "need to provide an action" | |
exit 1 | |
fi | |
tag=($(git describe --abbrev=0 --tags | perl -pe 's/^v?(\d+)\.(\d+)\.(\d+)$/\1 \2 \3/g')) | |
major=${tag[0]} | |
minor=${tag[1]} | |
patch=${tag[2]} | |
if [[ $bump == "major" ]]; then | |
major=$((major+1)) | |
newtag="v$major.0.0" | |
elif [[ $bump == "minor" ]]; then | |
minor=$((minor+1)) | |
newtag="v$major.$minor.0" | |
elif [[ $bump == "patch" ]]; then | |
patch=$((patch+1)) | |
newtag="v$major.$minor.$patch" | |
else | |
echo "unknown action '$bump'; must be one of major, minor, patch" | |
exit 1 | |
fi | |
git tag $newtag | |
git push --tags |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment