Skip to content

Instantly share code, notes, and snippets.

@m4hi2
Created February 26, 2025 19:36
Show Gist options
  • Save m4hi2/463036a6a8c7d92b73ddfe191007ff20 to your computer and use it in GitHub Desktop.
Save m4hi2/463036a6a8c7d92b73ddfe191007ff20 to your computer and use it in GitHub Desktop.
get_next_tag
# 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