-
Notifications
You must be signed in to change notification settings - Fork 10
58 lines (54 loc) · 2.61 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
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:
runs-on: ubuntu-latest
steps:
- name: Check for sl-require-admin-action label
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
LABELS=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json labels --jq '.labels[].name')
if echo "$LABELS" | grep -q "sl-require-admin-action"; then
echo "The sl-require-admin-action label is present. Failing the job."
COMMENTS=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json comments --jq '.comments[].body')
if ! echo "$COMMENTS" | grep -q "The CI failure for this job is normal. An admin must do the merge."; then
gh pr comment $PR_NUMBER --repo ${{ github.repository }} --body "The CI failure for this job is normal. An admin must do the merge."
fi
exit 1
else
echo "The sl-require-admin-action label is not present. Passing the job."
fi
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
prevent-label-removal:
runs-on: ubuntu-latest
steps:
- name: Prevent sl-require-admin-action label removal
if: github.event.action == 'unlabeled'
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
REMOVED_LABEL=${{ github.event.label.name }}
if [ "$REMOVED_LABEL" == "sl-require-admin-action" ]; then
echo "The sl-require-admin-action label cannot be removed. Failing the job."
COMMENTS=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json comments --jq '.comments[].body')
if ! echo "$COMMENTS" | grep -q "The sl-require-admin-action label cannot be removed once it has been added."; then
gh pr comment $PR_NUMBER --repo ${{ github.repository }} --body "The sl-require-admin-action label cannot be removed once it has been added."
fi
exit 1
else
echo "A different label was removed. Passing the job."
fi
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}