Skip to content

[SL-ONLY] Simplify require admin workflow #8

[SL-ONLY] Simplify require admin workflow

[SL-ONLY] Simplify require admin workflow #8

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: |
if contains(github.event.pull_request.labels.*.name, 'sl-require-admin-action'); then
echo "The sl-require-admin-action label is present. Failing the job."
if ! contains(github.event.pull_request.comments.*.body, 'The CI failure for this job is normal. An admin must do the merge.'); then
echo "The CI failure for this job is normal. An admin must do the merge." | gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }}
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: |
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."
if ! contains(github.event.pull_request.comments.*.body, 'The sl-require-admin-action label cannot be removed once it has been added.'); then
echo "The sl-require-admin-action label cannot be removed once it has been added." | gh pr comment ${{ github.event.pull_request.number }} --repo ${{ github.repository }}
fi
exit 1
else
echo "A different label was removed. Passing the job."
fi
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}