Skip to content

fix: Refuse to push on pull_request event #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down Expand Up @@ -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}"

Expand All @@ -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
Expand Down