Last active
September 7, 2019 10:35
-
-
Save Maghraby/8bc5b92e1b40269196cd906708b775e4 to your computer and use it in GitHub Desktop.
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 | |
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