Skip to content

Instantly share code, notes, and snippets.

@umutdz
Last active December 23, 2022 22:14
Show Gist options
  • Save umutdz/4796f77e2ca0aee68453dfc8d4723a0f to your computer and use it in GitHub Desktop.
Save umutdz/4796f77e2ca0aee68453dfc8d4723a0f to your computer and use it in GitHub Desktop.
#!/bin/bash
major() {
if IFS=. read -r major rest <version.txt || [ -n "$major" ]; then
echo "$((major + 1)).0.0.$1" >"version.txt"
else
echo "ERROR: Unable to read version number from version.txt" >&2
exit 1
fi
}
minor() {
if IFS=. read -r major minor patch build <version.txt || [ -n "$major" ]; then
echo "$major.$((minor + 1)).0.$1" >"version.txt"
else
echo "ERROR: Unable to read version number from version.txt" >&2
exit 1
fi
}
patch() {
if IFS=. read -r major minor patch build <version.txt || [ -n "$major" ]; then
echo "$major.$minor.$((patch + 1)).$1" >"version.txt"
else
echo "ERROR: Unable to read version number from version.txt" >&2
exit 1
fi
}
update() {
echo "New version = $(<version.txt)"
git config --global push.default simple
git config -l
git add version.txt
git commit -m "Updating version.txt with latest version number."
version=$(<version.txt)
git tag -a "v${version}" -m "Released new version: v${version}"
git push origin "v${version}"
git push -f
}
case "$1" in
major)
major $2
update
;;
minor)
minor $2
update
;;
patch)
patch $2
update
;;
build)
build $2
update
;;
*)
echo "Usage: bash version.sh {major|minor|patch} build_number"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment