|
| 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 | + name: Fail CI if sl-require-admin-action label is present |
| 21 | + runs-on: ubuntu-latest |
| 22 | + if: |
| 23 | + ${{ contains(github.event.pull_request.labels.*.name, |
| 24 | + 'sl-require-admin-action') }} |
| 25 | + steps: |
| 26 | + - name: Add comment to PR |
| 27 | + uses: actions/github-script@v7 |
| 28 | + with: |
| 29 | + script: | |
| 30 | + const prNumber = context.payload.pull_request.number; |
| 31 | + const comment = "The check for `sl-require-admin-action` label CI failure for this job is normal. An admin must do the merge."; |
| 32 | + const { data: comments } = await github.rest.issues.listComments({ |
| 33 | + owner: context.repo.owner, |
| 34 | + repo: context.repo.repo, |
| 35 | + issue_number: prNumber, |
| 36 | + }); |
| 37 | + const existingComment = comments.find(c => c.body.includes(comment)); |
| 38 | + if (!existingComment) { |
| 39 | + await github.rest.issues.createComment({ |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + issue_number: prNumber, |
| 43 | + body: comment, |
| 44 | + }); |
| 45 | + } |
| 46 | +
|
| 47 | + - name: Trigger CI failure |
| 48 | + run: | |
| 49 | + echo "The sl-require-admin-action label is present. Failing the job." |
| 50 | + process.exit(1); |
| 51 | + env: |
| 52 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 53 | + |
| 54 | + prevent-label-removal: |
| 55 | + name: Prevent sl-require-admin-action label from being removed |
| 56 | + runs-on: ubuntu-latest |
| 57 | + if: |
| 58 | + github.event.action == 'unlabeled' && github.event.label.name == |
| 59 | + 'sl-require-admin-action' |
| 60 | + steps: |
| 61 | + - name: Add comment to PR |
| 62 | + uses: actions/github-script@v7 |
| 63 | + with: |
| 64 | + script: | |
| 65 | + const prNumber = context.payload.pull_request.number; |
| 66 | + const comment = "The `sl-require-admin-action` label cannot be removed once it has been added."; |
| 67 | + const { data: comments } = await github.rest.issues.listComments({ |
| 68 | + owner: context.repo.owner, |
| 69 | + repo: context.repo.repo, |
| 70 | + issue_number: prNumber, |
| 71 | + }); |
| 72 | + const existingComment = comments.find(c => c.body.includes(comment)); |
| 73 | + if (!existingComment) { |
| 74 | + await github.rest.issues.createComment({ |
| 75 | + owner: context.repo.owner, |
| 76 | + repo: context.repo.repo, |
| 77 | + issue_number: prNumber, |
| 78 | + body: comment, |
| 79 | + }); |
| 80 | + } |
| 81 | +
|
| 82 | + - name: Re-add sl-require-admin-action label |
| 83 | + uses: actions/github-script@v7 |
| 84 | + with: |
| 85 | + script: | |
| 86 | + const prNumber = context.payload.pull_request.number; |
| 87 | + await github.rest.issues.addLabels({ |
| 88 | + owner: context.repo.owner, |
| 89 | + repo: context.repo.repo, |
| 90 | + issue_number: prNumber, |
| 91 | + labels: ['sl-require-admin-action'], |
| 92 | + }); |
| 93 | +
|
| 94 | + - name: Trigger CI failure |
| 95 | + run: | |
| 96 | + echo "The sl-require-admin-action label cannot be removed. Failing the job." |
| 97 | + process.exit(1); |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
0 commit comments