name: check

on:
  push:
    branches:
      - main
  pull_request:
  workflow_dispatch:

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
          - os: macos-latest
          - os: windows-latest
    runs-on: ${{ matrix.os }}
    timeout-minutes: 15

    steps:
      - uses: actions/checkout@v4
      - run: rustup update stable
      - run: rustup default stable
      - uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
      - run: cargo test --no-run
      - run: cargo test --all-features
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  typos:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    timeout-minutes: 10

    steps:
      - uses: actions/checkout@v4
      - run: cargo install --debug --path .
      - run: >
          jas install
          --gh crate-ci/typos@v1.31.1
          --sha f683c2abeaff70379df7176110100e18150ecd17a4b9785c32908aca11929993
          --gh-token ${{ secrets.GITHUB_TOKEN }}
      - run: typos .

  fmt:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    timeout-minutes: 10

    steps:
      - uses: actions/checkout@v4
      - run: rustup update stable
      - run: rustup default stable
      - run: rustup component add rustfmt
      - run: cargo fmt --all --check

  clippy:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    timeout-minutes: 10

    steps:
      - uses: actions/checkout@v4
      - run: rustup update stable
      - run: rustup default stable
      - run: cargo clippy --all --all-features -- -D warnings