Skip to content

Instantly share code, notes, and snippets.

@dreamstarter
Last active March 6, 2020 18:24
Show Gist options
  • Save dreamstarter/c06d198d6ffcf69ea24b6c5da0af6d20 to your computer and use it in GitHub Desktop.
Save dreamstarter/c06d198d6ffcf69ea24b6c5da0af6d20 to your computer and use it in GitHub Desktop.
#!/bin/bash
# enable debug
#set -x
# variables
VERSIONFILE="$HOME/current-version.sh"
# functions
function saveVersion () {
echo "#!/bin/bash
MAJOR=${1}
MINOR=${2}
MAINT=${3}
BUILD=${4}" > $5
}
# load current VERSION
. $VERSIONFILE
# main
# check paramater to see which number to increment
case $1 in
release)
MAJOR=$[$MAJOR + 1]
MINOR=0
MAINT=0
BUILD=0
;;
feature)
MINOR=$[$MINOR + 1]
;;
maint)
MAINT=$[$MAINT + 1]
;;
bug)
BUILD=$[$BUILD + 1]
;;
current)
echo "Current version: ${MAJOR}.${MINOR}.${MAINT}.${BUILD}"
exit 0
;;
*)
echo "Current version: ${MAJOR}.${MINOR}.${MAINT}.${BUILD}"
echo " "
echo "Usage: $(basename $0) (current || release || feature || maint || bug)"
exit 1
esac
# echo the new VERSION number
echo "NEW VERSION: ${MAJOR}.${MINOR}.${MAINT}.${BUILD}"
saveVersion "${MAJOR}" "${MINOR}" "${MAINT}" "${BUILD}" "$VERSIONFILE"
exit 0
@applematt
Copy link

Here's a suggested revision of that shell script:

#!/bin/bash
# enable debug
#set -x

# variables
VERSIONFILE="$HOME/current-version.sh"

# functions
function saveVersion () {
	echo "#!/bin/bash
	MAJOR=${1}
	MINOR=${2}
	MAINT=${3}
	BUILD=${4}" > $5
}

# load current VERSION
. $VERSIONFILE

# main
# check paramater to see which number to increment
case $1 in
	release)
		MAJOR=$[$MAJOR + 1]
		MINOR=0
		MAINT=0
		BUILD=0
		;;
	feature)
		MINOR=$[$MINOR + 1]
		;;
	maint)
		MAINT=$[$MAINT + 1]
		;;
	bug)
		BUILD=$[$BUILD + 1]
		;;
	current)
		echo "Current version: ${MAJOR}.${MINOR}.${MAINT}.${BUILD}"
		exit 0
		;;
	*)
		echo "Current version: ${MAJOR}.${MINOR}.${MAINT}.${BUILD}"
		echo " "
		echo "Usage: $(basename $0) (current || release || feature || maint || bug)"
  		exit 1
esac

# echo the new VERSION number
echo "NEW VERSION: ${MAJOR}.${MINOR}.${MAINT}.${BUILD}"
saveVersion "${MAJOR}" "${MINOR}" "${MAINT}" "${BUILD}" "$VERSIONFILE"

exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment