|
| 1 | +# Builds and deploys Sphinx documentation to GitHub Pages |
| 2 | +# - Push to master: deploys to site root |
| 3 | +# - Pull requests: deploys preview to pr-preview/pr-{number}/ |
| 4 | +# - PR closed: cleans up the preview automatically |
| 5 | +name: docs |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [master] |
| 10 | + pull_request: |
| 11 | + branches: [master] |
| 12 | + # Include 'closed' to trigger preview cleanup when PR is merged/closed |
| 13 | + types: [opened, synchronize, reopened, closed] |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write # Push to gh-pages branch |
| 17 | + pull-requests: write # Post preview URL comments on PRs |
| 18 | + |
| 19 | +jobs: |
| 20 | + # Build Sphinx docs and upload as artifact |
| 21 | + build: |
| 22 | + # Skip build on PR close - only cleanup is needed |
| 23 | + if: github.event.action != 'closed' |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Install uv |
| 29 | + uses: astral-sh/setup-uv@v5 |
| 30 | + |
| 31 | + - name: Install dependencies |
| 32 | + run: uv sync --group docs |
| 33 | + |
| 34 | + - name: Build docs |
| 35 | + run: uv run sphinx-build docs docs/_build/html |
| 36 | + |
| 37 | + # Disable Jekyll processing so _static directory is served correctly |
| 38 | + - name: Add .nojekyll |
| 39 | + run: touch docs/_build/html/.nojekyll |
| 40 | + |
| 41 | + - name: Upload artifact |
| 42 | + uses: actions/upload-artifact@v4 |
| 43 | + with: |
| 44 | + name: docs |
| 45 | + path: docs/_build/html |
| 46 | + |
| 47 | + # Deploy to gh-pages root on push to master |
| 48 | + deploy: |
| 49 | + needs: build |
| 50 | + if: github.ref == 'refs/heads/master' && github.event_name == 'push' |
| 51 | + runs-on: ubuntu-latest |
| 52 | + steps: |
| 53 | + - uses: actions/download-artifact@v4 |
| 54 | + with: |
| 55 | + name: docs |
| 56 | + path: docs |
| 57 | + |
| 58 | + - name: Deploy to GitHub Pages |
| 59 | + uses: peaceiris/actions-gh-pages@v4 |
| 60 | + with: |
| 61 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + publish_dir: ./docs |
| 63 | + |
| 64 | + # Deploy PR preview to pr-preview/pr-{number}/ subdirectory |
| 65 | + # Automatically posts comment with preview URL and cleans up on PR close |
| 66 | + preview: |
| 67 | + needs: build |
| 68 | + if: github.event_name == 'pull_request' |
| 69 | + runs-on: ubuntu-latest |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + |
| 73 | + - uses: actions/download-artifact@v4 |
| 74 | + with: |
| 75 | + name: docs |
| 76 | + path: docs |
| 77 | + |
| 78 | + - name: Deploy PR Preview |
| 79 | + uses: rossjrw/pr-preview-action@v1 |
| 80 | + with: |
| 81 | + source-dir: ./docs |
0 commit comments