name: CI

on:
  push:
    branches: [master]
  pull_request:

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-D warnings"

jobs:
  test:
    name: test (ubuntu)
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install system tools
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            gdisk \
            fdisk \
            e2fsprogs \
            genext2fs
          # Sanity-check that everything we cross-validate against is on PATH.
          which sgdisk
          which fdisk
          which e2fsck
          which debugfs
          which mke2fs
          which genext2fs

      - uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - uses: Swatinem/rust-cache@v2

      - name: cargo fmt --check
        run: cargo fmt --all -- --check

      - name: cargo clippy
        run: cargo clippy --all-targets --all-features -- -D warnings

      - name: cargo build
        run: cargo build --all-targets --verbose

      - name: cargo test
        run: cargo test --all-targets --verbose

      - name: cargo doc
        run: cargo doc --no-deps --all-features
        env:
          RUSTDOCFLAGS: "-D warnings"
