[Feature] add key-level skip_existing #699
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
| # Automatically add a label to PRs based on the [Label] prefix in the title | |
| # | |
| # Usage: | |
| # - PR title must start with a [Label] prefix in brackets | |
| # - Example: "[BugFix] Fix memory leak" will add the "bug" label | |
| # - Fails if no valid prefix is found | |
| # - Labels are ONLY ADDED, never removed (preserves manual labels) | |
| # - Matching is case-insensitive | |
| # | |
| # Supported prefixes -> label: | |
| # [BE] -> BE | |
| # [BugFix], [Fix] -> bug | |
| # [Feature] -> Feature | |
| # [Doc], [Docs], [Documentation] -> documentation | |
| # [Refactor], [Refactoring] -> Refactor | |
| # [CI] -> CI | |
| # [Test], [Tests] -> Test | |
| # [Compile] -> Compile | |
| # [Performance], [Perf] -> Performance | |
| # [Deprecation], [Deprecated] -> Deprecation | |
| # [Setup] -> setup | |
| # [Distributed], [Dist], [DTensor] -> Distributed | |
| # [Benchmark], [Benchmarks], [Bench] -> Benchmarks | |
| # [Typing], [Type] -> Typing | |
| # [BC-breaking], [BC] -> BC-breaking | |
| # [Formatting], [Format] -> Formatting | |
| # [Quality] -> Quality | |
| # [Release] -> release | |
| # [Versioning] -> versioning | |
| #------------------------------------------------------------ | |
| name: PR Label | |
| on: | |
| # Using pull_request_target to have write access for PRs from forks | |
| # This is safe because we only read PR metadata (title), not code from the fork | |
| pull_request_target: | |
| types: [opened, edited, synchronize, reopened] | |
| jobs: | |
| add-label: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - name: Parse and apply label from PR title | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| REPO: ${{ github.repository }} | |
| run: | | |
| set -euo pipefail | |
| post_help_comment() { | |
| local reason="$1" | |
| local current_title="$2" | |
| cat > /tmp/pr_comment.md << 'COMMENT_EOF' | |
| ## PR Title Label Error | |
| REASON_PLACEHOLDER | |
| **Current title:** `TITLE_PLACEHOLDER` | |
| ### Supported Prefixes | |
| Your PR title must start with **exactly** one of these prefixes (case-insensitive): | |
| | Prefix | Label Applied | Example | | |
| |--------|---------------|---------| | |
| | `[BE]` | BE | `[BE] Improve internal plumbing` | | |
| | `[BugFix]` or `[Fix]` | bug | `[BugFix] Fix memory leak in TensorDict` | | |
| | `[Feature]` | Feature | `[Feature] Add new storage backend` | | |
| | `[Doc]` or `[Docs]` | documentation | `[Doc] Update installation guide` | | |
| | `[Refactor]` | Refactor | `[Refactor] Clean up module imports` | | |
| | `[CI]` | CI | `[CI] Fix workflow permissions` | | |
| | `[Test]` or `[Tests]` | Test | `[Test] Add unit tests for nn module` | | |
| | `[Compile]` | Compile | `[Compile] Fix torch.compile issue` | | |
| | `[Performance]` or `[Perf]` | Performance | `[Perf] Optimize tensor operations` | | |
| | `[Deprecation]` | Deprecation | `[Deprecation] Mark old function` | | |
| | `[Setup]` | setup | `[Setup] Update build configuration` | | |
| | `[Distributed]`, `[Dist]`, or `[DTensor]` | Distributed | `[DTensor] Add cross-mesh transfer` | | |
| | `[Benchmark]` or `[Bench]` | Benchmarks | `[Benchmark] Add compile benchmark` | | |
| | `[Typing]` or `[Type]` | Typing | `[Typing] Add type stubs` | | |
| | `[BC-breaking]` or `[BC]` | BC-breaking | `[BC-breaking] Remove deprecated API` | | |
| | `[Formatting]` or `[Format]` | Formatting | `[Format] Fix code style` | | |
| | `[Quality]` | Quality | `[Quality] Improve error messages` | | |
| | `[Release]` | release | `[Release] Publish release artifacts` | | |
| | `[Versioning]` | versioning | `[Versioning] Bump release version` | | |
| **Note:** Matching is case-insensitive. Common variations (singular/plural) are supported. | |
| COMMENT_EOF | |
| sed -i 's/^ *//' /tmp/pr_comment.md | |
| COMMENT_REASON="$reason" COMMENT_TITLE="$current_title" python3 - <<'PY' | |
| import os | |
| from pathlib import Path | |
| path = Path("/tmp/pr_comment.md") | |
| comment = path.read_text() | |
| comment = comment.replace("REASON_PLACEHOLDER", os.environ["COMMENT_REASON"]) | |
| comment = comment.replace("TITLE_PLACEHOLDER", os.environ["COMMENT_TITLE"]) | |
| path.write_text(comment) | |
| PY | |
| gh pr comment "$PR_NUMBER" --repo "$REPO" --body-file /tmp/pr_comment.md | |
| } | |
| echo "PR Title: $PR_TITLE" | |
| # Check if title starts with [...] | |
| if [[ ! "$PR_TITLE" =~ ^\[([^\]]+)\] ]]; then | |
| echo "::error::PR title must start with [Label]. Got: '$PR_TITLE'" | |
| post_help_comment "PR title must start with a label prefix in brackets (e.g., \`[BugFix]\`)." "$PR_TITLE" | |
| exit 1 | |
| fi | |
| # Extract the prefix | |
| PREFIX="${BASH_REMATCH[1]}" | |
| echo "Extracted prefix: $PREFIX" | |
| # Case-insensitive matching: lowercase the prefix once | |
| PREFIX_LOWER="${PREFIX,,}" | |
| # Map prefixes to GitHub label names | |
| case "$PREFIX_LOWER" in | |
| be) LABEL="BE" ;; | |
| bugfix|fix|bug) LABEL="bug" ;; | |
| feature|features) LABEL="Feature" ;; | |
| doc|docs|documentation) LABEL="documentation" ;; | |
| refactor|refactoring) LABEL="Refactor" ;; | |
| ci) LABEL="CI" ;; | |
| test|tests) LABEL="Test" ;; | |
| compile) LABEL="Compile" ;; | |
| performance|perf) LABEL="Performance" ;; | |
| deprecation|deprecated) LABEL="Deprecation" ;; | |
| setup) LABEL="setup" ;; | |
| distributed|dist|dtensor) LABEL="Distributed" ;; | |
| benchmark|benchmarks|bench) LABEL="Benchmarks" ;; | |
| typing|type) LABEL="Typing" ;; | |
| bc-breaking|bc) LABEL="BC-breaking" ;; | |
| formatting|format) LABEL="Formatting" ;; | |
| quality) LABEL="Quality" ;; | |
| release) LABEL="release" ;; | |
| versioning) LABEL="versioning" ;; | |
| *) | |
| echo "::error::Unknown or invalid prefix '[$PREFIX]'." | |
| post_help_comment "Unknown or invalid prefix \`[$PREFIX]\`." "$PR_TITLE" | |
| exit 1 | |
| ;; | |
| esac | |
| echo "Mapped to label: $LABEL" | |
| # Add the label to the PR (never remove existing labels) | |
| gh pr edit "$PR_NUMBER" --repo "$REPO" --add-label "$LABEL" | |
| echo "Successfully added label '$LABEL' to PR #$PR_NUMBER" |