Created
February 26, 2025 19:36
-
-
Save m4hi2/463036a6a8c7d92b73ddfe191007ff20 to your computer and use it in GitHub Desktop.
get_next_tag
This file contains hidden or 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
# Gets the next tag of the given branch | |
get_next_tag() | |
{ | |
latestTag=$(git describe --tags $(git rev-list --tags="$1-*" --max-count=1)) | |
tagC=$(git rev-parse $latestTag) | |
head=$(git rev-parse HEAD) | |
if [ "$tagC" == "$head" ]; then | |
return 1 | |
fi | |
major=0 | |
minor=0 | |
patch=0 | |
# Regex to match parts of the version | |
re="^$1-([0-9]+)\.([0-9]+)\.([0-9]+)" | |
if [[ $latestTag =~ $re ]]; then | |
major=${BASH_REMATCH[1]} | |
minor=${BASH_REMATCH[2]} | |
patch=${BASH_REMATCH[3]} | |
else | |
return 1 | |
fi | |
((patch++)) | |
if [ $patch -gt 99 ]; then | |
((minor++)) | |
patch=0 | |
fi | |
if [ $minor -gt 50 ]; then | |
((major++)) | |
minor=0 | |
fi | |
echo "$1-$major.$minor.$patch" | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment