name: CI Docs

on:
  push:
    branches:
      - main
  pull_request:

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

jobs:
  build-docs:
    name: "Build Docs"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
      - name: Install dependencies
        run: |
          python -m pip install -e .
          python -m pip install ".[docs]"
      - name: Set up Quarto
        uses: quarto-dev/quarto-actions/setup@v2
      - name: Build docs
        run: |
          make docs-build
      - name: Save docs artifact
        uses: actions/upload-artifact@v4
        with:
          name: docs-html
          path: docs/_site

  publish-docs:
    name: "Publish Docs"
    runs-on: ubuntu-latest
    needs: "build-docs"
    if: github.ref == 'refs/heads/main'
    permissions:
      contents: read
      pages: write
      id-token: write
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: docs-html
          path: docs/_site
      - name: Setup Pages
        uses: actions/configure-pages@v4
      - name: Upload to GitHub Pages
        uses: actions/upload-pages-artifact@v3
        with:
          path: docs/_site
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
