|
| 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 label/milestone on PRs" |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request_target: |
| 9 | + types: |
| 10 | + - opened |
| 11 | + - edited |
| 12 | + - synchronize |
| 13 | + - labeled |
| 14 | + - unlabeled |
| 15 | + - reopened |
| 16 | + - ready_for_review |
| 17 | + |
| 18 | +jobs: |
| 19 | + check-metadata: |
| 20 | + name: PR has labels and milestone |
| 21 | + if: github.repository_owner == 'NVIDIA' |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Check for labels and milestone |
| 25 | + env: |
| 26 | + LABELS: ${{ toJson(github.event.pull_request.labels) }} |
| 27 | + MILESTONE: ${{ github.event.pull_request.milestone && github.event.pull_request.milestone.title || '' }} |
| 28 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 29 | + IS_BOT: ${{ github.actor == 'dependabot[bot]' || github.actor == 'pre-commit-ci[bot]' || github.actor == 'copy-pr-bot[bot]' }} |
| 30 | + IS_DRAFT: ${{ github.event.pull_request.draft }} |
| 31 | + run: | |
| 32 | + if [ "$IS_BOT" = "true" ] || [ "$IS_DRAFT" = "true" ]; then |
| 33 | + echo "Skipping check for bot or draft PR." |
| 34 | + exit 0 |
| 35 | + fi |
| 36 | +
|
| 37 | + LABEL_NAMES=$(echo "$LABELS" | jq -r '.[].name') |
| 38 | + ERRORS="" |
| 39 | +
|
| 40 | + # Module labels identify which package the PR touches. |
| 41 | + # Cross-cutting labels exempt PRs from needing a module label. |
| 42 | + MODULE_LABELS="cuda.bindings cuda.core cuda.pathfinder" |
| 43 | + MODULE_EXEMPT_LABELS="CI/CD" |
| 44 | + HAS_MODULE=false |
| 45 | + for label in $LABEL_NAMES; do |
| 46 | + for mod in $MODULE_LABELS $MODULE_EXEMPT_LABELS; do |
| 47 | + if [ "$label" = "$mod" ]; then |
| 48 | + HAS_MODULE=true |
| 49 | + break 2 |
| 50 | + fi |
| 51 | + done |
| 52 | + done |
| 53 | +
|
| 54 | + if [ "$HAS_MODULE" = "false" ]; then |
| 55 | + 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" |
| 56 | + fi |
| 57 | +
|
| 58 | + # Type labels categorize the kind of change. |
| 59 | + TYPE_LABELS="bug enhancement feature documentation test example CI/CD packaging dependencies performance experiment RFC support P0 P1 P2" |
| 60 | + HAS_TYPE=false |
| 61 | + for label in $LABEL_NAMES; do |
| 62 | + for typ in $TYPE_LABELS; do |
| 63 | + if [ "$label" = "$typ" ]; then |
| 64 | + HAS_TYPE=true |
| 65 | + break 2 |
| 66 | + fi |
| 67 | + done |
| 68 | + done |
| 69 | +
|
| 70 | + if [ "$HAS_TYPE" = "false" ]; then |
| 71 | + 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" |
| 72 | + fi |
| 73 | +
|
| 74 | + if [ -z "$MILESTONE" ]; then |
| 75 | + ERRORS="${ERRORS}- **Missing milestone**: assign a milestone to this PR.\n" |
| 76 | + fi |
| 77 | +
|
| 78 | + # Block PRs with labels that indicate they are not ready to merge. |
| 79 | + BLOCKED_PATTERNS="blocked DO NOT MERGE do not merge" |
| 80 | + for label in $LABEL_NAMES; do |
| 81 | + for pattern in $BLOCKED_PATTERNS; do |
| 82 | + if echo "$label" | grep -qi "$pattern"; then |
| 83 | + ERRORS="${ERRORS}- **Blocked label detected**: label \`$label\` prevents merging. Remove it when the PR is ready.\n" |
| 84 | + break |
| 85 | + fi |
| 86 | + done |
| 87 | + done |
| 88 | +
|
| 89 | + if [ -n "$ERRORS" ]; then |
| 90 | + echo "::error::This PR is missing required metadata. See the job summary for details." |
| 91 | + { |
| 92 | + echo "## PR Metadata Check Failed" |
| 93 | + echo "" |
| 94 | + printf '%b' "$ERRORS" |
| 95 | + echo "" |
| 96 | + echo "Please update the PR at: $PR_URL" |
| 97 | + } >> "$GITHUB_STEP_SUMMARY" |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | +
|
| 101 | + LABEL_LIST=$(echo "$LABEL_NAMES" | paste -sd ', ' -) |
| 102 | + { |
| 103 | + echo "## PR Metadata Check Passed" |
| 104 | + echo "" |
| 105 | + echo "- **Labels**: $LABEL_LIST" |
| 106 | + echo "- **Milestone**: $MILESTONE" |
| 107 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments