Skip to content

Instantly share code, notes, and snippets.

@learosema
Last active May 20, 2024 13:37
Show Gist options
  • Save learosema/79b25203f1e9013fe561ba8a7d835b88 to your computer and use it in GitHub Desktop.
Save learosema/79b25203f1e9013fe561ba8a7d835b88 to your computer and use it in GitHub Desktop.

Count up a version which is read from a VERSION file. The VERSION is assumed to be in the format v1.2.3

  • ./upcount-version.sh major increments the major version
  • ./upcount-version.sh minor increments the minor version
  • ./upcount-version.sh increments the patch version
#!/bin/sh
if [ -f "VERSION" ]; then
VERSION=$(cut -d'v' -f 2 <<< $(cat VERSION))
MAJOR=$(cut -d'.' -f 1 <<< ${VERSION})
MINOR=$(cut -d'.' -f 2 <<< ${VERSION})
PATCH=$(cut -d'.' -f 3 <<< ${VERSION})
else
MAJOR=0
MINOR=0
PATCH=0
fi
if [ "$1" == "major" ]; then
MAJOR=$(expr ${MAJOR} + 1)
MINOR=0
PATCH=0
elif [ "$1" == "minor" ]; then
MINOR=$(expr ${MINOR} + 1)
PATCH=0
else
PATCH=$(expr ${PATCH} + 1)
fi
echo v${MAJOR}.${MINOR}.${PATCH} > VERSION
cat VERSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment