name: CI

on:
  push:
    branches: [main]
    tags: ["v*"]
  pull_request:

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
          - os: macos-latest
            target: aarch64-apple-darwin
          - os: windows-latest
            target: x86_64-pc-windows-msvc

    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v5

      - name: Install Rust
        run: rustup toolchain install stable --target ${{ matrix.target }}

      - name: Install musl tools
        if: contains(matrix.target, 'musl')
        run: sudo apt-get update && sudo apt-get install -y musl-tools

      - name: Run tests
        run: cargo test --all-features --target ${{ matrix.target }}

      - name: Run clippy
        run: cargo clippy --all-features --target ${{ matrix.target }} -- -D warnings

      - name: Check no-default-features
        run: cargo check --no-default-features --target ${{ matrix.target }}

  wasm:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - name: Install Rust
        run: rustup toolchain install stable --target wasm32-unknown-unknown

      - name: Check wasm32
        run: cargo check --no-default-features --target wasm32-unknown-unknown

  fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - name: Install Rust
        run: rustup toolchain install stable --component rustfmt

      - name: Check formatting
        run: cargo fmt -- --check
