Skip to content

Commit 873b495

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 873b495

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

action.yml

Lines changed: 6 additions & 0 deletions
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

Lines changed: 9 additions & 4 deletions
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)