Last active
March 29, 2017 15:00
-
-
Save hghandri/ee03ecb688969bd6b8e6c072289242b1 to your computer and use it in GitHub Desktop.
Semantic Versioning : Create automatically a tag from specific naming Pull Request
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 | |
#get highest tag number | |
VERSION=` 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 | |
MAJOR=${VERSION_BITS[0]} | |
MINOR=${VERSION_BITS[1]} | |
PATCH=${VERSION_BITS[2]} | |
if git log -1 --pretty=%B | -Fxq "[MAJOR]" | |
then | |
MAJOR=$((MAJOR+1)) | |
elif git log -1 --pretty=%B | grep -Fxq "[MINOR]" | |
then | |
MINOR=$((MINOR+1)) | |
elif git log -1 --pretty=%B | grep -Fxq "[PATCH]" | |
then | |
PATCH=$((PATCH+1)) | |
else | |
MINOR=$((MINOR+1)) | |
fi | |
#create new tag | |
NEW_TAG="$MAJOR.$MINOR.$PATCH" | |
echo "Updating $VERSION to $NEW_TAG" | |
#get current and see if it already has a tag | |
GIT_COMMIT=`git rev-parse HEAD` | |
NEEDS_TAG=`git describe --contains $GIT_COMMIT` | |
#only tag if no tag already (would be better if the git describe command above could have a silent option) | |
if [ -z "$NEEDS_TAG" ]; then | |
echo "Tagged with $NEW_TAG (Ignoring fatal:cannot describe - this means commit is untagged) " | |
echo "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
Use specific name for Pull Request :
[MAJOR] TITLE PULL REQUEST --> Increment first digit 1.0.0
[MINOR] TITLE PULL REQUEST --> Increment second digit 1.1.0
[PATCH] TITLE PULL REQUEST --> Increment third digit 1.1.1