-
Notifications
You must be signed in to change notification settings - Fork 10
99 lines (92 loc) · 3.89 KB
/
silabs-require-admin-action-check.yaml
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Check for sl-require-admin-action label
on:
pull_request:
branches:
- main
- release_*
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
permissions:
pull-requests: write
jobs:
check-label:
name: Fail CI if sl-require-admin-action label is present
runs-on: ubuntu-latest
if:
${{ contains(github.event.pull_request.labels.*.name,
'sl-require-admin-action') }}
steps:
- name: Add comment to PR
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const comment = "The check for `sl-require-admin-action` label CI failure for this job is normal. An admin must do the merge.";
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existingComment = comments.find(c => c.body.includes(comment));
if (!existingComment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment,
});
}
- name: Trigger CI failure
run: |
echo "The sl-require-admin-action label is present. Failing the job."
process.exit(1);
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
prevent-label-removal:
name: Prevent sl-require-admin-action label from being removed
runs-on: ubuntu-latest
if:
github.event.action == 'unlabeled' && github.event.label.name ==
'sl-require-admin-action'
steps:
- name: Add comment to PR
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const comment = "The `sl-require-admin-action` label cannot be removed once it has been added.";
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existingComment = comments.find(c => c.body.includes(comment));
if (!existingComment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment,
});
}
- name: Re-add sl-require-admin-action label
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ['sl-require-admin-action'],
});
- name: Trigger CI failure
run: |
echo "The sl-require-admin-action label cannot be removed. Failing the job."
process.exit(1);
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}