Skip to content

Commit d535811

Browse files
[SL-ONLY] Add require admin check workflow (#259)
1 parent 29ed589 commit d535811

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

.github/workflows/silabs-open-csa-pr.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ jobs:
3636
3737
**PR MUST BE MERGED WITH MERGE COMMIT - ADMIN MUST ENABLE THE OPTION**
3838
token: ${{secrets.GITHUB_TOKEN}}
39-
labels: changing-submodules-on-purpose
39+
labels:
40+
changing-submodules-on-purpose, sl-require-admin-action
4041

4142
# The next step is necessary to force the CI to be executed when a PR is opened by the github-bot.
4243
# The PR event isn't triggered when the bot opens the PR and as such doesn't trigger the workflows that use the event as their trigger.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Check for sl-require-admin-action label
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- release_*
8+
types:
9+
- opened
10+
- reopened
11+
- synchronize
12+
- labeled
13+
- unlabeled
14+
15+
permissions:
16+
pull-requests: write
17+
18+
jobs:
19+
check-label:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Check for sl-require-admin-action label
23+
run: |
24+
PR_NUMBER=${{ github.event.pull_request.number }}
25+
LABELS=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json labels --jq '.labels[].name')
26+
if echo "$LABELS" | grep -q "sl-require-admin-action"; then
27+
echo "The sl-require-admin-action label is present. Failing the job."
28+
COMMENTS=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json comments --jq '.comments[].body')
29+
if ! echo "$COMMENTS" | grep -q "The CI failure for this job is normal. An admin must do the merge."; then
30+
gh pr comment $PR_NUMBER --repo ${{ github.repository }} --body "The CI failure for this job is normal. An admin must do the merge."
31+
fi
32+
exit 1
33+
else
34+
echo "The sl-require-admin-action label is not present. Passing the job."
35+
fi
36+
env:
37+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
38+
39+
prevent-label-removal:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Prevent sl-require-admin-action label removal
43+
if: github.event.action == 'unlabeled'
44+
run: |
45+
PR_NUMBER=${{ github.event.pull_request.number }}
46+
REMOVED_LABEL=${{ github.event.label.name }}
47+
if [ "$REMOVED_LABEL" == "sl-require-admin-action" ]; then
48+
echo "The sl-require-admin-action label cannot be removed. Failing the job."
49+
COMMENTS=$(gh pr view $PR_NUMBER --repo ${{ github.repository }} --json comments --jq '.comments[].body')
50+
if ! echo "$COMMENTS" | grep -q "The sl-require-admin-action label cannot be removed once it has been added."; then
51+
gh pr comment $PR_NUMBER --repo ${{ github.repository }} --body "The sl-require-admin-action label cannot be removed once it has been added."
52+
fi
53+
exit 1
54+
else
55+
echo "A different label was removed. Passing the job."
56+
fi
57+
env:
58+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

0 commit comments

Comments
 (0)