|
| 1 | +name: Build & Deploy Sphinx docs |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] # change if your default branch is different |
| 6 | + pull_request: |
| 7 | + branches: [ main ] # build on PRs (no deploy) |
| 8 | + workflow_dispatch: # manual run |
| 9 | + |
| 10 | +# Avoid overlapping deployments |
| 11 | +concurrency: |
| 12 | + group: "pages" |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + pages: write |
| 18 | + id-token: write |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Python |
| 28 | + uses: actions/setup-python@v5 |
| 29 | + with: |
| 30 | + python-version: "3.11" # pick the version you prefer |
| 31 | + |
| 32 | + - name: Cache pip |
| 33 | + uses: actions/cache@v4 |
| 34 | + with: |
| 35 | + path: ~/.cache/pip |
| 36 | + key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }} |
| 37 | + restore-keys: | |
| 38 | + ${{ runner.os }}-pip- |
| 39 | +
|
| 40 | + - name: Install docs dependencies |
| 41 | + run: | |
| 42 | + python -m pip install --upgrade pip |
| 43 | + pip install -r docs/requirements.txt |
| 44 | +
|
| 45 | + # If your docs use autodoc (import your package), install it too: |
| 46 | + - name: Install package (editable) |
| 47 | + run: pip install -e . |
| 48 | + |
| 49 | + # Optional: set html_baseurl at build time (nice for canonical links) |
| 50 | + # Replace URL if you want to hardcode; otherwise you can delete -D line. |
| 51 | + - name: Build Sphinx HTML |
| 52 | + run: | |
| 53 | + sphinx-build \ |
| 54 | + -b html \ |
| 55 | + -D html_baseurl="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/" \ |
| 56 | + docs docs/_build/html |
| 57 | +
|
| 58 | + # Optional: include CNAME if you use a custom domain. Create docs/CNAME. |
| 59 | + - name: Add CNAME (if present) |
| 60 | + run: | |
| 61 | + if [ -f docs/CNAME ]; then |
| 62 | + cp docs/CNAME docs/_build/html/CNAME |
| 63 | + fi |
| 64 | +
|
| 65 | + - name: Upload artifact (site) |
| 66 | + uses: actions/upload-pages-artifact@v3 |
| 67 | + with: |
| 68 | + path: docs/_build/html |
| 69 | + |
| 70 | + # Deploy only on pushes (not PRs) |
| 71 | + deploy: |
| 72 | + if: ${{ github.event_name == 'push' }} |
| 73 | + needs: build |
| 74 | + runs-on: ubuntu-latest |
| 75 | + environment: |
| 76 | + name: github-pages |
| 77 | + url: ${{ steps.deployment.outputs.page_url }} |
| 78 | + steps: |
| 79 | + - id: deployment |
| 80 | + uses: actions/deploy-pages@v4 |
0 commit comments