name: ci
on: [push, pull_request]

jobs:
  check:
    name: Check build
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Install libudev-dev on Ubuntu
        if: ${{ matrix.os == 'ubuntu-latest' }}
        run: sudo apt update && sudo apt install -y libudev-dev
      - run: cargo check
      # Check example with static pool configuration
      - run: cargo check -p satrs-example --no-default-features

  test:
    name: Run Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Install nextest
        uses: taiki-e/install-action@nextest
      - run: sudo apt update && sudo apt install -y libudev-dev
      - run: cargo nextest run --all-features
      - run: cargo test --doc --all-features

  cross-check:
    name: Check Cross-Compilation
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - armv7-unknown-linux-gnueabihf
          - thumbv7em-none-eabihf
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: "armv7-unknown-linux-gnueabihf, thumbv7em-none-eabihf"
      - run: cargo check -p satrs --target=${{matrix.target}} --no-default-features

  fmt:
    name: Check formatting
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt
      - run: cargo fmt --all -- --check

  docs:
    name: Check Documentation Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@nightly
      - run: RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc -p satrs --all-features --no-deps

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          components: clippy
      - run: sudo apt update && sudo apt install -y libudev-dev
      - run: cargo clippy -- -D warnings
