Created
October 4, 2020 16:59
-
-
Save pocc/fc4ff0f3c0867fc21f0cd2764c9d2d4b to your computer and use it in GitHub Desktop.
Increment patch in a git project and increment version in the package.json of node project
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
# Auto increment Z of X.Y.Z if a new pull request is merged | |
LATEST_TAG=$(git describe --abbrev=0) | |
INITIAL_TAG=$LATEST_TAG | |
for i in $(git log $LATEST_TAG..HEAD --format="%cI %H" | sort -rV | grep "Merge pull request" | awk '{ print $2 }'); do | |
NEXT_TAG=$(echo $LATEST_TAG | awk -F. -v OFS=. '{$NF++;print}') | |
BODY_ABBREV="$(git show $i --format=%b | head -n1)" | |
git tag -a "$NEXT_TAG" -m "Tag for $BODY_ABBREV" $i | |
printf "Tagging commit $i with $NEXT_TAG and pushing to master\n" | |
git push origin "$NEXT_TAG" | |
LATEST_TAG=$NEXT_TAG | |
done | |
# Change package.json version to latest (should be both GNU/BSD sed compatible) | |
sed -i.bak "s/version\(.*\)$/version\": \"$LATEST_TAG\",/g" package.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment