name: CI

on:
  pull_request:
  push:
  workflow_dispatch:

env:
  CARGO_INCREMENTAL: 0
  CARGO_PROFILE_RELEASE_LTO: "thin"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: swatinem/rust-cache@v2
      - name: Install Rust components
        run: |
          rustup component add clippy
          rustup component add rustfmt
      - name: Lint
        run: |
          cargo clippy --all-targets --all-features -- -D warnings
          cargo fmt -- --check
      - name: Build
        run: cargo build
  test:
    name: Test rust ${{ matrix.rust }} on ${{ matrix.os }}
    needs: build
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - { os: ubuntu-latest }
          - { os: macos-latest }
          - { os: windows-latest }
    steps:
      - uses: actions/checkout@v4
      - uses: swatinem/rust-cache@v2
      - name: Run tests
        run: cargo test
