name: CI

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

permissions:
  contents: read

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    name: Rust CI - ${{ matrix.rust }}
    runs-on: ubuntu-latest
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        rust: ["stable", "nightly"]
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}
          components: rustfmt,clippy
      - uses: Swatinem/rust-cache@v2
        with:
          cache-on-failure: true
      - name: Build
        run: cargo build
      - name: Test
        run: cargo test --workspace
      - name: Lint
        run: cargo clippy --workspace --all-targets --all-features
        env:
          RUSTFLAGS: -Dwarnings
      - name: Fmt
        run: cargo fmt --all --check
      - name: Licensing
        uses: EmbarkStudios/cargo-deny-action@v2.0.14
        with:
          command: check licenses sources
