From 2a51a5ea699a8f7800d9cbe6c3c691bc97dc8bb8 Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Thu, 19 May 2022 11:33:54 -0700 Subject: [PATCH 1/3] fix: Print error message to stderr --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 5ddd3c1..14762b2 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 From e8f5b017012086364f961d1ac65954ae91a9eb04 Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Wed, 11 May 2022 14:30:15 -0400 Subject: [PATCH 2/3] fix: Don't pull or push with nothing to push Check whether there are any commits to push by comparing the project version before and after bumping. --- entrypoint.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 14762b2..9d8ed2f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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}" From cb1c7296fad6bbf53a1ed266f21f887a112d9903 Mon Sep 17 00:00:00 2001 From: Kurt von Laven Date: Thu, 19 May 2022 11:32:22 -0700 Subject: [PATCH 3/3] fix: Refuse to push on pull_request event Avoid merging pull requests, which is unlikely to be the intended purpose of using this action. --- README.md | 2 ++ action.yml | 6 ++++++ entrypoint.sh | 13 +++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) 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 9d8ed2f..6cc1c39 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -72,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