Last active
May 7, 2024 23:31
-
-
Save florianpasteur/c9764ddc56042a075662e1adcfbcc0b4 to your computer and use it in GitHub Desktop.
Post commit hook to increment version of npm package
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
# Install command: | |
# curl https://gist.githubusercontent.com/florianpasteur/c9764ddc56042a075662e1adcfbcc0b4/raw -o .git/hooks/post-commit && chmod +x .git/hooks/post-commit | |
IS_AMEND=$(ps -ocommand= -p $PPID | grep -e '--amend'); | |
if [ -n "$IS_AMEND" ]; then | |
exit 0; | |
fi | |
if git diff package.json package-lock.json; then | |
git stash | |
npm version --no-git-tag-version patch | |
git add package.json package-lock.json | |
git commit --amend --no-edit --no-verify | |
git stash pop | |
else | |
npm version --no-git-tag-version patch | |
git add package.json package-lock.json | |
git commit --amend --no-edit --no-verify | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment