name: CI

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

env:
  CARGO_TERM_COLOR: always

jobs:
  ci:
    name: ${{ matrix.job }} (${{ matrix.os }})
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        job: [fmt, clippy, test, build]

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      - name: Install Rust toolchain
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          components: rustfmt, clippy

      - name: Install native dependencies
        run: sudo apt-get update && sudo apt-get install -y libudev-dev

      - name: Check formatting
        if: matrix.job == 'fmt'
        run: cargo fmt --all -- --check

      - name: Clippy
        if: matrix.job == 'clippy'
        run: cargo clippy --all-targets --all-features

      - name: Run tests
        if: matrix.job == 'test'
        run: cargo test --all-features

      - name: Release build
        if: matrix.job == 'build'
        run: cargo build --release --all-features

