Files
pseudoyu afef350fe1 fix(ci): keep fixing until the auto format result passes lint
oxlint applies fixes in a single pass and reports the problems it saw
before fixing, so a fix that creates a new problem still exits 0. In
60dd77d75 the prefer-switch fix left an unbraced `else switch` with
braced cases, the bot committed it, and every later Format run failed
on code it could no longer fix in one pass.

After `npm run format`, repeat oxlint --fix and oxfmt on the changed
files until they stop changing, then lint them without --fix so the
job fails instead of committing what lint rejects. Pushes without
fixes skip the loop. Remove the step once oxlint applies fixes
recursively (oxc-project/oxc#16118).
2026-10-15 02:46:47 +08:00

50 lines
2.2 KiB
YAML

name: Format
on:
push:
branches:
- master
jobs:
format:
permissions:
contents: write # for Git to git push
name: Auto format
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: lts/*
cache: 'pnpm'
- run: pnpm i
- run: npm run format:description
- run: npm run format
# oxlint applies fixes in a single pass, so a fix can leave problems that only the next pass fixes or reports
# Repeat on the changed files until they stop changing, and fail instead of committing what lint rejects
# https://github.com/oxc-project/oxc/issues/16118
- name: Apply chained fixes
run: |
files=()
while IFS= read -r file; do files+=("$file"); done < <(git diff --name-only -- '*.js' '*.mjs' '*.ts' '*.tsx')
if [ ${#files[@]} -gt 0 ]; then
for _ in 1 2 3 4 5; do
before=$(git diff | git hash-object --stdin)
pnpm exec oxlint --type-aware --fix "${files[@]}" || true
pnpm exec oxfmt "${files[@]}"
if [ "$(git diff | git hash-object --stdin)" = "$before" ]; then
break
fi
done
pnpm exec oxlint --type-aware "${files[@]}"
fi
- name: Commit files
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git status
git diff-index --quiet HEAD || (git commit -m "style: auto format" -a --no-verify && git push "https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:master)