name: Cargo Build & Test

on:
  push:
    branches: main
  pull_request:

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            ~/.cargo-install/
            ~/.rustup/toolchains/
            target/
            docs/book/book/
          key: cargo-${{ hashFiles('Cargo.toml') }}
      - name: Install wasm32 target
        run: rustup target add wasm32-unknown-unknown
      - name: Install mdbook
        uses: baptiste0928/cargo-install@v3
        with:
          crate: mdbook
      - name: Install mdbook-callouts
        uses: baptiste0928/cargo-install@v3
        with:
          crate: mdbook-callouts
      - name: Install mdbook-inline-highlighting
        uses: baptiste0928/cargo-install@v3
        with:
          crate: mdbook-inline-highlighting
      - name: Build
        run: cargo build --verbose
      - name: Build Wasm
        run: cargo build --verbose --target wasm32-unknown-unknown --no-default-features --features logging
      - name: Build book
        run: mdbook build docs/book
      - name: Build benchmarks
        run: cargo bench -p ixa-bench --no-run
      - name: Run tests
        run: cargo test --workspace --verbose
      - name: Run examples
        run: cargo test --examples
