Skip to content

ci(docs): cache the gallery execution stamps, and publish a PR docs artifact - #337

Draft
pellet wants to merge 1 commit into
NeuroTechX:masterfrom
pellet:fix/docs-ci-cache-and-preview
Draft

ci(docs): cache the gallery execution stamps, and publish a PR docs artifact#337
pellet wants to merge 1 commit into
NeuroTechX:masterfrom
pellet:fix/docs-ci-cache-and-preview

Conversation

@pellet

@pellet pellet commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

The cache stores doc/_build/html, which is not what makes a docs build cheap. sphinx-gallery skips an example only when <example>.py.md5 sits beside its generated rst in doc/auto_examples, and Sphinx tracks staleness in doc/_build/doctrees — neither cached, both gitignored, so every example re-executes every run. On master push 33301489918 the cache hit and the computation-time summary still shows 32.9 s, 31.3 s, 29.3 s, 24.2 s.

Cache those two directories instead. Locally: cold build 145 s, rebuild 28 s, all previously executed examples at 0.00 s.

The key is two-part because the per-example md5 cannot see a library change. The prefix hashes eegnb/**, doc/** and the docs environment; the examples hash follows it. So a restore-keys fallback only matches an entry built against the same library: examples-only PR reuses the rest, library change re-runs cold.

Also adds upload-artifact, so a reviewer can download a PR's rendered docs — docs.yml otherwise only publishes on push to master. No change to the master deploy.

Related: #322 (draft) adds an artifact step too and deploys a live preview to gh-pages/pr-preview/; that push needs a write token, which fork pull_request runs don't get, so the artifact is the part that works everywhere.

@pellet
pellet marked this pull request as draft September 1, 2026 12:10
@pellet
pellet force-pushed the fix/docs-ci-cache-and-preview branch from 96ef0f4 to 2cab680 Compare September 1, 2026 12:22
@pellet pellet changed the title ci(docs): fix stale cache key and add PR build artifact ci(docs): fix stale cache key and add a downloadable PR docs-build artifact Sep 1, 2026
Two independent changes to the docs workflow.

1. The cache never saved a rebuild. It stored doc/_build/html, but
sphinx-gallery decides whether to re-run an example by comparing the
example's md5 against `<example>.py.md5` written beside its generated rst
in doc/auto_examples, and Sphinx tracks its own staleness in
doc/_build/doctrees. Neither was cached, both are gitignored, so a fresh
checkout had no stamps and every example re-executed every run: on the
master push 33301489918 the cache hit restored 23 MB of html and the
computation-time summary still reports 32.9 s, 31.3 s, 29.3 s and 24.2 s
for the same examples. The restored html was overwritten and bought
nothing.

Cache doc/auto_examples and doc/_build/doctrees instead. Locally, a cold
build takes 145 s and an immediate rebuild 28 s, with every previously
executed example reported at 0.00 s; the one example that re-runs is the
one that failed the first pass, since a failed example is never stamped.

The key is in two parts because the per-example md5 covers only the
example source and cannot see a library change. The prefix hashes
eegnb/**, doc/** and the docs environment, and only the examples hash
follows it, so a restore-key fallback can match only an entry built
against the same library, an example-only change still reuses every other
example's output, and a library change matches nothing and re-runs cold.
This replaces a discard-on-full-build step: that keyed off a diff against
master, which is empty on a master push, so it could not have caught the
library merge it was meant to catch.

2. Upload doc/_build/html as an artifact so a reviewer can look at the
rendered docs for a pull request. Deliberately not a deployed preview:
that needs a write token, which pull_request runs from forks do not get,
whereas a downloadable artifact works on every pull request.
@pellet
pellet force-pushed the fix/docs-ci-cache-and-preview branch from 312ec77 to 682e3c1 Compare September 3, 2026 12:34
@pellet pellet changed the title ci(docs): fix stale cache key and add a downloadable PR docs-build artifact ci(docs): cache the gallery execution stamps, and publish a PR docs artifact Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant