-
-
Save MousyBusiness/2d7b9b640272626f048ae8dcb2984520 to your computer and use it in GitHub Desktop.
simple script to bump semantically versioned repos
This file contains hidden or 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
#!/usr/bin/env bash | |
while [[ -n "$1" ]] ; do | |
case "$1" in | |
--minor) | |
MINOR=true | |
;; | |
--major) | |
MAJOR=true | |
;; | |
--help) | |
echo "Usage: bump [--major|--minor]" | |
exit 1 | |
;; | |
*) | |
echo "error: unknown arg" && exit 1 ;; | |
esac | |
shift | |
done | |
TAGS=$(git ls-remote --tags origin | awk '{ print $2 }' | sed 's|refs/tags/||' | sort -t "." -V) | |
LAST=$(echo "$TAGS" | tac - | head -n 1) | |
echo "last tag: $LAST" | |
tag(){ | |
echo "new tag: $VERSION" | |
git tag $VERSION | |
git push --tags | |
} | |
if [[ -z "$LAST" ]] ; then | |
echo "no tag" | |
VERSION="v0.0.1" | |
tag | |
exit 0 | |
fi | |
if [[ "$MINOR" == "true" ]] ; then | |
PREFIX=$(echo "$LAST" | sed 's/^\(.*\.\)\(.*\)\.\(.*\)$/\1/') | |
MINOR=$(echo "$LAST" | sed 's/^\(.*\.\)\(.*\)\.\(.*\)$/\2/') | |
INCREMENTED=$(expr $(($MINOR + 1))) | |
VERSION=$(echo "${PREFIX}${INCREMENTED}.0") | |
elif [[ "$MAJOR" == "true" ]] ; then | |
MAJOR=$(echo "$LAST" | sed 's/^v\(.*\)\..*\..*$/\1/') | |
INCREMENTED=$(expr $(($MAJOR + 1))) | |
VERSION=$(echo "v${INCREMENTED}.0.0") | |
else | |
PREFIX=$(echo "$LAST" | sed 's/^\(.*\..*\.\)\(.*\)$/\1/') | |
LATEST=$(echo "$LAST" | sed 's/^\(.*\..*\.\)\(.*\)$/\2/') | |
INCREMENTED=$(expr $(($LATEST + 1))) | |
VERSION=$(echo "${PREFIX}${INCREMENTED}") | |
fi | |
tag |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment