diff --git a/README.md b/README.md index 5b940b9..5ca8668 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,8 @@ jobs: | `git_name` | Name used to configure git (for git operations) | `github-actions[bot]` | | `git_email` | Email address used to configure git (for git operations) | `github-actions[bot]@users.noreply.github.com` | | `push` | Define if the changes should be pushed to the branch. | true | +| `merge` | Define if the changes should be pushed even on the pull_request event, immediately merging the pull request. | false | + | `commit` | Define if the changes should be committed to the branch. | true | | `commitizen_version` | Specify the version to be used by commitizen. Eg: `2.21.0` | latest | | `changelog` | Create changelog when bumping the version | true | diff --git a/action.yml b/action.yml index 9f76626..2821930 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,12 @@ inputs: description: 'If true the bump commit is pushed to the remote repository' required: false default: "true" + merge: + description: > + If true, the bump commit is pushed to the remote repository even when the + action is run on the pull_request event, immediately merging the pull request + required: false + default: "false" prerelease: description: 'Set as prerelease version' required: false diff --git a/entrypoint.sh b/entrypoint.sh index 5ddd3c1..6cc1c39 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,7 +3,7 @@ set -e if [[ -z $INPUT_GITHUB_TOKEN ]]; then - echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".' + echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".' >&2 exit 1 fi @@ -26,6 +26,8 @@ echo "${PIP_CMD[@]}" "${PIP_CMD[@]}" echo "Commitizen version: $(cz version)" +PREV_REV="$(cz version --project)" + CZ_CMD=('cz') if [[ $INPUT_NO_RAISE ]]; then CZ_CMD+=('--no-raise' "$INPUT_NO_RAISE") @@ -56,6 +58,9 @@ else fi REV="$(cz version --project)" +if [[ $REV == "$PREV_REV" ]]; then + INPUT_PUSH='false' +fi echo "REVISION=${REV}" >>"$GITHUB_ENV" echo "::set-output name=version::${REV}" @@ -67,10 +72,15 @@ echo "Repository: ${INPUT_REPOSITORY}" echo "Actor: ${GITHUB_ACTOR}" if [[ $INPUT_PUSH == 'true' ]]; then - echo "Pushing to branch..." - REMOTE_REPO="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_REPOSITORY}.git" - git pull "$REMOTE_REPO" "$INPUT_BRANCH" - git push "$REMOTE_REPO" "HEAD:${INPUT_BRANCH}" --tags + if [[ $INPUT_MERGE != 'true' && $GITHUB_EVENT_NAME == 'pull_request' ]]; then + echo "Refusing to push on pull_request event since that would merge the pull request." >&2 + echo "You probably want to run on push to your default branch instead." >&2 + else + echo "Pushing to branch..." + REMOTE_REPO="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_REPOSITORY}.git" + git pull "$REMOTE_REPO" "$INPUT_BRANCH" + git push "$REMOTE_REPO" "HEAD:${INPUT_BRANCH}" --tags + fi else echo "Not pushing" fi