Skip to content

Commit 0d10fe0

Browse files
authored
Merge pull request #36 from Kurt-von-Laven/dont-merge-pull-requests
2 parents a868ba9 + cb1c729 commit 0d10fe0

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

README.md

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

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: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
if [[ -z $INPUT_GITHUB_TOKEN ]]; then
6-
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".'
6+
echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}".' >&2
77
exit 1
88
fi
99

@@ -26,6 +26,8 @@ echo "${PIP_CMD[@]}"
2626
"${PIP_CMD[@]}"
2727
echo "Commitizen version: $(cz version)"
2828

29+
PREV_REV="$(cz version --project)"
30+
2931
CZ_CMD=('cz')
3032
if [[ $INPUT_NO_RAISE ]]; then
3133
CZ_CMD+=('--no-raise' "$INPUT_NO_RAISE")
@@ -56,6 +58,9 @@ else
5658
fi
5759

5860
REV="$(cz version --project)"
61+
if [[ $REV == "$PREV_REV" ]]; then
62+
INPUT_PUSH='false'
63+
fi
5964
echo "REVISION=${REV}" >>"$GITHUB_ENV"
6065
echo "::set-output name=version::${REV}"
6166

@@ -67,10 +72,15 @@ echo "Repository: ${INPUT_REPOSITORY}"
6772
echo "Actor: ${GITHUB_ACTOR}"
6873

6974
if [[ $INPUT_PUSH == 'true' ]]; then
70-
echo "Pushing to branch..."
71-
REMOTE_REPO="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_REPOSITORY}.git"
72-
git pull "$REMOTE_REPO" "$INPUT_BRANCH"
73-
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
7484
else
7585
echo "Not pushing"
7686
fi

0 commit comments

Comments
 (0)