Skip to content

[CI] Install torchcodec from source #785

[CI] Install torchcodec from source

[CI] Install torchcodec from source #785

Workflow file for this run

# 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 "BugFix" label
# - Fails if no valid prefix is found
# - Labels are ONLY ADDED, never removed (preserves manual labels)
#
# Supported prefixes (supports common variations):
# - [BugFix], [Bugfix] → BugFix
# - [Feature], [Features] → Feature
# - [Doc], [Docs], [Documentation] → Documentation
# - [Refactor], [Refactoring] → Refactoring
# - [CI] → CI
# - [Test], [Tests] → Tests
# - [Environment], [Environments] → Environments
# - [Data] → Data
# - [Performance], [Perf] → Performance
# - [BC-Breaking], [BCBreaking] → bc breaking
# - [Deprecation], [Deprecated] → Deprecation
# - [Quality] → Quality
#------------------------------------------------------------
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 (case-sensitive)
Your PR title must start with **exactly** one of these prefixes:
| Prefix | Label Applied | Example |
|--------|---------------|---------|
| `[BugFix]` | BugFix | `[BugFix] Fix memory leak in collector` |
| `[Feature]` | Feature | `[Feature] Add new optimizer` |
| `[Doc]` or `[Docs]` | Documentation | `[Doc] Update installation guide` |
| `[Refactor]` | Refactoring | `[Refactor] Clean up module imports` |
| `[CI]` | CI | `[CI] Fix workflow permissions` |
| `[Test]` or `[Tests]` | Tests | `[Tests] Add unit tests for buffer` |
| `[Environment]` or `[Environments]` | Environments | `[Environments] Add Gymnasium support` |
| `[Data]` | Data | `[Data] Fix replay buffer sampling` |
| `[Performance]` or `[Perf]` | Performance | `[Performance] Optimize tensor ops` |
| `[BC-Breaking]` | bc breaking | `[BC-Breaking] Remove deprecated API` |
| `[Deprecation]` | Deprecation | `[Deprecation] Mark old function` |
| `[Quality]` | Quality | `[Quality] Fix typos and add codespell` |
**Note:** Common variations like singular/plural are supported (e.g., `[Doc]` or `[Docs]`).
COMMENT_EOF
# Strip leading spaces from heredoc (YAML indentation artifact)
sed -i 's/^ //' /tmp/pr_comment.md
sed -i "s/REASON_PLACEHOLDER/$reason/" /tmp/pr_comment.md
sed -i "s|TITLE_PLACEHOLDER|$current_title|" /tmp/pr_comment.md
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 (case-sensitive, no normalization)
PREFIX="${BASH_REMATCH[1]}"
echo "Extracted prefix: $PREFIX"
# Map prefixes to GitHub label names (supports common variations)
case "$PREFIX" in
BugFix|Bugfix|bugfix)
LABEL="BugFix"
;;
Feature|Features|feature|features)
LABEL="Feature"
;;
Doc|Docs|Documentation|doc|docs)
LABEL="Documentation"
;;
Refactor|Refactoring|refactor|refactoring)
LABEL="Refactoring"
;;
CI|ci)
LABEL="CI"
;;
Test|Tests|test|tests)
LABEL="Tests"
;;
Environment|Environments|environment|environments)
LABEL="Environments"
;;
Data|data)
LABEL="Data"
;;
Performance|Perf|performance|perf)
LABEL="Performance"
;;
BC-Breaking|BCBreaking|bc-breaking)
LABEL="bc breaking"
;;
Deprecation|Deprecated|deprecation|deprecated)
LABEL="Deprecation"
;;
Quality|quality)
LABEL="Quality"
;;
*)
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"