|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +name: Maintainer Approval |
| 5 | + |
| 6 | +on: |
| 7 | + merge_group: |
| 8 | + types: [checks_requested] |
| 9 | + pull_request_review: |
| 10 | + types: [submitted, dismissed] |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + pull-requests: read |
| 15 | + |
| 16 | +concurrency: |
| 17 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + maintainer-approval: |
| 22 | + # This name is the required status check context. Changing it silently |
| 23 | + # breaks the ruleset entry that gates merges on this job. |
| 24 | + name: OpenShell / Maintainer Approval |
| 25 | + if: github.repository_owner == 'NVIDIA' |
| 26 | + runs-on: ubuntu-latest |
| 27 | + timeout-minutes: 5 |
| 28 | + steps: |
| 29 | + # Check out the default branch, never the pull request head. Both the |
| 30 | + # maintainer list and the decision helper must come from main: reading |
| 31 | + # either from the pull request ref would let a contributor add themselves |
| 32 | + # to the list, or rewrite the decision logic, and self-approve. |
| 33 | + - name: Check out the maintainer list and helper |
| 34 | + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 35 | + with: |
| 36 | + ref: main |
| 37 | + sparse-checkout: | |
| 38 | + MAINTAINERS.md |
| 39 | + tasks/scripts/check_maintainer_approval.py |
| 40 | + sparse-checkout-cone-mode: false |
| 41 | + persist-credentials: false |
| 42 | + |
| 43 | + - name: Require an approving review from a maintainer |
| 44 | + env: |
| 45 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + GH_REPO: ${{ github.repository }} |
| 47 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 48 | + # merge_group carries no pull request in its payload, but the queue |
| 49 | + # branch names the entry: gh-readonly-queue/main/pr-3027-<base sha>. |
| 50 | + MERGE_GROUP_REF: ${{ github.ref_name }} |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + set -euo pipefail |
| 54 | +
|
| 55 | + if [ -z "${PR_NUMBER:-}" ]; then |
| 56 | + if [[ "$MERGE_GROUP_REF" =~ /pr-([0-9]+)-[0-9a-f]+$ ]]; then |
| 57 | + PR_NUMBER="${BASH_REMATCH[1]}" |
| 58 | + else |
| 59 | + # Fail closed: an unrecognised ref must never satisfy the gate. |
| 60 | + echo "::error::No pull request resolved from '$MERGE_GROUP_REF'." |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + fi |
| 64 | +
|
| 65 | + gh api --paginate "repos/$GH_REPO/pulls/$PR_NUMBER/reviews" --jq '.[]' \ |
| 66 | + | jq -s '.' > reviews.json |
| 67 | +
|
| 68 | + # Exits non-zero when no maintainer's latest decisive review is an |
| 69 | + # approval, and when MAINTAINERS.md yields no handles. That exit code |
| 70 | + # is the check result; nothing is posted anywhere. |
| 71 | + python3 tasks/scripts/check_maintainer_approval.py \ |
| 72 | + --maintainers MAINTAINERS.md \ |
| 73 | + --reviews reviews.json |
0 commit comments