name: Check
on:
  pull_request:
  push:
    branches:
      - main

env:
  RUSTFLAGS: -D warnings
  RUSTDOCFLAGS: -D warnings
  RUST_BACKTRACE: 1
  CARGO_TERM_COLOR: always
  CLICOLOR: 1

jobs:
  cargo-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1
      - uses: taiki-e/install-action@cargo-hack

      - run: cargo hack check --each-feature --locked --rust-version --ignore-private --workspace --lib --bins --keep-going

  cargo-clippy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1

      - run: cargo clippy --workspace --all-features --all-targets --keep-going

  cargo-doc:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1

      - run: cargo doc --workspace --all-features --no-deps --document-private-items --keep-going

  cargo-reedme:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1

      - run: cargo install --locked cargo-reedme
      - run: cargo +nightly reedme --check

  cargo-fmt:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1

      - run: cargo fmt --all --check

  cargo-test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    continue-on-error: true
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rust-lang/setup-rust-toolchain@v1
      - uses: taiki-e/install-action@cargo-hack

      - run: cargo test --workspace --no-run
      - run: cargo hack test --each-feature --workspace
