Update .github/workflows/pr-metadata-check.yml #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| name: "CI: Enforce label/milestone on PRs" | ||
| on: | ||
| pull_request_target: | ||
| types: | ||
| - opened | ||
| - edited | ||
| - synchronize | ||
| - labeled | ||
| - unlabeled | ||
| jobs: | ||
| check-metadata: | ||
| name: PR has labels and milestone | ||
| if: github.repository_owner == 'nvidia' | ||
| if: github.repository_owner == 'NVIDIA' | ||
| steps: | ||
| - name: Check for labels and milestone | ||
| env: | ||
| LABELS: ${{ toJson(github.event.pull_request.labels) }} | ||
| MILESTONE: ${{ github.event.pull_request.milestone && github.event.pull_request.milestone.title || '' }} | ||
| PR_URL: ${{ github.event.pull_request.html_url }} | ||
| IS_BOT: ${{ github.actor == 'dependabot[bot]' || github.actor == 'pre-commit-ci[bot]' || github.actor == 'copy-pr-bot[bot]' }} | ||
| IS_DRAFT: ${{ github.event.pull_request.draft }} | ||
| run: | | ||
| if [ "$IS_BOT" = "true" ] || [ "$IS_DRAFT" = "true" ]; then | ||
| echo "Skipping check for bot or draft PR." | ||
| exit 0 | ||
| fi | ||
| LABEL_COUNT=$(echo "$LABELS" | jq 'length') | ||
| ERRORS="" | ||
| if [ "$LABEL_COUNT" -eq 0 ]; then | ||
| ERRORS="${ERRORS} - Missing labels: add at least one label to categorize this PR.\n" | ||
| fi | ||
| if [ -z "$MILESTONE" ]; then | ||
| ERRORS="${ERRORS} - Missing milestone: assign a milestone to this PR.\n" | ||
| fi | ||
| if [ -n "$ERRORS" ]; then | ||
| echo "::error::This PR is missing required metadata:" | ||
| printf "$ERRORS" | ||
| echo "" | ||
| echo "Please update the PR at: $PR_URL" | ||
| exit 1 | ||
| fi | ||
| echo "PR has $LABEL_COUNT label(s) and milestone '$MILESTONE'." | ||