Skip to content

Instantly share code, notes, and snippets.

@jerlendds
Created September 18, 2022 14:53
Show Gist options
  • Save jerlendds/6e0fff803e18fcb49fd05ced6b647219 to your computer and use it in GitHub Desktop.
Save jerlendds/6e0fff803e18fcb49fd05ced6b647219 to your computer and use it in GitHub Desktop.
#!/bin/bash
PROJECT_NAME=todo
SEMVER_FILE=./version.sh
version=0.0.0
if [ -f "$SEMVER_FILE" ]; then
source $SEMVER_FILE
version=$SEMVER
fi
# Increment a version string using Semantic Versioning (SemVer) terminology.
# Parse command line options.
while getopts ":Mmp" Option
do
case $Option in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
esac
done
shift $(($OPTIND - 1))
# Build array from version string.
a=( ${version//./ } )
# If version string is missing or has the wrong number of members, show usage message.
if [ ${#a[@]} -ne 3 ]
then
echo "usage: $(basename $0) [-Mmp] major.minor.patch"
exit 1
fi
# Increment version numbers as requested.
if [ ! -z $major ]
then
((a[0]++))
a[1]=0
a[2]=0
fi
if [ ! -z $minor ]
then
((a[1]++))
a[2]=0
fi
if [ ! -z $patch ]
then
((a[2]++))
fi
if [ -f "$FILE" ]; then
echo "$FILE exists."
fi
echo "Deploying $PROJECT_NAME v${a[0]}.${a[1]}.${a[2]}"
echo "#!/bin/bash
SEMVER=${a[0]}.${a[1]}.${a[2]}" > $SEMVER_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment