ci: pass API_USGS_PAT to docs + tests; cache Sphinx build outputs#294
Draft
thodson-usgs wants to merge 2 commits into
Draft
ci: pass API_USGS_PAT to docs + tests; cache Sphinx build outputs#294thodson-usgs wants to merge 2 commits into
thodson-usgs wants to merge 2 commits into
Conversation
Both workflows hit the live Water Data API: the doc build executes
every notebook with no committed outputs (nbsphinx ``nbsphinx_execute``
defaults to ``'auto'`` and the project convention is no committed
outputs); the test workflow runs the live ``tests/waterdata_test.py``
suite. Without an API key both run unauthenticated (~60 req/min),
which is fragile as the demo notebook set and live-test count grow.
Add ``env: API_USGS_PAT: ${{ secrets.API_USGS_PAT }}`` to the relevant
step in each workflow. If the secret is not configured the variable
resolves to an empty string and both workflows fall back to
unauthenticated behavior (no change from today); once the secret is
added in repo settings, both workflows pick up the higher
authenticated quota automatically.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sphinx tracks source mtimes against doctrees in ``${BUILDDIR}/.doctrees/``:
unchanged sources skip re-parsing, which for nbsphinx
(``nbsphinx_execute='auto'``) means unchanged notebooks aren't
re-executed. Persisting ``docs/build/`` across CI runs picks up that
free incremental behavior — most PRs touch a handful of source files,
so the doc build only re-executes the actually-changed notebooks
instead of the whole 19-notebook set.
The cache key hashes every input that affects the rendered docs
(notebooks, RST/MD, ``conf.py``, and the Python package — autodoc
reads docstrings); any change invalidates exact-match. The
``restore-keys: sphinx-`` fallback gives partial-match recovery so
even a cache-key miss restores recent doctrees, and Sphinx then only
re-builds the files whose source actually changed.
A proper jupyter-cache adoption via MyST-NB is the deeper migration
path (``nb_execution_mode = 'cache'`` integrates jupyter-cache
natively) but it requires reworking the existing ``.nblink`` references
to external notebooks. This caches the equivalent via the build dir
without the doc-tree rewrite.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two small CI improvements that compound. Targeted at the doc-build and live-test workflows that hit the live Water Data API.
Commits
ci: pass API_USGS_PAT to docs + test workflows when the secret is setenv: API_USGS_PAT: ${{ secrets.API_USGS_PAT }}to the build step insphinx-docs.ymland the pytest step inpython-package.yml.ci(docs): cache Sphinx build outputs across runsactions/cache@v4ondocs/build/keyed on source hashes, so unchanged notebooks aren't re-executed on the next CI run.What problem this solves
main— all.ipynbship with emptyoutputsarrays), sonbsphinx's default'auto'mode executes every notebook against the live API on everypushandpull_request.API_USGS_PATtoday, so the doc build (and the live tests inpython-package.yml) hit the ~60 req/min unauthenticated rate limit. As the demo notebook set grows this becomes increasingly fragile.What this PR does
Commit 1 — pass through
API_USGS_PATThe change is purely additive: if
secrets.API_USGS_PATis configured (in repo settings), both workflows pick up the authenticated quota. If it isn't, the env var resolves to an empty string and the workflows fall back to today's unauthenticated behavior — no observable change until the secret is added.Commit 2 — cache Sphinx build outputs
actions/cache@v4persistsdocs/build/(which includes.doctrees/) across CI runs. Sphinx checks source mtimes against the doctree; unchanged sources skip re-parsing, which fornbsphinx(nbsphinx_execute='auto') means unchanged notebooks aren't re-executed. The cache key hashes every input that affects the rendered docs — notebooks, RST/MD,conf.py, and the Python package (autodoc reads docstrings) — so any source change invalidates exact-match. Therestore-keys: sphinx-fallback gives partial-match recovery: even a key miss restores recent doctrees, and Sphinx then only re-builds the files whose source actually changed.Result: most PRs only touch a handful of files, so the doc build re-executes only the actually-changed notebooks instead of the whole 19-notebook set.
What this PR does NOT do (intentional)
MyST-NB+jupyter-cache. That's the canonical "adopt jupyter-cache" path (nb_execution_mode = 'cache'integrates jupyter-cache natively), but it requires reworking the existing.nblinkreferences to external notebooks underdemos/. Cachingdocs/build/viaactions/cacheachieves the equivalent functional benefit without the doc-tree rewrite. The MyST-NB migration is a worthwhile larger follow-up.API_USGS_PATsecret (can't be done from code; that's a repo-settings action).🤖 Generated with Claude Code