name: Build and deploy docs

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]
    tags:
      - "v*"
  workflow_dispatch: {}

permissions:
  contents: write

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install uv and set the Python version
        uses: astral-sh/setup-uv@v7
        with:
          enable-cache: true
          python-version: "3.12"

      - name: Install dependencies
        run: |
          uv sync --locked --all-groups

      - name: Build docs
        working-directory: docs
        run: |
          uv run bash sphinx_build.sh
        #   uv run sphinx-build -b html docs docs/_build/

      - name: Copy README into site
        run: cp README.md docs/_build/README.md

      - name: Copy CNAME into site
        run: cp docs/CNAME docs/_build/CNAME

      - name: Copy contributing into site
        run: cp Contributing.md docs/_build/Contributing.md

      - name: Deploy to gh-pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: docs/_build/
          publish_branch: gh-pages
