Documentation
on:
  push:
    branches:
      - main
  pull_request:
    types:
      - opened
      - synchronize

name: Rust CI

jobs:
  rust_ci:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-latest, ubuntu-latest, windows-latest]
        rust: [stable, beta, nightly]

    steps:
      - name: Prepare git
        if: startsWith(matrix.os, 'windows')
        run: |-
          git config --global core.autocrlf false
          git config --global core.eol lf

      - uses: actions/checkout@v4
        with:
          submodules: "recursive"

      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: ~/.cargo
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-cargo

      - name: Cache cargo build
        uses: actions/cache@v4
        with:
          path: target
          key: ${{ runner.os }}-${{ matrix.rust }}-build-target-${{ hashFiles('**/Cargo.lock') }}
          restore-keys: ${{ runner.os }}-${{ matrix.rust }}-build-target-

      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ matrix.rust }}
          targets: wasm32-unknown-unknown
          components: rustfmt, clippy

      - run: cargo fmt --all -- --check
      - run: cargo clippy --all -- -D warnings
      - run: cargo clippy --target wasm32-unknown-unknown -- -D warnings
      - run: cargo test --all