Skip to content
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

✨ Add "Do not Merge" Workflow #111

Merged
merged 12 commits into from
Apr 25, 2024
55 changes: 55 additions & 0 deletions .github/workflows/template_merge_block.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Do Not Merge

on:
workflow_call:
inputs:
label:
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

steps:
- 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: ⚠️ **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 == ''
uses: peter-evans/create-or-update-comment@v4.0.0
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
⚠️ **This Pull Request is not ready to be merged.**

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 }}'."
exit 1
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,30 @@ jobs:

</details>

### Merge Block

<details>
<summary>The action can be used to block the merge if a do not merge label is set.</summary>

```yml
name: Merge Block

on:
pull_request:
types: [opened, labeled, unlabeled]

jobs:
block:
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: false
```

</details>

### Release Drafter

<details>
Expand Down