name: Deploy Docs

on:
  push:
    branches: ["main"]
    paths:
      - 'docs/**'
      - 'mkdocs.yml'
      - 'mkdocs.en.yml'
      - 'README.md'
  pull_request:
    paths:
      - 'docs/**'
      - 'mkdocs.yml'
      - 'mkdocs.en.yml'
      - 'README.md'
  workflow_dispatch:

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

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

jobs:
  build:
    name: Build mkdocs site
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install uv
        uses: astral-sh/setup-uv@v4
        with:
          enable-cache: false
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - name: Configure Pages
        uses: actions/configure-pages@v4
      - name: Install docs dependencies
        run: uv pip install --system mkdocs mkdocs-material mkdocstrings[python] pymdown-extensions
      - name: Install package with dev dependencies
        run: uv pip install --system -e '.[dev]'
      - name: Build site (Chinese)
        run: PYTHONPATH=src mkdocs build
      - name: Build site (English)
        run: PYTHONPATH=src mkdocs build --config-file mkdocs.en.yml
      - name: Upload Pages artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: 'site'

  deploy:
    name: Deploy to GitHub Pages
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - name: Deploy
        id: deployment
        uses: actions/deploy-pages@v4
