-
Notifications
You must be signed in to change notification settings - Fork 5.9k
38 lines (33 loc) · 1.22 KB
/
do-not-merge-label-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# This GitHub Action workflow is triggered on label changes for pull requests.
# When a pull request is labeled with "DO NOT MERGE", the workflow fails, thus
# preventing the pull request from being merged. Otherwise, the workflow will
# succeed, allowing the pull request to be merged.
name: "Check labels that prevent merge"
on:
pull_request:
branches: [main]
types: [labeled, unlabeled]
permissions:
contents: read
jobs:
labels-preventing-merge-check:
runs-on: ubuntu-latest
strategy:
matrix:
label:
# Labels that prevent merging
- 'DO NOT MERGE'
steps:
- name: Harden Runner
uses: step-security/harden-runner@0d381219ddf674d61a7572ddd19d7941e271515c # v2.9.0
with:
egress-policy: audit
- name: 'Check "${{ matrix.label }}" label'
run: |
echo "::notice::Merging permission is diabled for PRs when the '${{ matrix.label }}' label is applied."
if [ "${{ contains(github.event.pull_request.labels.*.name, matrix.label) }}" = "true" ]; then
echo "::error::Pull request is labeled as '${{ matrix.label }}'. Please remove the label before merging."
exit 1
else
exit 0
fi