Skip to content

Commit cb1c729

Browse files
fix: Refuse to push on pull_request event
Avoid merging pull requests, which is unlikely to be the intended purpose of using this action.
1 parent e8f5b01 commit cb1c729

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ jobs:
7676
| `git_name` | Name used to configure git (for git operations) | `github-actions[bot]` |
7777
| `git_email` | Email address used to configure git (for git operations) | `github-actions[bot]@users.noreply.github.com` |
7878
| `push` | Define if the changes should be pushed to the branch. | true |
79+
| `merge` | Define if the changes should be pushed even on the pull_request event, immediately merging the pull request. | false |
80+
7981
| `commit` | Define if the changes should be committed to the branch. | true |
8082
| `commitizen_version` | Specify the version to be used by commitizen. Eg: `2.21.0` | latest |
8183
| `changelog` | Create changelog when bumping the version | true |

action.yml

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ inputs:
2121
description: 'If true the bump commit is pushed to the remote repository'
2222
required: false
2323
default: "true"
24+
merge:
25+
description: >
26+
If true, the bump commit is pushed to the remote repository even when the
27+
action is run on the pull_request event, immediately merging the pull request
28+
required: false
29+
default: "false"
2430
prerelease:
2531
description: 'Set as prerelease version'
2632
required: false

entrypoint.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@ echo "Repository: ${INPUT_REPOSITORY}"
7272
echo "Actor: ${GITHUB_ACTOR}"
7373

7474
if [[ $INPUT_PUSH == 'true' ]]; then
75-
echo "Pushing to branch..."
76-
REMOTE_REPO="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_REPOSITORY}.git"
77-
git pull "$REMOTE_REPO" "$INPUT_BRANCH"
78-
git push "$REMOTE_REPO" "HEAD:${INPUT_BRANCH}" --tags
75+
if [[ $INPUT_MERGE != 'true' && $GITHUB_EVENT_NAME == 'pull_request' ]]; then
76+
echo "Refusing to push on pull_request event since that would merge the pull request." >&2
77+
echo "You probably want to run on push to your default branch instead." >&2
78+
else
79+
echo "Pushing to branch..."
80+
REMOTE_REPO="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_REPOSITORY}.git"
81+
git pull "$REMOTE_REPO" "$INPUT_BRANCH"
82+
git push "$REMOTE_REPO" "HEAD:${INPUT_BRANCH}" --tags
83+
fi
7984
else
8085
echo "Not pushing"
8186
fi

0 commit comments

Comments
 (0)