|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +name: "CI: Restricted Paths Review Gate" |
| 5 | + |
| 6 | +on: |
| 7 | + # Keep this separate from pr-metadata-check.yml so only the |
| 8 | + # Needs-Restricted-Paths-Review policy becomes merge-blocking. |
| 9 | + pull_request_target: |
| 10 | + types: |
| 11 | + - opened |
| 12 | + - synchronize |
| 13 | + - reopened |
| 14 | + - ready_for_review |
| 15 | + - labeled |
| 16 | + - unlabeled |
| 17 | + |
| 18 | +jobs: |
| 19 | + restricted-paths-review-gate: |
| 20 | + name: Restricted paths review gate |
| 21 | + if: github.repository_owner == 'NVIDIA' |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + pull-requests: read |
| 25 | + steps: |
| 26 | + - name: Check for merge-blocking restricted-paths label |
| 27 | + env: |
| 28 | + GH_TOKEN: ${{ github.token }} |
| 29 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 30 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 31 | + REPO: ${{ github.repository }} |
| 32 | + REVIEW_LABEL: Needs-Restricted-Paths-Review |
| 33 | + run: | |
| 34 | + set -euo pipefail |
| 35 | +
|
| 36 | + if ! LIVE_LABELS=$( |
| 37 | + gh pr view "${PR_NUMBER}" --repo "${REPO}" \ |
| 38 | + --json labels \ |
| 39 | + --jq '[.labels[].name]' |
| 40 | + ); then |
| 41 | + echo "::error::Failed to inspect the current PR labels." |
| 42 | + { |
| 43 | + echo "## Restricted Paths Review Gate Failed" |
| 44 | + echo "" |
| 45 | + echo "- **Error**: Failed to inspect the current PR labels." |
| 46 | + echo "" |
| 47 | + echo "Please update the PR at: $PR_URL" |
| 48 | + } >> "$GITHUB_STEP_SUMMARY" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | +
|
| 52 | + CURRENT_LABELS=$(jq -r ' |
| 53 | + if length == 0 then |
| 54 | + "(none)" |
| 55 | + else |
| 56 | + join(", ") |
| 57 | + end |
| 58 | + ' <<<"$LIVE_LABELS") |
| 59 | +
|
| 60 | + if jq -e --arg label "$REVIEW_LABEL" '.[] == $label' <<<"$LIVE_LABELS" >/dev/null; then |
| 61 | + echo "::error::The $REVIEW_LABEL label is present. Remove it after restricted-paths review is complete." |
| 62 | + { |
| 63 | + echo "## Restricted Paths Review Gate Failed" |
| 64 | + echo "" |
| 65 | + echo "- **Blocking label**: \`$REVIEW_LABEL\`" |
| 66 | + echo "- **Current labels**: $CURRENT_LABELS" |
| 67 | + echo "- **Why this failed**: This label means the PR touched \`cuda_bindings/\` or \`cuda_python/\` without a trusted author signal." |
| 68 | + echo "- **How to unblock merge**: A maintainer must review the restricted-paths policy decision and remove \`$REVIEW_LABEL\` manually when the PR is allowed to merge." |
| 69 | + echo "" |
| 70 | + echo "Please update the PR at: $PR_URL" |
| 71 | + } >> "$GITHUB_STEP_SUMMARY" |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | +
|
| 75 | + { |
| 76 | + echo "## Restricted Paths Review Gate Passed" |
| 77 | + echo "" |
| 78 | + echo "- **Blocking label absent**: \`$REVIEW_LABEL\`" |
| 79 | + echo "- **Current labels**: $CURRENT_LABELS" |
| 80 | + echo "- **Result**: This gate does not block merging." |
| 81 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments