Skip to content

Instantly share code, notes, and snippets.

@Sigafoos
Created June 10, 2019 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sigafoos/578c4ad0d9e082317fe8460ec828fc42 to your computer and use it in GitHub Desktop.
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)
#!/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