Last active
June 27, 2024 08:17
-
-
Save dsheiko/620c7b0dcfbda39ce959eab70c5b2077 to your computer and use it in GitHub Desktop.
Git-hook to create a tag automatically based on lately committed package.json version
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 | |
version=`git diff HEAD^..HEAD -- "$(git rev-parse --show-toplevel)"/package.json | grep -m 1 '^\+.*version' | sed -s 's/[^A-Z0-9\.\-]//g'` | |
if [[ ! $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(\-[A-Z]+\.[0-9]+)?$ ]]; then | |
echo -e "Skip tag: invalid version '$version'" | |
exit 1 | |
fi | |
git tag -a "v$version" -m "`git log -1 --format=%s`" | |
echo "Created a new tag, v$version" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is incredibly useful. Thank you!
One note for anyone on OS X, you will need to remove the
-s
flag from thesed
call on line 2