Skip to content

Instantly share code, notes, and snippets.

@stewartjarod
Created July 9, 2018 19:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stewartjarod/9cdaab406b587521cfadd36ad15f5f79 to your computer and use it in GitHub Desktop.
Save stewartjarod/9cdaab406b587521cfadd36ad15f5f79 to your computer and use it in GitHub Desktop.
Bump git version tag by patch, minor, or major
# Usage: `tag M` | `tag maj` | `tag major` || `tag m` | `tag min` | `tag minor` || `tag p` | `tag patch`
function gtag() {
if [ -n $1 ]
then
echo "› Creating tag: v$1"
if git tag -a "v$1" -m "v$1" >/dev/null
then
echo "› Pushing Tag to Upstream"
git push origin --tags
else
echo "EXITING"
return
fi
else
echo "Must pass tag"
fi
}
function tag() {
if [ -n $1 ]
then
git fetch --all --tags
current_tag="$(git describe --abbrev=0 --tags)"
echo "› Current Tag: $current_tag"
vers=("${(@s/./)current_tag}")
patch=$vers[3]
minor=$vers[2]
major=${vers[1][2,-1]}
if [[ "$1" == "p" || "$1" == "patch" ]]
then
echo "› Patching"
patch=$(($patch + 1))
elif [[ $1 == "m" || $1 == "min" || $1 == "minor" ]]
then
echo "› Minor Update"
minor=$(($minor + 1))
patch=0
elif [[ $1 == "M" || $1 == "maj" || $1 == "major" ]]
then
echo "› Major Update"
major=$(($major + 1))
minor=0
patch=0
else
echo '›› Failed to create tag'
return
fi
echo "› Updating to: v$major.$minor.$patch"
gtag $major.$minor.$patch
else
echo "››› Must pass tag"
fi
}
@vulcan25
Copy link

Nice script!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment