Last active
February 19, 2022 20:35
-
-
Save roerohan/17e08ee9ed42d97bb841033b038117bd to your computer and use it in GitHub Desktop.
Automatically add a git tag by adding adding flags like --minor, --major, --bug. Modification of https://gist.github.com/dtiemann83/cfa16ade69a3ea451ad760d4118a9351.
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 | |
CURTAG=`git describe --tags --abbrev=0`; | |
CURTAG="${CURTAG/v/}" | |
IFS='.' read -a vers <<< "$CURTAG" | |
MAJ=${vers[0]} | |
MIN=${vers[1]} | |
BUG=${vers[2]} | |
echo "Current Tag: v$MAJ.$MIN.$BUG" | |
for cmd in "$@" | |
do | |
case $cmd in | |
"--major") | |
# $((MAJ+1)) | |
((MAJ+=1)) | |
MIN=0 | |
BUG=0 | |
echo "Incrementing Major Version#" | |
;; | |
"--minor") | |
((MIN+=1)) | |
BUG=0 | |
echo "Incrementing Minor Version#" | |
;; | |
"--bug") | |
((BUG+=1)) | |
echo "Incrementing Bug Version#" | |
;; | |
esac | |
done | |
NEWTAG="v$MAJ.$MIN.$BUG" | |
echo "Adding Tag: $NEWTAG"; | |
git tag -a $NEWTAG -m $NEWTAG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment