name: Quality

on:
  pull_request:
  push:
    branches: [master]

permissions:
  contents: read

jobs:
  pre-commit:
    name: pre-commit + typecheck
    runs-on: ubuntu-latest
    timeout-minutes: 20

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"

      - name: Install pre-commit
        run: pip install pre-commit

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 11

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 24
          cache: pnpm

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      # pre-commit 为本地与 CI 的统一入口(local hook 复用 package.json scripts 同款工具)
      - name: pre-commit (PR incremental)
        if: github.event_name == 'pull_request'
        run: pre-commit run --from-ref origin/${{ github.base_ref }} --to-ref HEAD

      - name: pre-commit (full)
        if: github.event_name != 'pull_request'
        run: pre-commit run --all-files

      - name: Lint
        run: pnpm lint

      - name: Typecheck
        run: pnpm typecheck

      - name: Format check
        run: pnpm format:check