name: CI

on:
  push:
    branches: [main]
  pull_request:
  workflow_call:

env:
  CARGO_TERM_COLOR: always

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: Swatinem/rust-cache@v2
      - name: Formatting
        run: cargo fmt --all --check
      - name: Clippy
        run: cargo clippy --all-targets --all-features -- -D warnings
      - name: Build docs
        run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features

  test:
    name: Test (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v4
      - uses: Swatinem/rust-cache@v2
      - name: Tests (default features)
        run: cargo test
      - name: Tests alloc
        run: cargo test --features alloc-tests -j 1 alloc
      - name: Tests cli
        run: cargo test --features cli cli
      - name: Build examples
        run: cargo build --examples --all-features

  test-no-simd:
    name: Test (no SIMD)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: Swatinem/rust-cache@v2
      - name: Tests (no default features)
        run: cargo test --no-default-features
