Last active
October 19, 2018 20:18
-
-
Save Tucker-Eric/9e5ff81848b3fa6a16faf233b3968630 to your computer and use it in GitHub Desktop.
Git Version
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 | |
# FROM: https://engineering.taboola.com/calculating-git-version/ | |
branch=$(git rev-parse --abbrev-ref HEAD) | |
latest=$(git tag -l --merged master --sort='-*authordate' | head -n1) | |
semver_parts=(${latest//./ }) | |
major=${semver_parts[0]} | |
minor=${semver_parts[1]} | |
patch=${semver_parts[2]} | |
count=$(git rev-list HEAD ^${latest} --ancestry-path ${latest} --count) | |
version="" | |
case $branch in | |
"master") | |
version=${major}.$((minor+1)).0 | |
;; | |
"feature/*") | |
version=${major}.${minor}.${patch}-${branch}-${count} | |
;; | |
*) | |
>&2 echo "unsupported branch type" | |
exit 1 | |
;; | |
esac | |
echo ${version} | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment