|
| 1 | +# This workflow checks that the appropriate ATS labels are applied to a pull request: |
| 2 | +# - "ATS Approval Not Needed": pass |
| 3 | +# - "ATS Approved": pass |
| 4 | +# - "ATS Approval Needed": fail |
| 5 | +# - Missing ATS label: fail |
| 6 | + |
| 7 | +name: "[PR] ATS labels" |
| 8 | + |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + types: |
| 12 | + - opened |
| 13 | + - edited |
| 14 | + - reopened |
| 15 | + - labeled |
| 16 | + - unlabeled |
| 17 | + - synchronize |
| 18 | + |
| 19 | +permissions: |
| 20 | + pull-requests: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + check: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Get PR details |
| 27 | + uses: actions/github-script@v7 |
| 28 | + id: check-pr |
| 29 | + with: |
| 30 | + script: | |
| 31 | + const pr = await github.rest.pulls.get({ |
| 32 | + owner: context.repo.owner, |
| 33 | + repo: context.repo.repo, |
| 34 | + pull_number: context.payload.pull_request.number, |
| 35 | + }); |
| 36 | + const labels = pr.data.labels.map(label => label.name); |
| 37 | + core.setOutput('labels', JSON.stringify(labels)); |
| 38 | + core.setOutput('author', context.payload.pull_request.user.login); |
| 39 | +
|
| 40 | + - name: Evaluate ATS labels |
| 41 | + run: | |
| 42 | + AUTHOR='${{ steps.check-pr.outputs.author }}' |
| 43 | + if [ "$AUTHOR" == "DeployDuck" ] || [ "$AUTHOR" == "pre-commit-ci[bot]" ]; then |
| 44 | + echo "Bot PR, skipping." |
| 45 | + exit 0 |
| 46 | + fi |
| 47 | + LABELS=$(echo '${{ steps.check-pr.outputs.labels }}' | jq -r '.[]') |
| 48 | + echo "Labels found:" |
| 49 | + echo -e "$LABELS\n" |
| 50 | + echo "Result:" |
| 51 | + if echo "$LABELS" | grep -qi "ATS approval not needed"; then |
| 52 | + echo "ATS approval not needed. Passing." |
| 53 | + EXIT_CODE=0 |
| 54 | + elif echo "$LABELS" | grep -qi "ATS approved"; then |
| 55 | + echo "ATS Approved. Passing." |
| 56 | + EXIT_CODE=0 |
| 57 | + elif echo "$LABELS" | grep -qi "ATS approval needed"; then |
| 58 | + echo "ATS Approval Needed. Failing." |
| 59 | + EXIT_CODE=1 |
| 60 | + else |
| 61 | + echo "No ATS approval labels found. Please assign the appropriate ATS label. Failing." |
| 62 | + EXIT_CODE=1 |
| 63 | + fi |
| 64 | + echo -e "\nFor more information on ATS labels, see:" |
| 65 | + echo "https://anemoi.readthedocs.io/en/latest/contributing/guidelines.html#labelling-guidelines" |
| 66 | + exit $EXIT_CODE |
0 commit comments