Last active
March 4, 2023 17:29
-
-
Save alexdyukov/c9b91907c0594747a516d998b2ad1c08 to your computer and use it in GitHub Desktop.
Easy semver for github-flow
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
# semver: increment MAJOR version when you make incompatible API changes | |
# magic number 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is git commit hash of null (before init commit) | |
MAJOR_VERSION=0 | |
MAJOR_LAST_COMMIT_HASH="4b825dc642cb6eb9a060e54bf8d69288fbee4904" | |
# semver: increment MINOR version when you add functionality in a backwards-compatible manner | |
MINOR_LAST_COMMIT_HASH=$(git rev-list --invert-grep -i --grep='fix' ${MAJOR_LAST_COMMIT_HASH}..HEAD --no-merges -n 1) | |
MINOR_VERSION=$(git rev-list --invert-grep -i --grep='fix' ${MAJOR_LAST_COMMIT_HASH}..HEAD --no-merges --count) | |
[ "${MINOR_LAST_COMMIT_HASH}" = "" ] && MINOR_LAST_COMMIT_HASH=${MAJOR_LAST_COMMIT_HASH} | |
[ "${MINOR_LAST_COMMIT_HASH}" = "" ] && MINOR_VERSION="0" | |
# semver: increment PATCH version when you make backwards-compatible bug fixes | |
PATCH_VERSION=$(git rev-list ${MINOR_LAST_COMMIT_HASH}..HEAD --no-merges --count) | |
echo ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment