Skip to content

Instantly share code, notes, and snippets.

@Maghraby
Last active September 7, 2019 10:35
Show Gist options
  • Save Maghraby/8bc5b92e1b40269196cd906708b775e4 to your computer and use it in GitHub Desktop.
Save Maghraby/8bc5b92e1b40269196cd906708b775e4 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ -z $2 ]
then
BRANCH=master
else
BRANCH=$2
fi
git checkout $BRANCH
git pull
VERSION=`git tag --sort=v:refname | tail -n 1`
IFS='.'
read -a VERSION <<< "$VERSION"
MAJOR=${VERSION[0]}
MINOR=${VERSION[1]}
PATCH=${VERSION[2]}
function bumpMajor() {
((MAJOR++))
MINOR=0
PATCH=0
}
function bumpMinior() {
((MINOR++))
PATCH=0
}
function bumpPatch() {
((PATCH++))
}
case "$1" in
major)
echo "Bumping major version."
bumpMajor
;;
minor)
echo "Bumping minor version."
bumpMinior
;;
patch)
echo "Bumping patch version."
if [ "$PATCH" -eq 9 ]
then
bumpMinior
else
bumpPatch
fi
;;
esac
IFS=''
NEXT_VERSION="$MAJOR.$MINOR.$PATCH"
echo $NEXT_VERSION
while true; do
read -p "Do you want to bump the version ($NEXT_VERSION) ? (Yy/Nn): " YN
echo $YN
case $YN in
[Yy]* ) echo "Tagging.."; git tag "$NEXT_VERSION" -m "Version $NEXT_VERSION"; break;;
[Nn]* ) exit;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment