Last active
April 25, 2020 22:03
-
-
Save olgusirman/4afaf9eb2bf36e5ce6bcdec3a6123d82 to your computer and use it in GitHub Desktop.
Gets latest tag, increment build number and version number, set a commit with this tag and push
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 Tags Latest number, increment and set build and version number | |
echo "Please set an input your tag description, ticket number etc." | |
read TAG_DESCRIPTION | |
# get latest tag number | |
VERSION=`git describe --abbrev=0 --tags` | |
echo "CURRENT VERSION => $VERSION" | |
#replace . with space so can split into an array | |
VERSION_BITS=(${VERSION//./ }) | |
#get tag number parts for version and build numbers | |
VNUM1=${VERSION_BITS[0]} | |
VNUM2=${VERSION_BITS[1]} | |
VNUM3=${VERSION_BITS[2]} | |
### Increment version numer | |
VNUM2=$((VNUM2+1)) | |
# bump version number | |
xcrun agvtool new-marketing-version $VNUM1.$VNUM2 | |
# Increment build number | |
VNUM3=$((VNUM3+1)) | |
# set new build number | |
# use AGVTool for set new build number | |
agvtool new-version -all $VNUM3 | |
echo "Updated new-version VNUM3 => $VNUM3" | |
# add and push that commit | |
git add . | |
git commit -m "Bump version and build number to $VNUM1.$VNUM2.$VNUM3" | |
git push | |
#create new tag | |
NEW_TAG="v$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 -a $NEW_TAG -m "$TAG_DESCRIPTION" | |
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