name: Format

on:
  merge_group:
  pull_request:
  push:
    branches:
      - main

env:
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

jobs:
  fmt:
    name: Runs "cargo fmt"
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
          components: rustfmt

      - name: Cache .cargo
        uses: actions/cache@v5
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: cargo-fmt-${{ hashFiles('**/Cargo.toml') }}

      - name: Run fmt
        run: cargo fmt --all -- --check