Skip to content

Instantly share code, notes, and snippets.

@MousyBusiness
Last active May 31, 2023 19:57
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 MousyBusiness/2d7b9b640272626f048ae8dcb2984520 to your computer and use it in GitHub Desktop.
Save MousyBusiness/2d7b9b640272626f048ae8dcb2984520 to your computer and use it in GitHub Desktop.
simple script to bump semantically versioned repos
#!/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