name: PR checks

# Runs on pull requests into main (typically from dev) and into dev (typically
# from feature/* branches): lint + format checks, a demo settings-manifest
# drift guard, and a no-push image build to prove the Docker images still build.

on:
  pull_request:
    branches: [main, dev]

concurrency:
  group: ci-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  lint:
    name: Lint & format
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Install ruff
        run: pip install "ruff>=0.8.0"

      - name: Ruff lint (Python)
        run: ruff check .

      - name: Ruff format check (Python)
        run: ruff format --check .

      - name: Set up Node
        uses: actions/setup-node@v4
        with:
          node-version: "22"
          cache: npm
          cache-dependency-path: frontend/package-lock.json

      - name: Install frontend deps
        run: npm ci
        working-directory: frontend

      - name: ESLint (frontend)
        run: npm run lint
        working-directory: frontend

      - name: Prettier check (frontend)
        run: npm run format:check
        working-directory: frontend

  demo-manifest:
    name: Demo settings manifest in sync
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.12"
          cache: pip
          cache-dependency-path: backend/requirements.txt

      - name: Install backend deps + pytest
        run: pip install -r backend/requirements.txt pytest

      # Fails if admin_settings_manifest.py changed without regenerating the
      # demo snapshot. Fix: `python scripts/export_settings_manifest.py` then
      # `npx --prefix frontend prettier --write \
      #   src/lib/webapp/settingsManifest.generated.json`, and commit the result.
      - name: Check demo settings manifest is in sync
        run: python -m pytest tests/test_settings_manifest_demo_sync.py -q

  build:
    name: Docker build
    uses: ./.github/workflows/_docker-build-push.yml
    with:
      push: false
      tag_mode: dev
