124 lines
4.7 KiB
YAML
124 lines
4.7 KiB
YAML
name: autofix.ci
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
on:
|
|
workflow_call:
|
|
workflow_dispatch:
|
|
pull_request:
|
|
merge_group:
|
|
env:
|
|
BUN_VERSION: "1.3.14"
|
|
LLVM_VERSION: "21.1.8"
|
|
LLVM_VERSION_MAJOR: "21"
|
|
|
|
jobs:
|
|
autofix:
|
|
name: Format
|
|
runs-on: ubuntu-latest
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
persist-credentials: false
|
|
- name: Configure Git
|
|
run: |
|
|
git config --global core.autocrlf true
|
|
git config --global core.ignorecase true
|
|
git config --global core.precomposeUnicode true
|
|
- name: Setup Bun
|
|
uses: ./.github/actions/setup-bun
|
|
with:
|
|
bun-version: ${{ env.BUN_VERSION }}
|
|
- name: Setup Dependencies
|
|
run: |
|
|
bun install
|
|
- name: Format Code
|
|
env:
|
|
# Pin the toolchain explicitly so rustup ignores rust-toolchain.toml's
|
|
# `targets` list (11 cross triples ≈ 450 MB of prebuilt std we don't
|
|
# need just to run rustfmt). Keep this in sync with `channel` there.
|
|
RUSTUP_TOOLCHAIN: nightly-2026-07-20
|
|
run: |
|
|
# Without pipefail, `cmd | sed` always reports sed's exit status, so a
|
|
# failing formatter is invisible to the `wait $PID` checks below.
|
|
set -o pipefail
|
|
|
|
# `*.generated.rs` are deterministic outputs of `*.string-map.ts`; the
|
|
# source `.ts` is the truth. Regenerating here, alongside the
|
|
# formatters, makes a stale checked-in copy one more fix for the
|
|
# autofix step below to push back to the PR (it also fails the run
|
|
# whenever it has something to push, so staleness stays a red check
|
|
# where it can't push, e.g. the merge queue). Runs before the
|
|
# formatters start so prettier isn't rewriting a `.string-map.ts`
|
|
# while the generator imports it.
|
|
echo "::group::String maps"
|
|
bun run codegen:string-maps 2>&1 | sed 's/^/[string-maps] /'
|
|
echo "::endgroup::"
|
|
|
|
# Start prettier in background with prefixed output
|
|
echo "::group::Prettier"
|
|
(bun run prettier 2>&1 | sed 's/^/[prettier] /') &
|
|
PRETTIER_PID=$!
|
|
|
|
# Start clang-format installation and formatting in background with prefixed output
|
|
echo "::group::Clang-format"
|
|
(
|
|
echo "[clang-format] Installing clang-format-${LLVM_VERSION_MAJOR}..."
|
|
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc > /dev/null
|
|
echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-${LLVM_VERSION_MAJOR} main" | sudo tee /etc/apt/sources.list.d/llvm.list > /dev/null
|
|
sudo apt-get update -qq
|
|
sudo apt-get install -y -qq --no-install-recommends --no-install-suggests -o=Dpkg::Use-Pty=0 clang-format-${LLVM_VERSION_MAJOR}
|
|
echo "[clang-format] Running clang-format..."
|
|
./scripts/run-clang-format.sh format 2>&1 | sed 's/^/[clang-format] /'
|
|
) &
|
|
CLANG_PID=$!
|
|
|
|
# Run cargo fmt in background with prefixed output. RUSTUP_TOOLCHAIN
|
|
# (step env) overrides rust-toolchain.toml, so install only the host
|
|
# toolchain + rustfmt instead of the file's 11 cross-target std libs.
|
|
echo "::group::Cargo fmt"
|
|
(
|
|
echo "[rustfmt] Installing toolchain $RUSTUP_TOOLCHAIN..."
|
|
rustup toolchain install "$RUSTUP_TOOLCHAIN" --profile minimal --component rustfmt --no-self-update 2>&1 | sed 's/^/[rustfmt] /'
|
|
echo "[rustfmt] Running cargo fmt --all..."
|
|
cargo fmt --all 2>&1 | sed 's/^/[rustfmt] /'
|
|
) &
|
|
RUST_PID=$!
|
|
|
|
# Wait for all formatting tasks to complete
|
|
echo ""
|
|
echo "Running formatters in parallel..."
|
|
FAILED=0
|
|
|
|
if ! wait $PRETTIER_PID; then
|
|
echo "::error::Prettier failed"
|
|
FAILED=1
|
|
fi
|
|
echo "::endgroup::"
|
|
|
|
if ! wait $CLANG_PID; then
|
|
echo "::error::Clang-format failed"
|
|
FAILED=1
|
|
fi
|
|
echo "::endgroup::"
|
|
|
|
if ! wait $RUST_PID; then
|
|
echo "::error::cargo fmt failed"
|
|
FAILED=1
|
|
fi
|
|
echo "::endgroup::"
|
|
|
|
# Exit with error if any formatter failed
|
|
if [ $FAILED -eq 1 ]; then
|
|
echo "::error::One or more formatters failed"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ All formatters completed successfully"
|
|
- uses: autofix-ci/action@c5b2d67aa2274e7b5a18224e8171550871fc7e4a # v1.3.4
|