---
name: Cargo Build & Test

on:  # yamllint disable-line rule:truthy
  push:
  pull_request:

env:
  CARGO_TERM_COLOR: always
  # Make sure CI fails on all warnings, including Clippy lints
  RUSTFLAGS: "-Dwarnings"

jobs:
  build_and_test:
    name: Rust project - latest
    runs-on: ubuntu-latest
    strategy:
      matrix:
        toolchain:
          - stable
          - beta
          - nightly
    steps:
      - name: Install dependencies
        run: >
          sudo apt-get update
          && sudo apt-get install --no-install-recommends --yes
          bzip2 lz4 lzop xz-utils zstd
      - uses: actions/checkout@v4
      - run: >
          rustup update ${{ matrix.toolchain }}
          && rustup default ${{ matrix.toolchain }}
      - run: cargo build --verbose
      - run: cargo test --verbose

  clippy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run Clippy
        run: cargo clippy --all-targets --all-features

  rustfmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run rustfmt
        run: cargo fmt --all --check
