Skip to content

Instantly share code, notes, and snippets.

@030
Last active June 22, 2019 13:07
Show Gist options
  • Save 030/db4d7c5495d751a1001fc425e1f14302 to your computer and use it in GitHub Desktop.
Save 030/db4d7c5495d751a1001fc425e1f14302 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
#based on: https://stackoverflow.com/a/27332476/2777965
#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]}
VNUM2=${VERSION_BITS[1]}
VNUM3=${VERSION_BITS[2]}
VNUM3=$((VNUM3+1))
#create new tag
NEW_TAG="$VNUM1.$VNUM2.$VNUM3"
echo "Updating $VERSION to $NEW_TAG"
LATEST_TAG=$(git tag | tail -1)
TAG_COMMIT=$(git rev-list -n 1 $LATEST_TAG)
echo $TAG_COMMIT
LATEST_COMMIT=$(git rev-parse HEAD)
echo $LATEST_COMMIT
if [ "${LATEST_COMMIT}" != "${TAG_COMMIT}" ]; then
echo "Tagged with $NEW_TAG (Ignoring fatal:cannot describe - this means commit is untagged) "
git tag $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