name: CI

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2

      - name: Build
        run: cargo build --verbose

      - name: Run tests
        run: cargo test --verbose

      - name: Clippy
        run: cargo clippy -- -D warnings

      - name: Format check
        run: cargo fmt -- --check

  build-macos:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v6

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2

      - name: Build
        run: cargo build --verbose

      - name: Run tests
        run: cargo test --verbose

  msrv:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Install MSRV Rust
        uses: dtolnay/rust-toolchain@1.88

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2

      - name: Check MSRV
        run: cargo check --verbose

  build-freebsd:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Build on FreeBSD
        uses: vmactions/freebsd-vm@v1
        with:
          release: "14.2"
          usesh: true
          prepare: |
            pkg install -y curl
            curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
          run: |
            . $HOME/.cargo/env
            cargo build --verbose
            cargo test --verbose
