Skip to content

Instantly share code, notes, and snippets.

@euaaron
Last active June 5, 2022 04:38
Show Gist options
  • Select an option

  • Save euaaron/67d27e96c67268e53be15d9f6c91f625 to your computer and use it in GitHub Desktop.

Select an option

Save euaaron/67d27e96c67268e53be15d9f6c91f625 to your computer and use it in GitHub Desktop.
GitHook - package.json version bump (main=major, feat=minor, other=patch)
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
commit_message=$(git log -1 --pretty=%B | cat)
branch=$(git rev-parse --abbrev-ref HEAD | cat)
version="patch"
if $(echo $branch | grep -q "main")
then
echo "Do not push to main branch, do a PR instead."
exit -1
fi
if $(echo $commit_message | grep -q "Release" || echo $commit_message | grep -q "version bump")
then
echo "Version Bump: skipping hook."
exit 0
fi
if $(echo $commit_message | grep -q "!:")
then
version="major"
elif $(echo $commit_message | grep -q "feat")
then
version="minor"
fi
if $(echo $version | grep -q "major")
then
yarn version --no-commit-hooks --$version
else
yarn version --no-git-tag-version --no-commit-hooks --$version
fi
git add package.json
version=$(node -p -e "require('./package.json').version")
git commit -m "chore: version bump to v$version"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment