From f45f93b17878521835a47b91e5fd277c3ab9e9bb Mon Sep 17 00:00:00 2001 From: Stefan Meschke Date: Tue, 4 Apr 2023 10:16:52 +0200 Subject: [PATCH 01/12] =?UTF-8?q?=E2=9C=A8=20do=20not=20merge=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/do-not-merge.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/do-not-merge.yml diff --git a/.github/workflows/do-not-merge.yml b/.github/workflows/do-not-merge.yml new file mode 100644 index 00000000..a43d3f08 --- /dev/null +++ b/.github/workflows/do-not-merge.yml @@ -0,0 +1,17 @@ +name: Do Not Merge +on: + pull_request: + types: [labeled, unlabeled] + +jobs: + do-not-merge: + # contains(search, item) is not case-sensitive + # Therefore 'Do Not Merge' and 'DO NOT MERGE' will also match + # see https://docs.github.com/en/actions/learn-github-actions/expressions#contains + if: contains(github.event.pull_request.labels.*.name, 'do not merge') + runs-on: ubuntu-latest + steps: + - name: fail if label exists + run: | + echo "This PR has the label 'do not merge'." + exit 1 From f1a3210679e62852c38ea5597b34c3dcec9014ab Mon Sep 17 00:00:00 2001 From: Stefan Meschke Date: Tue, 4 Apr 2023 11:02:01 +0200 Subject: [PATCH 02/12] =?UTF-8?q?=F0=9F=8E=A8=20rename=20step?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 0x46616c6b <0x46616c6b@users.noreply.github.com> --- .github/workflows/do-not-merge.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/do-not-merge.yml b/.github/workflows/do-not-merge.yml index a43d3f08..e51947e2 100644 --- a/.github/workflows/do-not-merge.yml +++ b/.github/workflows/do-not-merge.yml @@ -9,6 +9,7 @@ jobs: # Therefore 'Do Not Merge' and 'DO NOT MERGE' will also match # see https://docs.github.com/en/actions/learn-github-actions/expressions#contains if: contains(github.event.pull_request.labels.*.name, 'do not merge') + name: Check runs-on: ubuntu-latest steps: - name: fail if label exists From 7cc9412ca6898728fd8dada6484d8e69d4740454 Mon Sep 17 00:00:00 2001 From: Falk Puschner Date: Thu, 4 May 2023 15:19:20 +0200 Subject: [PATCH 03/12] :art: make reusable workflow --- ...ot-merge.yml => template_do_not_merge.yml} | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) rename .github/workflows/{do-not-merge.yml => template_do_not_merge.yml} (54%) diff --git a/.github/workflows/do-not-merge.yml b/.github/workflows/template_do_not_merge.yml similarity index 54% rename from .github/workflows/do-not-merge.yml rename to .github/workflows/template_do_not_merge.yml index e51947e2..ff31cbe4 100644 --- a/.github/workflows/do-not-merge.yml +++ b/.github/workflows/template_do_not_merge.yml @@ -1,18 +1,26 @@ name: Do Not Merge + on: - pull_request: - types: [labeled, unlabeled] + workflow_call: + inputs: + label: + required: false + type: string + default: do not merge jobs: do-not-merge: + + name: Check + runs-on: ubuntu-22.04 + # contains(search, item) is not case-sensitive # Therefore 'Do Not Merge' and 'DO NOT MERGE' will also match # see https://docs.github.com/en/actions/learn-github-actions/expressions#contains - if: contains(github.event.pull_request.labels.*.name, 'do not merge') - name: Check - runs-on: ubuntu-latest + if: contains(github.event.pull_request.labels.*.name, ${{ inputs.label }}) + steps: - name: fail if label exists run: | - echo "This PR has the label 'do not merge'." + echo "This PR has the label '${{ inputs.label }}'." exit 1 From 65bd8216b313a6d0827bb15e3b5541d0d32b9045 Mon Sep 17 00:00:00 2001 From: Falk Puschner Date: Thu, 4 May 2023 15:31:40 +0200 Subject: [PATCH 04/12] :art: add minor improvements --- .github/workflows/template_do_not_merge.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/template_do_not_merge.yml b/.github/workflows/template_do_not_merge.yml index ff31cbe4..bf742d83 100644 --- a/.github/workflows/template_do_not_merge.yml +++ b/.github/workflows/template_do_not_merge.yml @@ -17,10 +17,9 @@ jobs: # contains(search, item) is not case-sensitive # Therefore 'Do Not Merge' and 'DO NOT MERGE' will also match # see https://docs.github.com/en/actions/learn-github-actions/expressions#contains - if: contains(github.event.pull_request.labels.*.name, ${{ inputs.label }}) - steps: - name: fail if label exists + if: contains(github.event.pull_request.labels.*.name, ${{ inputs.label }}) run: | echo "This PR has the label '${{ inputs.label }}'." exit 1 From c56b97db1743d562cd4e9e0c3261425b10ec0a26 Mon Sep 17 00:00:00 2001 From: Falk Puschner Date: Thu, 4 May 2023 15:34:02 +0200 Subject: [PATCH 05/12] :art: quote input --- .github/workflows/template_do_not_merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/template_do_not_merge.yml b/.github/workflows/template_do_not_merge.yml index bf742d83..6a7e11c8 100644 --- a/.github/workflows/template_do_not_merge.yml +++ b/.github/workflows/template_do_not_merge.yml @@ -19,7 +19,7 @@ jobs: # see https://docs.github.com/en/actions/learn-github-actions/expressions#contains steps: - name: fail if label exists - if: contains(github.event.pull_request.labels.*.name, ${{ inputs.label }}) + if: contains(github.event.pull_request.labels.*.name, '${{ inputs.label }}') run: | echo "This PR has the label '${{ inputs.label }}'." exit 1 From 2d727ad7b85bd22b895d00956a2e77981a75051d Mon Sep 17 00:00:00 2001 From: Falk Puschner Date: Thu, 4 May 2023 15:35:22 +0200 Subject: [PATCH 06/12] :art: simplify inputs --- .github/workflows/template_do_not_merge.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/template_do_not_merge.yml b/.github/workflows/template_do_not_merge.yml index 6a7e11c8..ebd9f842 100644 --- a/.github/workflows/template_do_not_merge.yml +++ b/.github/workflows/template_do_not_merge.yml @@ -2,11 +2,6 @@ name: Do Not Merge on: workflow_call: - inputs: - label: - required: false - type: string - default: do not merge jobs: do-not-merge: @@ -19,7 +14,7 @@ jobs: # see https://docs.github.com/en/actions/learn-github-actions/expressions#contains steps: - name: fail if label exists - if: contains(github.event.pull_request.labels.*.name, '${{ inputs.label }}') + if: contains(github.event.pull_request.labels.*.name, 'do not merge') run: | - echo "This PR has the label '${{ inputs.label }}'." + echo "This PR has the label 'do not merge'." exit 1 From 1afcb2d8324d7ecd0dfa41b1ba5ac45a4078cf28 Mon Sep 17 00:00:00 2001 From: Falk Puschner Date: Thu, 4 May 2023 15:40:48 +0200 Subject: [PATCH 07/12] :art: try to use inputs --- .github/workflows/template_do_not_merge.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/template_do_not_merge.yml b/.github/workflows/template_do_not_merge.yml index ebd9f842..3b413f49 100644 --- a/.github/workflows/template_do_not_merge.yml +++ b/.github/workflows/template_do_not_merge.yml @@ -2,6 +2,11 @@ name: Do Not Merge on: workflow_call: + inputs: + label: + required: false + type: string + default: do not merge jobs: do-not-merge: @@ -14,7 +19,7 @@ jobs: # see https://docs.github.com/en/actions/learn-github-actions/expressions#contains steps: - name: fail if label exists - if: contains(github.event.pull_request.labels.*.name, 'do not merge') + if: contains(github.event.pull_request.labels.*.name, inputs.label) run: | - echo "This PR has the label 'do not merge'." + echo "This PR has the label '${{ inputs.label }}'." exit 1 From d564b9aeba9d8fad13959267644e7513cf377452 Mon Sep 17 00:00:00 2001 From: Falk Puschner Date: Thu, 4 May 2023 15:44:17 +0200 Subject: [PATCH 08/12] :truck: rename action --- .../{template_do_not_merge.yml => template_merge_block.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{template_do_not_merge.yml => template_merge_block.yml} (100%) diff --git a/.github/workflows/template_do_not_merge.yml b/.github/workflows/template_merge_block.yml similarity index 100% rename from .github/workflows/template_do_not_merge.yml rename to .github/workflows/template_merge_block.yml From d9faf2ecf248c80e311ab76fde621d9646219d06 Mon Sep 17 00:00:00 2001 From: Falk Puschner Date: Thu, 4 May 2023 15:49:41 +0200 Subject: [PATCH 09/12] :memo: update merge block documentation --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 0b91202e..75fd0bfd 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,27 @@ jobs: +### Merge Block + +
+The action can be used to block the merge if a do not merge label is set. + +```yml +name: Merge Block + +on: + pull_request: + types: [opened, labeled, unlabeled] + +jobs: + block: + uses: Staffbase/gha-workflows/.github/workflows/template_do_not_merge.yml@v2.0.0 + with: + # optional: name of the label if the PR should not be merged, default: do not merge + label: merge block +``` +
+ ### Release Drafter
From 990a71219d330845656a6217d1d1e523a0bc079c Mon Sep 17 00:00:00 2001 From: Falk Puschner Date: Thu, 4 May 2023 15:52:07 +0200 Subject: [PATCH 10/12] :memo: update merge name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75fd0bfd..abe8349a 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ on: jobs: block: - uses: Staffbase/gha-workflows/.github/workflows/template_do_not_merge.yml@v2.0.0 + uses: Staffbase/gha-workflows/.github/workflows/template_merge_block.yml@v2.0.0 with: # optional: name of the label if the PR should not be merged, default: do not merge label: merge block From 6da6b80c611537ccf2fda254d71f7ef2fbcce9ef Mon Sep 17 00:00:00 2001 From: Falk Scheerschmidt Date: Thu, 25 Apr 2024 11:54:42 +0200 Subject: [PATCH 11/12] Add comment for merge block workflow --- .github/workflows/template_merge_block.yml | 40 +++++++++++++++++++--- README.md | 3 ++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/.github/workflows/template_merge_block.yml b/.github/workflows/template_merge_block.yml index 3b413f49..26f3b6a7 100644 --- a/.github/workflows/template_merge_block.yml +++ b/.github/workflows/template_merge_block.yml @@ -7,18 +7,48 @@ on: required: false type: string default: do not merge + comment: + required: false + type: boolean + default: true jobs: do-not-merge: - name: Check runs-on: ubuntu-22.04 - # contains(search, item) is not case-sensitive - # Therefore 'Do Not Merge' and 'DO NOT MERGE' will also match - # see https://docs.github.com/en/actions/learn-github-actions/expressions#contains steps: - - name: fail if label exists + - name: Find Comment + if: inputs.comment + uses: peter-evans/find-comment@v3.1.0 + id: comment + with: + issue-number: ${{ github.event.pull_request.number }} + body-includes: ⚠️ **The merge is blocked.** + + - name: Comment on PR + if: inputs.comment && contains(github.event.pull_request.labels.*.name, inputs.label) && steps.comment.outputs.comment-id == '' + uses: peter-evans/create-or-update-comment@v4.0.0 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + ⚠️ **The merge is blocked.** + + Remove the label '${{ inputs.label }}' to proceed. + + - name: Delete Comment + if: inputs.comment && !contains(github.event.pull_request.labels.*.name, inputs.label) && steps.comment.outputs.comment-id != '' + uses: actions/github-script@v7.0.1 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.rest.issues.deleteComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: ${{ steps.comment.outputs.comment-id }} + }) + + - name: Fail if label exists to block merge if: contains(github.event.pull_request.labels.*.name, inputs.label) run: | echo "This PR has the label '${{ inputs.label }}'." diff --git a/README.md b/README.md index abe8349a..096a6e81 100644 --- a/README.md +++ b/README.md @@ -249,7 +249,10 @@ jobs: with: # optional: name of the label if the PR should not be merged, default: do not merge label: merge block + # optional: comment when the PR is blocked, default: true + comment: true ``` +
### Release Drafter From 551b37b4e76a656deaeb272969bafa74fc1fd9f6 Mon Sep 17 00:00:00 2001 From: 0x46616c6b <0x46616c6b@users.noreply.github.com> Date: Thu, 25 Apr 2024 13:32:30 +0200 Subject: [PATCH 12/12] Apply suggestions from code review Co-authored-by: Falk Puschner --- .github/workflows/template_merge_block.yml | 6 +++--- README.md | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/template_merge_block.yml b/.github/workflows/template_merge_block.yml index 26f3b6a7..fc184760 100644 --- a/.github/workflows/template_merge_block.yml +++ b/.github/workflows/template_merge_block.yml @@ -6,7 +6,7 @@ on: label: required: false type: string - default: do not merge + default: "do not merge" comment: required: false type: boolean @@ -24,7 +24,7 @@ jobs: id: comment with: issue-number: ${{ github.event.pull_request.number }} - body-includes: ⚠️ **The merge is blocked.** + body-includes: ⚠️ **This Pull Request is not ready to be merged.** - name: Comment on PR if: inputs.comment && contains(github.event.pull_request.labels.*.name, inputs.label) && steps.comment.outputs.comment-id == '' @@ -32,7 +32,7 @@ jobs: with: issue-number: ${{ github.event.pull_request.number }} body: | - ⚠️ **The merge is blocked.** + ⚠️ **This Pull Request is not ready to be merged.** Remove the label '${{ inputs.label }}' to proceed. diff --git a/README.md b/README.md index 096a6e81..ec2cea1b 100644 --- a/README.md +++ b/README.md @@ -245,12 +245,12 @@ on: jobs: block: - uses: Staffbase/gha-workflows/.github/workflows/template_merge_block.yml@v2.0.0 + uses: Staffbase/gha-workflows/.github/workflows/template_merge_block.yml@v5.2.0 with: # optional: name of the label if the PR should not be merged, default: do not merge label: merge block # optional: comment when the PR is blocked, default: true - comment: true + comment: false ```