-
-
Save Derioss/066d69bb07d6a3a61868c21c72383192 to your computer and use it in GitHub Desktop.
simple bash script to increment the version number of the format major.minor.build
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 | |
version="$1" | |
major=0 | |
minor=0 | |
build=0 | |
# break down the version number into it's components | |
regex="([0-9]+).([0-9]+).([0-9]+)" | |
if [[ $version =~ $regex ]]; then | |
major="${BASH_REMATCH[1]}" | |
minor="${BASH_REMATCH[2]}" | |
build="${BASH_REMATCH[3]}" | |
fi | |
# check paramater to see which number to increment | |
if [[ "$2" == "feature" ]]; then | |
minor=$(echo $minor + 1 | bc) | |
elif [[ "$2" == "bug" ]]; then | |
build=$(echo $build + 1 | bc) | |
elif [[ "$2" == "major" ]]; then | |
major=$(echo $major+1 | bc) | |
else | |
echo "usage: ./version.sh version_number [major/feature/bug]" | |
exit -1 | |
fi | |
# echo the new version number | |
echo "new version: ${major}.${minor}.${build}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment