name: Docs (MkDocs → GitHub Pages)

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

permissions:
  contents: read
  pages: write
  id-token: write

concurrency:
  group: "pages"
  cancel-in-progress: false

jobs:
  build:
    name: Build MkDocs Site
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"
          cache: "pip"
          cache-dependency-path: "pyproject.toml"

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e ".[dev]"

      - name: Build MkDocs site (strict)
        env:
          PYTHONPATH: ${{ github.workspace }}/src
        run: mkdocs build --clean --strict --site-dir site

      - name: Upload site artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: ./site

  deploy:
    name: Deploy to GitHub Pages
    runs-on: ubuntu-latest
    timeout-minutes: 10
    needs: build
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4

