name: CI

on:
  push:
    branches: [main]
    tags-ignore:
      - "**"
  pull_request:
    branches: [main]
  workflow_call:

env:
  CARGO_TERM_COLOR: always

jobs:
  check:
    name: Check
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/setup-rust
      - run: cargo check --all-features

  fmt:
    name: Format
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/setup-rust
      - run: cargo fmt --all -- --check

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/setup-rust
      - run: cargo clippy --all-features -- -D warnings

  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/setup-rust
      - run: cargo test --all-features

  doc:
    name: Documentation
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/setup-rust
      - run: cargo doc --all-features --no-deps
        env:
          RUSTDOCFLAGS: -D warnings

  msrv:
    name: MSRV (1.87)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/setup-rust
        with:
          toolchain: "1.87"
      - run: cargo check --all-features

  feature-combinations:
    name: Feature Combinations
    runs-on: ubuntu-latest
    strategy:
      matrix:
        features:
          - ""
          - "helios"
          - "lasercube-usb"
          - "ether-dream"
          - "idn"
          - "lasercube-wifi"
          - "usb-dacs"
          - "network-dacs"
          - "all-dacs"
          - "serde"
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/setup-rust
      - name: Check with features '${{ matrix.features }}'
        run: cargo check --no-default-features ${{ matrix.features && format('--features {0}', matrix.features) || '' }}
