Created
August 7, 2018 15:53
-
-
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.
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 | |
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