name: Build docs

on: [push, pull_request]

permissions:
    contents: write
jobs:
    build:
      runs-on: ubuntu-latest
      steps:
        - name: checkout source code
          uses: actions/checkout@v4
        - name: Set up Python
          uses: actions/setup-python@v5
          with:
            python-version: "3.11"
        - name: Install uv
          uses: astral-sh/setup-uv@v4
        - name: Install python dependencies
          run: |
            uv venv
            uv sync
        - name: Build documentation
          run: |
            mkdir gh-pages
            touch gh-pages/.nojekyll
            uv run make -C docs html
            cp -r docs/_build/html/* gh-pages/
        - name: Deploy documentation
          if: ${{ github.event_name == 'push' }}
          uses: JamesIves/github-pages-deploy-action@v4
          with:
            branch: gh-pages
            folder: gh-pages
