name: CI
on: [push, pull_request]

env:
  RUSTFLAGS: "-Dwarnings"
  RUSTDOCFLAGS: "-Dwarnings"

jobs:
  test:
    name: Test
    strategy:
      matrix:
        os: [windows-2025, ubuntu-24.04, macos-15]
        rust: [stable, nightly]
        include:
          - os: ubuntu-24.04
            rust: beta
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@master
      - name: Install Rust
        run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}
      - run: cargo test
      - run: cargo test --no-default-features

  doc_fmt:
    name: Document and check formatting
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@master
      - name: Install Rust
        run: |
          rustup update nightly
          rustup default nightly
          rustup component add rustfmt
      - uses: Swatinem/rust-cache@v2
      - run: cargo doc
      - run: cargo fmt --check

  msrv:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@master
      - name: Install Rust
        run: |
          msrv="$(cargo metadata --format-version=1 |
            jq -r '.packages[] | select(.name == "getopts").rust_version'
          )"
          rustup update "$msrv" && rustup default "$msrv"
      - uses: Swatinem/rust-cache@v2
      - run: cargo check
