Skip to content

Instantly share code, notes, and snippets.

@Tucker-Eric
Last active October 19, 2018 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tucker-Eric/9e5ff81848b3fa6a16faf233b3968630 to your computer and use it in GitHub Desktop.
Save Tucker-Eric/9e5ff81848b3fa6a16faf233b3968630 to your computer and use it in GitHub Desktop.
Git Version
#!/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