From ecd94be1a354105a6dcacfdcb63af7e864a06b38 Mon Sep 17 00:00:00 2001 From: Phil Phillips Date: Tue, 14 Jun 2022 17:30:43 -0500 Subject: [PATCH 1/3] feat: Allow check of diff between branch files to be configurable --- README.md | 2 ++ action.yml | 4 ++++ entrypoint.sh | 11 +++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bacb5d8..12c31c0 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Features: new_string: "** Automatic pull request**" get_diff: true ignore_users: "dependabot" + check_diff: true ``` @@ -62,6 +63,7 @@ Features: | github_token | Yes | `""` | GitHub token `${{ secrets.GITHUB_TOKEN }}` | | assignee | No | `""` | Assignee's usernames. | | body | No | *list of commits* | Pull request body. | +| check_diff | No | `true` | Whether to check if files differ before creating a PR. | | draft | No | `false` | Whether to mark it as a draft. | | get_diff | No | `false` | Whether to replace predefined comments with differences between branches - see details below. | | ignore_users | No | `"dependabot"` | List of users to ignore, coma separated. | diff --git a/action.yml b/action.yml index 1476be0..1d2d605 100644 --- a/action.yml +++ b/action.yml @@ -60,6 +60,10 @@ inputs: description: List of users to ignore, coma separated required: false default: "dependabot" + check_diff: + description: Whether to check if files differ before creating a PR + required: false + default: "true" outputs: url: description: Pull request URL. diff --git a/entrypoint.sh b/entrypoint.sh index 7a2b63f..8417002 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,6 +20,7 @@ echo " get_diff: ${INPUT_GET_DIFF}" echo " old_string: ${INPUT_OLD_STRING}" echo " new_string: ${INPUT_NEW_STRING}" echo " ignore_users: ${INPUT_IGNORE_USERS}" +echo " check_diff: ${INPUT_CHECK_DIFF}" # Skip whole script to not cause errors IFS=',' read -r -a IGNORE_USERS <<< "${INPUT_IGNORE_USERS}" @@ -65,10 +66,12 @@ if [[ $(git rev-parse --revs-only "${SOURCE_BRANCH}") == $(git rev-parse --revs- exit 0 fi -echo -e "\nComparing branches by diff..." -if [[ -z $(git diff "remotes/origin/${TARGET_BRANCH}...remotes/origin/${SOURCE_BRANCH}") ]]; then - echo -e "\n[INFO] Both branches are the same. No action needed." - exit 0 +if [[ "${INPUT_CHECK_DIFF}" == "true" ]]; then + echo -e "\nComparing branches by diff..." + if [[ -z $(git diff "remotes/origin/${TARGET_BRANCH}...remotes/origin/${SOURCE_BRANCH}") ]]; then + echo -e "\n[INFO] Both branches are the same. No action needed." + exit 0 + fi fi # sed has problems with putting multi-line strings in the next steps, and later we use # for sed From c43145a01ab3f6d7880d1f5e6fcb72228f962de3 Mon Sep 17 00:00:00 2001 From: Krzysztof Szyper <45788587+ChristophShyper@users.noreply.github.com> Date: Thu, 30 Jun 2022 09:16:58 +0200 Subject: [PATCH 2/3] Replace input `check_diff` with `allow_no_diff` This will allow for better understanding of underlying logic. --- README.md | 6 +++--- action.yml | 6 +++--- entrypoint.sh | 10 ++++++---- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 12c31c0..a6f5197 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Features: * Can assign `assignee`, `reviewer`, one or more `label`, a `milestone` or mark it as a `draft` * Can replace any `old_string` inside a pull request template with a `new_string`. Or put commits' subjects in place of `old_string`. * When `get_diff` is `true` will add list of commits in place of `` and list of modified files in place of `` in a pull request template. - +* When `allow_no_diff` is set to true will continue execution and create pull request even if both branches have no differences, e.g. having only a merge commit. ## Badge swag [![Master branch](https://github.com/devops-infra/action-pull-request/workflows/Master%20branch/badge.svg)](https://github.com/devops-infra/action-pull-request/actions?query=workflow%3A%22Master+branch%22) @@ -54,16 +54,16 @@ Features: new_string: "** Automatic pull request**" get_diff: true ignore_users: "dependabot" - check_diff: true + allow_no_diff: false ``` | Input Variable | Required | Default | Description | | -------------- | -------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------ | | github_token | Yes | `""` | GitHub token `${{ secrets.GITHUB_TOKEN }}` | +| allow_no_diff | No | `false` | Allows to continue on merge commits with no diffs. | | assignee | No | `""` | Assignee's usernames. | | body | No | *list of commits* | Pull request body. | -| check_diff | No | `true` | Whether to check if files differ before creating a PR. | | draft | No | `false` | Whether to mark it as a draft. | | get_diff | No | `false` | Whether to replace predefined comments with differences between branches - see details below. | | ignore_users | No | `"dependabot"` | List of users to ignore, coma separated. | diff --git a/action.yml b/action.yml index 1d2d605..41d2b1f 100644 --- a/action.yml +++ b/action.yml @@ -60,10 +60,10 @@ inputs: description: List of users to ignore, coma separated required: false default: "dependabot" - check_diff: - description: Whether to check if files differ before creating a PR + allow_no_diff: + description: Allows to continue on merge commits with no diffs required: false - default: "true" + default: "false" outputs: url: description: Pull request URL. diff --git a/entrypoint.sh b/entrypoint.sh index 8417002..27b69d8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,7 +20,7 @@ echo " get_diff: ${INPUT_GET_DIFF}" echo " old_string: ${INPUT_OLD_STRING}" echo " new_string: ${INPUT_NEW_STRING}" echo " ignore_users: ${INPUT_IGNORE_USERS}" -echo " check_diff: ${INPUT_CHECK_DIFF}" +echo " allow_no_diff: ${INPUT_ALLOW_NO_DIFF}" # Skip whole script to not cause errors IFS=',' read -r -a IGNORE_USERS <<< "${INPUT_IGNORE_USERS}" @@ -66,9 +66,11 @@ if [[ $(git rev-parse --revs-only "${SOURCE_BRANCH}") == $(git rev-parse --revs- exit 0 fi -if [[ "${INPUT_CHECK_DIFF}" == "true" ]]; then - echo -e "\nComparing branches by diff..." - if [[ -z $(git diff "remotes/origin/${TARGET_BRANCH}...remotes/origin/${SOURCE_BRANCH}") ]]; then +echo -e "\nComparing branches by diff..." +if [[ -z $(git diff "remotes/origin/${TARGET_BRANCH}...remotes/origin/${SOURCE_BRANCH}") ]]; then + if [[ "${INPUT_ALLOW_NO_DIFF}" == "true" ]]; then + echo -e "\n[INFO] Both branches are the same. Continuing." + else echo -e "\n[INFO] Both branches are the same. No action needed." exit 0 fi From 396ddec529de76ef259b3a14b3359d2ec603f43f Mon Sep 17 00:00:00 2001 From: Krzysztof Szyper <45788587+ChristophShyper@users.noreply.github.com> Date: Thu, 30 Jun 2022 09:21:26 +0200 Subject: [PATCH 3/3] Bump release to 0.5.0 --- Makefile | 2 +- README.md | 6 +++--- action.yml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 941f5b3..458c832 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ phony: help # Release tag for the action -VERSION := v0.4.2 +VERSION := v0.5.0 # GitHub Actions bogus variables GITHUB_REF ?= refs/heads/null diff --git a/README.md b/README.md index a6f5197..4319fe6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Features: ```yaml - name: Run the Action - uses: devops-infra/action-pull-request@v0.4.2 + uses: devops-infra/action-pull-request@v0.5.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} source_branch: development @@ -118,7 +118,7 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - name: Create pull request - uses: devops-infra/action-pull-request@v0.4.2 + uses: devops-infra/action-pull-request@v0.5.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} title: Automatic pull request @@ -140,7 +140,7 @@ jobs: fetch-depth: 0 - name: Run the Action if: startsWith(github.ref, 'refs/heads/feature') - uses: devops-infra/action-pull-request@v0.4.2 + uses: devops-infra/action-pull-request@v0.5.0 with: github_token: ${{ secrets.GITHUB_TOKEN }} title: ${{ github.event.commits[0].message }} diff --git a/action.yml b/action.yml index 41d2b1f..4a53a1a 100644 --- a/action.yml +++ b/action.yml @@ -69,7 +69,7 @@ outputs: description: Pull request URL. runs: using: docker - image: docker://devopsinfra/action-pull-request:v0.4.2 + image: docker://devopsinfra/action-pull-request:v0.5.0 env: GITHUB_TOKEN: ${{ inputs.github_token }} branding: