Skip to content

Instantly share code, notes, and snippets.

@kulvind3r
Created August 7, 2018 15:53
Show Gist options
  • Save kulvind3r/a4f7bacdda01d68af7485c95aef85731 to your computer and use it in GitHub Desktop.
Save kulvind3r/a4f7bacdda01d68af7485c95aef85731 to your computer and use it in GitHub Desktop.
Instead of using <build_number>, version build artefacts using git tags. Maintain history and remove dependency on your CI server.
#!/bin/bash
set -e
SCRIPT=$0
ARG=$1
BASE_VERSION="0.1"
validation_error() {
echo "Not inside a git repo. Exiting."
exit 1
}
usage() {
echo -n " ${SCRIPT} [OPTIONS]
Versions application using git tags
Options:
-b|--bump Increment the app version
-p|--publish Commit the version tag to git repo
"
exit 1
}
bump() {
echo "Current base version is ${BASE_VERSION}"
PATCH_NUMBER=$(git tag -l "${BASE_VERSION}.*" | wc -l)
NEXT_VERSION="${BASE_VERSION}.${PATCH_NUMBER}"
echo "Next app version would be ${NEXT_VERSION}"
git tag $NEXT_VERSION
}
publish() {
echo "Checkout and clean any changes to repo"
git checkout .
echo "Commit version to the repo"
git push --tags
}
[[ -d .git ]] || validation_error
case $ARG in
-b|--bump)
bump
;;
-p|--publish)
publish
;;
*)
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment