[CI] adapt .github/workflows/*.yml for MetaxGPU new #11
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
| name: auto-label | |
| permissions: | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| on: | |
| issues: | |
| types: [opened, edited] | |
| pull_request_target: | |
| types: [opened, edited] | |
| jobs: | |
| apply-label: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Skip non-title edits | |
| id: guard | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| EVENT_ACTION: ${{ github.event.action }} | |
| EVENT_PATH: ${{ github.event_path }} | |
| run: | | |
| set -euo pipefail | |
| if [[ "$EVENT_ACTION" != "edited" ]]; then | |
| echo "should_run=true" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| if ! jq -e '.changes | has("title")' "$EVENT_PATH" >/dev/null; then | |
| echo "Body-only edit detected; skipping label sync." | |
| echo "should_run=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| echo "should_run=true" >> "$GITHUB_OUTPUT" | |
| - uses: actions/checkout@v4 | |
| if: ${{ steps.guard.outputs.should_run == 'true' }} | |
| with: | |
| ref: ${{ github.event.pull_request.base.sha || github.sha }} | |
| sparse-checkout: .claude/conventions | |
| sparse-checkout-cone-mode: false | |
| - name: Extract type from title and apply label | |
| if: ${{ steps.guard.outputs.should_run == 'true' }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| EVENT_NAME: ${{ github.event_name }} | |
| ISSUE_TITLE: ${{ github.event.issue.title }} | |
| ISSUE_NUMBER: ${{ github.event.issue.number }} | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| run: | | |
| source .claude/conventions/types.sh | |
| LABEL="" | |
| if [ "$EVENT_NAME" = "issues" ]; then | |
| TITLE="$ISSUE_TITLE" | |
| NUMBER="$ISSUE_NUMBER" | |
| GH_CMD="issue" | |
| else | |
| TITLE="$PR_TITLE" | |
| NUMBER="$PR_NUMBER" | |
| GH_CMD="pr" | |
| fi | |
| # Try commit/PR-style types first (e.g. [BugFix]) | |
| TYPE=$(echo "$TITLE" | grep -oP "^\[\K(${COMMIT_PR_TYPES})(?=\])" || true) | |
| if [ -n "$TYPE" ]; then | |
| LABEL="${TYPE_TO_LABEL[$TYPE]:-}" | |
| elif [ "$EVENT_NAME" = "issues" ]; then | |
| # Fall back to ALL-CAPS issue types (e.g. [BUG]) | |
| TYPE=$(echo "$TITLE" | grep -oP "^\[\K(${ISSUE_TYPES})(?=\])" || true) | |
| if [ -n "$TYPE" ]; then | |
| LABEL="${ISSUE_TYPE_TO_LABEL[$TYPE]:-}" | |
| fi | |
| fi | |
| if [ -z "$TYPE" ] || [ -z "$LABEL" ]; then | |
| echo "No recognized type tag in title, skipping label" | |
| exit 0 | |
| fi | |
| echo "Detected type: $TYPE -> label: $LABEL" | |
| # Check if correct label already applied | |
| CURRENT_LABELS=$(gh "$GH_CMD" view "$NUMBER" --repo "$GITHUB_REPOSITORY" --json labels --jq '.labels[].name') | |
| if echo "$CURRENT_LABELS" | grep -qx "$LABEL"; then | |
| echo "Label '$LABEL' already applied, skipping" | |
| exit 0 | |
| fi | |
| # Remove any stale type labels | |
| for l in $ALL_TYPE_LABELS; do | |
| if echo "$CURRENT_LABELS" | grep -qx "$l"; then | |
| gh "$GH_CMD" edit "$NUMBER" --repo "$GITHUB_REPOSITORY" --remove-label "$l" | |
| fi | |
| done | |
| # Ensure label exists (create if missing) | |
| if ! gh label list --repo "$GITHUB_REPOSITORY" --search "$LABEL" --json name --jq '.[].name' | grep -qx "$LABEL"; then | |
| gh label create "$LABEL" --repo "$GITHUB_REPOSITORY" --description "Auto-created by labeler" --force | |
| echo "Created label: $LABEL" | |
| fi | |
| # Apply the matching label | |
| gh "$GH_CMD" edit "$NUMBER" --repo "$GITHUB_REPOSITORY" --add-label "$LABEL" | |
| echo "Applied label: $LABEL" |