Last active
October 17, 2020 16:07
-
-
Save dharrigan/3e083f8d0fd0fc5646b6871d011a1e02 to your computer and use it in GitHub Desktop.
git major minor commits tag script
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
#!/usr/bin/env bash | |
# For projects that follow the version scheme MAJOR.MINOR.COMMITS where MAJOR | |
# and MINOR provide some relative indication of the size of the change, but do | |
# not follow semantic versioning. In general, all changes endeavor to be | |
# non-breaking (by moving to new names rather than by breaking existing | |
# names). COMMITS is an ever-increasing counter of commits since the | |
# beginning of this repository. | |
# Just put this file into your $PATH somewhere, e.g., `~/bin` then use | |
# `git mmctag` to invoke it (note no hyphen when invoking it via git!) | |
version_type=${1:-commits} | |
existing_tag=$( git describe --abbrev=0 --match="*" 2>/dev/null || echo "0.0.0" ) | |
total_commits=$( git rev-list --count HEAD ) | |
echo existing tag "'${existing_tag}'" | |
case "$version_type" in | |
ma|maj|major) | |
new_tag=$(echo $existing_tag | awk -F. -vOFS=. -vtotal_commits=$total_commits '{$1+=1;$2=0;$3=total_commits}1') | |
;; | |
mi|min|minor) | |
new_tag=$(echo $existing_tag | awk -F. -vOFS=. -vtotal_commits=$total_commits '{$2+=1;$3=total_commits}1') | |
;; | |
c|com|commits) | |
new_tag=$(echo $existing_tag | awk -F. -vOFS=. -vtotal_commits=$total_commits '{$3=total_commits}1') | |
;; | |
*) | |
echo Version type "${version_type}" not known, expected major/minor | |
exit 1 | |
;; | |
esac | |
echo creating new tag "'$new_tag'" | |
git tag $new_tag -m "release ${new_tag}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment