name: CI Checks

on: [push, pull_request]

jobs:
  test-units:
    strategy:
      matrix:
        os: [ubuntu-latest]
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: wasm32-unknown-unknown
          override: true
      - uses: actions/setup-python@v5
        with:
          python-version: '3.13'

      - uses: Swatinem/rust-cache@v2

      - name: Update apt cache
        run: |
          sudo apt update -y

      - name: Install dependencies (Linux)
        run: |
          sh contrib/dependency_setup.sh
        if: matrix.os == 'ubuntu-latest'

      - name: Run test units
        run: |
          make test

      - name: Compile all bins
        run: |
          make

  feature-powerset:
    name: Test crate feature powerset on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest]

    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: wasm32-unknown-unknown
          override: true
      - uses: taiki-e/install-action@cargo-hack
      - uses: Swatinem/rust-cache@v2

      - name: Update apt cache
        run: |
          sudo apt update -y

      - name: Install dependencies (Linux)
        run: |
          sh contrib/dependency_setup.sh
        if: matrix.os == 'ubuntu-latest'

      - name: Run feature powerset builds
        run: |
          make check

  fmt:
    name: rustfmt
    timeout-minutes: 30
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          components: rustfmt
          override: true
      - run: |
          cargo +nightly fmt -- --check
