Last active
June 5, 2022 04:38
-
-
Save euaaron/67d27e96c67268e53be15d9f6c91f625 to your computer and use it in GitHub Desktop.
GitHook - package.json version bump (main=major, feat=minor, other=patch)
This file contains hidden or 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/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