name: CI

on:
  push:
    branches:
      - main
      - master
  pull_request:

jobs:
  build-and-test:
    name: Build and test (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest

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

      - name: Set up Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Install Rust components
        run: rustup component add rustfmt clippy

      - name: Cache cargo registry and build
        uses: Swatinem/rust-cache@v2

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

      - name: Lint
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: Install cargo-audit
        run: cargo install --locked cargo-audit

      - name: Security audit
        run: cargo audit -D warnings

      - name: Build
        run: cargo build --all-targets --locked

      - name: Test
        run: cargo test --all-targets --locked
