Created
December 16, 2019 12:32
-
-
Save psucodervn/4a4cd9bca237fc2d185ca816fb9a3be4 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
#get highest tag number | |
VERSION=`git describe --abbrev=0 --tags` | |
#replace . with space so can split into an array | |
VERSION_BITS=(${VERSION//./ }) | |
#get number parts and increase last one by 1 | |
VNUM1=${VERSION_BITS[0]-0} | |
VNUM2=${VERSION_BITS[1]-0} | |
VNUM3=${VERSION_BITS[2]-0} | |
VNUM3=$((VNUM3+1)) | |
#create new tag | |
NEW_TAG="$VNUM1.$VNUM2.$VNUM3" | |
echo "Updating $VERSION to $NEW_TAG" | |
#get current hash and see if it already has a tag | |
GIT_COMMIT=`git rev-parse HEAD` | |
NEEDS_TAG=`git describe --contains ${GIT_COMMIT} 2>/dev/null` | |
#only tag if no tag already | |
if [[ -z "$NEEDS_TAG" ]]; then | |
git tag ${NEW_TAG} | |
echo "Tagged with $NEW_TAG" | |
git push --tags | |
else | |
echo "Already a tag on this commit" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment