|
| 1 | +name: Docs |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # Publish to dev/ on every push to main … |
| 6 | + branches: [main] |
| 7 | + # … and to a versioned directory on every release tag. |
| 8 | + tags: ["v*.*.*"] |
| 9 | + # Allow manual re-builds from the Actions tab. |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +# Only one docs deployment should run at a time to avoid race conditions on |
| 13 | +# the gh-pages branch. |
| 14 | +concurrency: |
| 15 | + group: docs-${{ github.ref }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write # needed to push to gh-pages |
| 20 | + |
| 21 | +jobs: |
| 22 | + build-and-deploy: |
| 23 | + name: Build & deploy docs |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Checkout repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + # Full history lets sphinx-gallery / git tools see tags correctly. |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + # ── uv + Python ──────────────────────────────────────────────────────── |
| 34 | + - name: Set up uv |
| 35 | + uses: astral-sh/setup-uv@v5 |
| 36 | + with: |
| 37 | + python-version: "3.13" |
| 38 | + enable-cache: true |
| 39 | + |
| 40 | + # ── Dependencies ─────────────────────────────────────────────────────── |
| 41 | + # Install the package itself plus the [docs] optional-dependency group |
| 42 | + # (sphinx, pydata-sphinx-theme, sphinx-gallery, pillow). |
| 43 | + # sphinx-gallery transitively brings in matplotlib, which the custom |
| 44 | + # scraper (docs/_sg_html_scraper.py) needs to render thumbnails. |
| 45 | + - name: Install dependencies (with docs extras) |
| 46 | + run: uv sync --extra docs |
| 47 | + |
| 48 | + # ── Sphinx build ─────────────────────────────────────────────────────── |
| 49 | + # -W turns warnings into errors so broken cross-references are caught. |
| 50 | + # Remove -W if the gallery examples produce unavoidable warnings. |
| 51 | + - name: Build HTML documentation |
| 52 | + run: | |
| 53 | + uv run sphinx-build -b html docs build/html -W --keep-going |
| 54 | +
|
| 55 | + # ── Determine deployment target ───────────────────────────────────────── |
| 56 | + # Release tag (refs/tags/v1.2.3) → destination = "v1.2.3" |
| 57 | + # Everything else (push to main, manual dispatch) → destination = "dev" |
| 58 | + - name: Determine deployment directory |
| 59 | + id: target |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then |
| 63 | + echo "dest_dir=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT" |
| 64 | + else |
| 65 | + echo "dest_dir=dev" >> "$GITHUB_OUTPUT" |
| 66 | + fi |
| 67 | +
|
| 68 | + # ── Deploy to gh-pages ──────────────────────────────────────────────── |
| 69 | + # keep_files: true preserves all existing directories on the branch so |
| 70 | + # versioned releases accumulate rather than overwriting each other. |
| 71 | + # Only the target destination_dir is replaced on each run. |
| 72 | + - name: Deploy to GitHub Pages |
| 73 | + uses: peaceiris/actions-gh-pages@v4 |
| 74 | + with: |
| 75 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + publish_dir: ./build/html |
| 77 | + destination_dir: ${{ steps.target.outputs.dest_dir }} |
| 78 | + keep_files: true |
| 79 | + # Commit message makes the deployment easy to identify in the branch log. |
| 80 | + commit_message: | |
| 81 | + docs: deploy ${{ steps.target.outputs.dest_dir }} @ ${{ github.sha }} |
| 82 | +
|
0 commit comments