Repository navigation
feat(templates): deploy the pull request preview from a job that runs no notebook code (#232) - #254
Conversation
2fcbbab to
3f97e8d
Compare
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟢 Approval recommended
The review context indicates there are no remaining active issues after the workflow-hardening updates (splitting untrusted build from credentialed deploy and disabling persisted checkout credentials) and associated docs/harness/changelog updates.
No open issues 🎉
What changed in this PR
This pull request hardens the workflow templates by separating the PR preview build work (which can execute untrusted notebook/build code) from the deploy work (which holds provider credentials), and by ensuring actions/checkout does not persist credentials in git config.
Changes:
- Split
templates/ci.ymlintobuild(no secrets),deploy(secrets + deploy from downloaded artifact), andpdf-check(runs alongside deploy; consumes build outputs). - Set
persist-credentials: falseon template checkouts (ci.yml,cache.yml,publish.yml) to avoid leaving tokens in git config across steps. - Update docs, add CI harness coverage for the build→deploy artifact handoff (including hidden files), and record the change in the changelog.
| File | Summary | Review notes (from final comments) |
|---|---|---|
templates/README.md |
Documents the new build/deploy/pdf-check structure and rationale. |
— |
templates/publish.yml |
Adds persist-credentials: false on checkout. |
— |
templates/ci.yml |
Implements the job split and artifact handoff; updates permissions and checkout behavior. | jupyter-cache upload lacks if-no-files-found, which can defer failure to download-artifact in pdf-check with a less actionable error. |
templates/cache.yml |
Adds persist-credentials: false on checkout. |
— |
docs/user/actions/preview-netlify.md |
Updates examples/guidance to the build+deploy job pattern (incl. private repo notes). | Example uploads from ${{ steps.build.outputs.build-path }} while deploy downloads/uses _build/html; this can drift if build dir is customized unless kept in sync. |
docs/user/actions/preview-cloudflare.md |
Updates examples/guidance to the build+deploy job pattern (incl. private repo notes). | Same potential path drift between uploaded artifact and deploy job’s _build/html configuration if build dir is customized. |
docs/user/actions/build-lectures.md |
Updates template references and required-check guidance (build vs preview). |
— |
CHANGELOG.md |
Adds an Unreleased entry documenting the template change. | — |
.github/workflows/test-actions.yml |
Adds harness jobs validating artifact handoff and credential-free change detection. | Broken quoting on the line that sets the job output ("$manifest" terminates the outer double-quoted string). |
Review effort: Balanced
|
Copilot's review (on
Claude Code (on behalf of mmcky) |
f719e8f to
3f97e8d
Compare
… no notebook code (#232) templates/ci.yml now builds in a `build` job (container, contents: read, no secrets) that uploads _build/html as an artifact, and deploys from a `deploy` job that holds the provider secrets and runs only setup-node, the artifact download and the preview action. pdf-check needs build and runs beside the deploy. Every checkout in the three templates sets persist-credentials: false. Change detection in the deploy job fetches without credentials, which a public repository allows; a private one sets fetch-depth: 0. Two harness jobs run the hand-off and the credential-free change detection against this repository's own pull request. Part of #239. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMYb5kQXUExhE6SQ65R
3f97e8d to
9b6db22
Compare
…ates and container READMEs (#191) (#260) PR 4 of the user manual (#178). docs/user gains five chapters: getting-started.md (the templates, their jobs and permissions, the changes a site makes to them, and migrating an existing repository), composition.md, containers.md, versioning.md and security.md. They describe main as it is after #254, #255, #257 and #258, with one alert for the two inputs the templates use that ship in v0.15.0. templates/README.md and the three container READMEs become signposts. The container READMEs' build, update and test sections move to a new docs/dev/CONTAINERS.md. docs/MIGRATION-GUIDE.md and docs/CONTAINER-GUIDE.md are removed; their per-repository migration notes go to PLAN's rollout section. The root README points at the manual, CONTRIBUTING's doc-update table names each chapter, and its known limit on Dependabot says bumps come on each repository's own schedule. A root SECURITY.md says to report a vulnerability privately, through the Security tab, and what is in scope. The harness gate's IGNORED treats it as documentation, root only, and its self-test checks that. PLAN: item 6 is done (#253, #258), item 10 moves to PR 5, and the rows for #232, #233, #235, #239 and #247 record their closure. Claude-Session: https://claude.ai/code/session_01WT8bMXc6EroDo2qFL1pCjS Co-authored-by: Claude Opus 5.5 <[email protected]>
Building the lectures runs code the repository does not fully control: notebook cells, packages installed at build time, and network fetches. In
templates/ci.ymlthat code ran in the same job, and the same container, as the step that hands the Netlify (or Cloudflare) token to the deploy CLI. Code that runs earlier in a job can affect the steps after it, so a compromised build dependency, on a pull request from a branch of the repository, shared a job with a long-lived deploy credential. Separately, no template setpersist-credentials: false, so the job's token stayed in git's config for the whole job. This is finding M1 of the 2026-10-06 review, as #232 describes it.This PR splits
ci.ymlinto a build job that holds no secrets and a deploy job that runs no notebook or repository code, and setspersist-credentials: falseon every checkout in the three templates.Changes
templates/ci.ymlbuild(waspreview): the container,contents: readandpackages: read, no secrets. It restores the cache and builds as before, then uploads_build/htmlas thehtmlartifact (include-hidden-files: true,if-no-files-found: error, 1 day), and then_build/.jupyter_cacheforpdf-check, as before. It carries thepdf-checkoutput.deploy(new):needs: build,ubuntu-latest, no container,contents: readandpull-requests: write, the provider secrets. Its steps are checkout (persist-credentials: false, withfetch-depth: 0as a commented option for private repositories),actions/setup-node@v7with Node 24 andpackage-manager-cache: false, the artifact download, andpreview-netlify(or the commentedpreview-cloudflare).pdf-check:needs: build, so it now runs beside the deploy rather than after it; otherwise unchanged. Header and job comments describe the split and the required-check advice (build, notpreview).templates/cache.yml,templates/publish.ymlpersist-credentials: falseon the checkout. Both run only localgit logafter it..github/workflows/test-actions.ymlpreview-site-handoffandpreview-deploy-job, beside thepdf-check-*jobs and inharness-summary'sneeds:(below). Thepdf-check-*comments say build job where they said preview job.templates/README.mdpersist-credentials: false, what a private repository needs, and the artifact's retention. "The PDF Check" saysbuildwhere it saidpreview. The diagram, Secrets table and standard-runner note follow the new shape.docs/user/actions/preview-netlify.md,preview-cloudflare.mdfetch-depth: 0for a private one. "Outside a pull request" builds on the two-job example. Troubleshooting gives the private-repository fix. No comment text changes.docs/user/actions/build-lectures.mdpdf-checkparagraph under "In the templates" says build job, and to requirebuild.CHANGELOG.md[Unreleased], Changed.No action code changes.
Design choices
The jobs are named
buildanddeploy, and no job is calledpreviewany more.pdf-checkanddeployare both skipped whenbuildfails, and GitHub counts a skipped required check as passed. If the deploy job kept the namepreview, a site that already requirespreview(as v0.14.0's template advised, alongsidepdf-check) would see both required checks skipped on a broken build, and the pull request would be mergeable with nothing to say so. With nopreviewjob, such a site's pull requests wait for a check that never reports, until the site switches the requirement tobuild. That fails loudly, and the fix is stated below.Both uploads are in
build, sodeployandpdf-checkstart together. A job can't start before every job itneedshas finished, so wherever the execution cache is uploaded, it has to be by the job that has it, which isbuild. The cost is that the preview link now waits for the.jupyter_cacheupload too, beforedeploycan start. The gain is thatpdf-checkno longer waits for the deploy. The site is uploaded first.include-hidden-files: trueon the site.upload-artifactleaves out a file whose name starts with a dot, and Sphinx writes one,_build/html/.buildinfo.netlify-cliskips dotfiles on its own, butwrangleruploads them, so without the flag a Cloudflare preview would lose files the single job used to deploy. With it, the deploy job deploys exactly what the build wrote, as before.package-manager-cache: falseonsetup-node. Since v5,setup-noderestores and saves an npm cache by itself when the repository'spackage.jsonnames npm. The deploy job needs no cache: the preview action installs its own pinned CLI from its lockfile. So it restores nothing.The deploy job has no
if:of its own. The preview action already decides whether to deploy: forks, Dependabot and the event allow-list are all inscripts/preview-decide.sh(#227). Repeating that in the job'sif:would make a second copy that could drift. The cost is about half a minute of a hosted runner on a fork's pull request: checkout, Node and the download, before the action skips with its notice.Change detection and private repositories. The deploy job checks out the repository only so the preview action can list the changed lectures. From the template's shallow checkout,
scripts/detect-changed-lectures.shfetches the base and head commits and deepens until it finds the merge base (#242). Withpersist-credentials: falsethat fetch has no credentials. A public repository serves it anonymously, and the new harness job proves that against GitHub (below). A private repository refuses it, and the action then warns and lists no lectures. The deploy still runs. So a private repository setsfetch-depth: 0on the deploy job's checkout, which then has the merge base, and the script fetches nothing (the existingpreview-change-detectionjob'sfullcase covers that path). The template's checkout comment, its Prerequisites, the README and both chapters say so.What I checked, and how
preview-site-handoffwrites a site with.buildinfoand a file in a hidden directory, and uploads it with the template's options. Its job output is a SHA-256 manifest of every path and its content.preview-deploy-jobchecks out as the template's deploy job does and downloads the artifact. It asserts that both hidden files arrived and that the manifest matches. Onpull_request, it then asserts that git has no extraheader or credential helper configured, and that the checkout is shallow. It runs the PR's ownscripts/detect-changed-lectures.shwith no token in its environment, using the manual'sdocs/as the lectures directory, since this repository has none. It asserts that the script printed no warning, that it actually fetched (refs/remotes/origin/pr-baseexists), and that itschanged-filesequals GitHub's own list of the PR's files (pulls/{n}/files) after the script's filters. This PR changes three.mdfiles underdocs/, so the comparison isn't empty here.3f97e8d, in run 41975329712, the script compareddc7f339...3f97e8dand listeddocs/user/actions/build-lectures.md,preview-cloudflare.mdandpreview-netlify.md, exactly GitHub's list. The whole harness was green. The PR was then rebased onto fix(preview-*): one shared comment script, which finds its own comment past the first 30 (#153, M2) #253 (bee12fe) with no conflicts, and its head,9b6db22, is green too, in run 41976333827.f719e8f, with two deliberate breaks, then force-pushed back to3f97e8d. The first setinclude-hidden-files: falseon the stand-in's upload. The second pointedoriginat a repository an anonymous client cannot read, which is how a private repository's fetch looks from a job with no credentials. In run 41975828097,preview-deploy-jobfailed on both:the hidden files did not arrive: the upload left them out, so the deploy would publish less than the build wrote;Could not fetch the pull request's base and head commits: fatal: could not read Username for 'https://github.com': No such device or address, from the script, thenchange detection warned (above), so it could not fetch or compare the pull request's commits without credentials. That is also what a private repository's deploy job would log withoutfetch-depth: 0.templates/ci.ymland on the manual's examples, which include two new complete workflows. So dopython scripts/generate-docs.py --checkand--check-exampleslocally: the generated docs are current, and 50quantecon/actionssteps and 14 complete workflows pass. I could not run actionlint or shellcheck locally. Downloading the actionlint binary was refused in this session, and the sandbox also refuses to create a local git repository, so I couldn't try a credential-free fetch on my machine either. The CI runs above cover both. Nothing yet shellchecks the harness's ownrun:blocks (testing: publish/preview/cache action logic has no automated tests #100's M5 comment), so the two new jobs' scripts are checked only by running.actions/setup-node@v7,actions/upload-artifact@v7andactions/download-artifact@v8, all of which.github/workflows/already pins.What a site has to change
Templates are copied, not pinned, so nothing changes for a site until it updates its copy of
ci.yml. When it does:previewcheck, the merge button stays greyed out, withpreviewshown as "Expected — Waiting for status to be reported". Under Settings → Branches (the rule formain, "Require status checks to pass") or Settings → Rules → Rulesets ("Require status checks to pass"), removepreviewand addbuild. Keeppdf-checkif it was required, and adddeployonly if a failed deploy should block a merge. Requirebuildbeside either of them, since both are skipped when it fails.fetch-depth: 0on the deploy job's checkout, or its preview comment lists no lectures.runs-ononbuildonly.deployandpdf-checkstay onubuntu-latest.jupyterandpdflatexbuilds for downloads,html-copy-*) go inbuild, before the upload.What to watch after merge
deploynow waits for both artifact uploads, then a new runner, Node and the download. Onlecture-python.myst(lecture-python.myst: HTML-only PR previews; three-format build behind a full-preview label #148 is the first adopter of the newerci.yml), compare the time from push to comment with today's, and look at thehtmlandjupyter-cacheartifact sizes. If the site upload dominates,compression-levelis the knob to try.ci.ymlon a PR before lecture-python.myst: HTML-only PR previews; three-format build behind a full-preview label #148 does, to see the comment's lecture links come from the deploy job.deploydownloads the artifact its run'sbuilduploaded, which works within the artifact's one day. After that, use "Re-run all jobs", as the README says.Not in this PR
publish-gh-pagesand the same split intemplates/publish.yml. That is this session's next PR. Herepublish.ymlonly gainspersist-credentials: false.needs:,pull-requests: writeand no checkout, since it must post beforebuildfinishes. The final comment stays with the preview action indeploy.deploypublishes whateverbuildproduced. As Keep deploy credentials out of the jobs that execute notebooks #239 says, this isolates credentials, not content.paths-ignore).Closes #232. Part of #239.
🤖 Generated with Claude Code
https://claude.ai/code/session_01WT8bMYb5kQXUExhE6SQ65R