name: Documentation

"on":
  push:
    branches: [main]
    paths:
      - 'docs/**'
      - 'src/genro_builders/**'
      - '.readthedocs.yaml'
  pull_request:
    branches: [main]
    paths:
      - 'docs/**'
      - 'src/genro_builders/**'
      - '.readthedocs.yaml'
  workflow_dispatch:

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

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -e ".[docs]"

      - name: Build documentation with Sphinx
        run: |
          sphinx-build -b html docs docs/_build/html --keep-going

      - name: Upload documentation artifacts
        uses: actions/upload-artifact@v4
        with:
          name: documentation
          path: docs/_build/html/

      - name: Check for broken links
        run: |
          sphinx-build -b linkcheck docs docs/_build/linkcheck
