Skip to content

Instantly share code, notes, and snippets.

@Sigafoos Sigafoos/git-bump
Created Jun 10, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.