name: Documentation Building

on:
  release:
    types: [published]
  push:
    branches:
      - main
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build_and_deploy:
    permissions:
      contents: write
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Install uv
        uses: astral-sh/setup-uv@v7

      - name: Set up Python
        run: uv python install 3.13

      - name: Install dependencies
        run: uv sync --all-extras --dev

      - name: Build Release Documentation
        run: uv run python tools/build_docs.py docs-build --version latest
        if: github.event_name == 'release'

      - name: Build Documentation
        run: uv run python tools/build_docs.py docs-build --version latest
        if: github.event_name != 'release'

      - name: Upload artifact
        uses: actions/upload-pages-artifact@v4
        with:
          path: docs-build/

      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
