name: CI

on:
  pull_request:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read

jobs:
  ci:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - uses: jdx/mise-action@v4
      - name: Install Rust components
        run: rustup component add rustfmt clippy
      - name: Format
        run: cargo fmt --check
      - name: Clippy
        run: cargo clippy --all-targets --locked -- -D warnings
      - name: Test
        run: cargo test --all-targets --locked
      - name: Rustdoc
        run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --locked
      - name: CLI help smoke
        run: |
          cargo run --locked -- --help
          cargo run --locked -- run --help
          cargo run --locked -- chat --help
          cargo run --locked -- audit --help | tee /tmp/oy-audit-help.txt
          grep -F -- "--max-chunks <N>" /tmp/oy-audit-help.txt
          cargo run --locked -- model --help
          cargo run --locked -- doctor --help
      - name: Documentation drift checks
        run: |
          ! grep -R -n -E 'src/(app|chat|config|model|session|ui)\.rs' README.md CONTRIBUTING.md docs
      - name: Package crate
        run: cargo package --locked
