Skip to content

Instantly share code, notes, and snippets.

@mccurdyc
Created September 7, 2018 13:34
Show Gist options
  • Save mccurdyc/0a5eaf822501965a7eb596422d4b88c8 to your computer and use it in GitHub Desktop.
Save mccurdyc/0a5eaf822501965a7eb596422d4b88c8 to your computer and use it in GitHub Desktop.
#! /bin/bash
ORG_VER=$(git describe --abbrev=0 --tags)
# remove 'v' from start of string
CURR_VER=${ORG_VER//v}
NEW_VER=$CURR_VER
MAJOR_VER=$(echo $CURR_VER | awk '{split($0,a,"."); print a[1]}')
MINOR_VER=$(echo $CURR_VER | awk '{split($0,a,"."); print a[2]}')
FIX_VER=$(echo $CURR_VER | awk '{split($0,a,"."); print a[3]}')
FIX="fix"
MINOR="minor"
MAJOR="major"
update_version(){
str=$(echo $1 | awk '{print tolower($0)}')
case $str in
$MAJOR)
MAJOR_VER=$(echo "${MAJOR_VER} + 1" | bc)
;;
$MINOR)
MINOR_VER=$(echo "${MINOR_VER} + 1" | bc)
;;
$FIX)
FIX_VER=$(echo "${FIX_VER} + 1" | bc)
;;
esac
NEW_VER="v$MAJOR_VER.$MINOR_VER.$FIX_VER"
echo "Updating version: $ORG_VER -> $NEW_VER"
if [ "$#" -gt "1" ]; then
echo "adding message"
echo $2
# $(git tag $NEW_VER -m $2)
else
# $(git tag $NEW_VER)
fi
}
print_help(){
echo "$package - attempt to capture frames"
echo " "
echo "$package [options] application [arguments]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-b, --bump=VERSION specify the version to increase: major | minor | [default] fix"
}
case "$#" in
"1")
case "$1" in
-h|--help)
print_help
;;
-b|--bump)
echo "VERSION not specified; using default [fix]."
update_version $FIX
exit 0
;;
esac
;;
"2")
if [ "$1" == "-b" ]; then
update_version $2
exit 0
fi
;;
"3")
if [ "$1" == "-b" ]; then
if [ "$3" == "-m" ]; then
echo "if using the '-m' flag, you must specify a message"
exit 1
fi
update_version $2 $3
exit 0
fi
;;
"4")
if [ "$1" == "-b" ]; then
if [ "$3" == "-m" ]; then
update_version $2 $4
exit 0
else
update_version $2
exit 0
fi
fi
;;
*)
print_help
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment