Skip to content

Instantly share code, notes, and snippets.

@florianpasteur
Last active May 7, 2024 23:31
Show Gist options
  • Save florianpasteur/c9764ddc56042a075662e1adcfbcc0b4 to your computer and use it in GitHub Desktop.
Save florianpasteur/c9764ddc56042a075662e1adcfbcc0b4 to your computer and use it in GitHub Desktop.
Post commit hook to increment version of npm package
# 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