name: PR

on:
  pull_request:
    paths-ignore:
      - 'README.md'
  schedule:
    - cron: '0 20 * * 6'

permissions:
  contents: read

jobs:
  test:
    name: test
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - 1.65.0 # MSRV
          - stable
          - beta
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
      - name: Run tests
        run: cargo test --workspace

  coverage:
    name: coverage
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-llvm-cov
      - name: Generate code coverage
        run: cargo llvm-cov --lcov --output-path lcov.info
      - name: Upload to Coveralls
        uses: coverallsapp/github-action@v2
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

  lint:
    name: fmt & lint
    runs-on: ubuntu-slim
    steps:
      - uses: actions/checkout@v6
      - uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          components: rustfmt, clippy
      - name: Rustfmt Check
        run: cargo fmt --check --all
      - name: Clippy check
        run: cargo clippy --workspace
