|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +name: "CI: Enforce assignee/label/milestone on PRs" |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request_target: |
| 9 | + types: |
| 10 | + - opened |
| 11 | + - edited |
| 12 | + - synchronize |
| 13 | + - assigned |
| 14 | + - unassigned |
| 15 | + - labeled |
| 16 | + - unlabeled |
| 17 | + - reopened |
| 18 | + - ready_for_review |
| 19 | + |
| 20 | +jobs: |
| 21 | + check-metadata: |
| 22 | + name: PR has assignee, labels, and milestone |
| 23 | + if: github.repository_owner == 'NVIDIA' |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Check for assignee, labels, and milestone |
| 27 | + env: |
| 28 | + ASSIGNEES: ${{ toJson(github.event.pull_request.assignees) }} |
| 29 | + LABELS: ${{ toJson(github.event.pull_request.labels) }} |
| 30 | + MILESTONE: ${{ github.event.pull_request.milestone && github.event.pull_request.milestone.title || '' }} |
| 31 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 32 | + IS_BOT: ${{ github.actor == 'dependabot[bot]' || github.actor == 'pre-commit-ci[bot]' || github.actor == 'copy-pr-bot[bot]' }} |
| 33 | + IS_DRAFT: ${{ github.event.pull_request.draft }} |
| 34 | + run: | |
| 35 | + if [ "$IS_BOT" = "true" ] || [ "$IS_DRAFT" = "true" ]; then |
| 36 | + echo "Skipping check for bot or draft PR." |
| 37 | + exit 0 |
| 38 | + fi |
| 39 | +
|
| 40 | + ERRORS="" |
| 41 | +
|
| 42 | + ASSIGNEE_COUNT=$(echo "$ASSIGNEES" | jq 'length') |
| 43 | + if [ "$ASSIGNEE_COUNT" -eq 0 ]; then |
| 44 | + ERRORS="${ERRORS}- **Missing assignee**: assign at least one person to this PR.\n" |
| 45 | + fi |
| 46 | +
|
| 47 | + # Module labels identify which package the PR touches. |
| 48 | + # Cross-cutting labels exempt PRs from needing a module label. |
| 49 | + # Read label names line-by-line (jq outputs one per line) so |
| 50 | + # multi-word GitHub labels are not split by shell word-splitting. |
| 51 | + MODULE_LABELS="cuda.bindings cuda.core cuda.pathfinder" |
| 52 | + MODULE_EXEMPT_LABELS="CI/CD" |
| 53 | + HAS_MODULE=false |
| 54 | + while IFS= read -r label; do |
| 55 | + [ -n "$label" ] || continue |
| 56 | + for mod in $MODULE_LABELS $MODULE_EXEMPT_LABELS; do |
| 57 | + if [ "$label" = "$mod" ]; then |
| 58 | + HAS_MODULE=true |
| 59 | + break 2 |
| 60 | + fi |
| 61 | + done |
| 62 | + done < <(echo "$LABELS" | jq -r '.[].name') |
| 63 | +
|
| 64 | + if [ "$HAS_MODULE" = "false" ]; then |
| 65 | + ERRORS="${ERRORS}- **Missing module label**: add at least one of: \`cuda.bindings\`, \`cuda.core\`, \`cuda.pathfinder\` (or a cross-cutting label such as \`CI/CD\`).\n" |
| 66 | + fi |
| 67 | +
|
| 68 | + # Type labels categorize the kind of change. |
| 69 | + TYPE_LABELS="bug enhancement feature documentation test example CI/CD packaging dependencies performance experiment RFC support P0 P1 P2" |
| 70 | + HAS_TYPE=false |
| 71 | + while IFS= read -r label; do |
| 72 | + [ -n "$label" ] || continue |
| 73 | + for typ in $TYPE_LABELS; do |
| 74 | + if [ "$label" = "$typ" ]; then |
| 75 | + HAS_TYPE=true |
| 76 | + break 2 |
| 77 | + fi |
| 78 | + done |
| 79 | + done < <(echo "$LABELS" | jq -r '.[].name') |
| 80 | +
|
| 81 | + if [ "$HAS_TYPE" = "false" ]; then |
| 82 | + ERRORS="${ERRORS}- **Missing type label**: add at least one of: \`bug\`, \`enhancement\`, \`feature\`, \`documentation\`, \`test\`, \`example\`, \`CI/CD\`, \`packaging\`, \`dependencies\`, \`performance\`, \`experiment\`, \`RFC\`, \`support\`, \`P0\`, \`P1\`, \`P2\`.\n" |
| 83 | + fi |
| 84 | +
|
| 85 | + if [ -z "$MILESTONE" ]; then |
| 86 | + ERRORS="${ERRORS}- **Missing milestone**: assign a milestone to this PR.\n" |
| 87 | + fi |
| 88 | +
|
| 89 | + # Block PRs with labels that indicate they are not ready to merge. |
| 90 | + # Match blocked label names exactly (case-insensitively); emit the |
| 91 | + # original spelling from the payload so error text matches GitHub. |
| 92 | + BLOCKED_LABELS=$(jq -r ' |
| 93 | + (["blocked", "do not merge"]) as $blocking |
| 94 | + | .[] |
| 95 | + | .name as $n |
| 96 | + | if ($blocking | index($n | ascii_downcase)) != null |
| 97 | + then $n |
| 98 | + else empty |
| 99 | + end |
| 100 | + ' <<<"$LABELS") |
| 101 | + while IFS= read -r label; do |
| 102 | + [ -n "$label" ] || continue |
| 103 | + ERRORS="${ERRORS}- **Blocked label detected**: label \`$label\` prevents merging. Remove it when the PR is ready.\n" |
| 104 | + done <<<"$BLOCKED_LABELS" |
| 105 | +
|
| 106 | + if [ -n "$ERRORS" ]; then |
| 107 | + echo "::error::This PR is missing required metadata. See the job summary for details." |
| 108 | + { |
| 109 | + echo "## PR Metadata Check Failed" |
| 110 | + echo "" |
| 111 | + printf '%b' "$ERRORS" |
| 112 | + echo "" |
| 113 | + echo "Please update the PR at: $PR_URL" |
| 114 | + } >> "$GITHUB_STEP_SUMMARY" |
| 115 | + exit 1 |
| 116 | + fi |
| 117 | +
|
| 118 | + ASSIGNEE_LIST=$(echo "$ASSIGNEES" | jq -r '.[].login' | paste -sd ', ' -) |
| 119 | + LABEL_LIST=$(echo "$LABELS" | jq -r '.[].name' | paste -sd ', ' -) |
| 120 | + { |
| 121 | + echo "## PR Metadata Check Passed" |
| 122 | + echo "" |
| 123 | + echo "- **Assignees**: $ASSIGNEE_LIST" |
| 124 | + echo "- **Labels**: $LABEL_LIST" |
| 125 | + echo "- **Milestone**: $MILESTONE" |
| 126 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments