name: CI

on: [push, pull_request]

jobs:
  find_typos:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: crate-ci/typos@v1.40.0

  format_and_docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - uses: Swatinem/rust-cache@v2
      - name: 'Run fmt (Check formatting)'
        run: cargo fmt -- --check
      - name: 'Run doc (Check documentation)'
        run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features

  clippy:
    strategy:
      matrix:
        feature: ['', '--no-default-features', '--all-features']
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - uses: Swatinem/rust-cache@v2
      - name: 'Run clippy: ${{ matrix.feature }}'
        run: cargo clippy --all-targets ${{ matrix.feature }} -- -D warnings

  build_and_test:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        feature: ['', '--no-default-features', '--all-features']
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v4
    - uses: dtolnay/rust-toolchain@stable
    - uses: Swatinem/rust-cache@v2
    - name: 'Build and test ${{ matrix.os }}: ${{ matrix.feature }}'
      run: cargo test ${{ matrix.feature }}

  test_wasm:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v6
        with:
          node-version: 24
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: wasm32-unknown-unknown
      - uses: Swatinem/rust-cache@v2
      - uses: jetli/wasm-pack-action@v0.4.0
      - name: 'Test WebAssembly'
        run: wasm-pack test --node