Skip to content

feat(templates): deploy the pull request preview from a job that runs no notebook code (#232) - #254

Merged
mmcky merged 1 commit into
mainfrom
feat/232-preview-deploy-job
Nov 5, 2026
Merged

mmcky merged 1 commit into
mainfrom
feat/232-preview-deploy-job

Conversation

@mmcky

@mmcky mmcky commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Building the lectures runs code the repository does not fully control: notebook cells, packages installed at build time, and network fetches. In templates/ci.yml that 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 set persist-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.yml into a build job that holds no secrets and a deploy job that runs no notebook or repository code, and sets persist-credentials: false on every checkout in the three templates.

Changes

File Change
templates/ci.yml Three jobs. build (was preview): the container, contents: read and packages: read, no secrets. It restores the cache and builds as before, then uploads _build/html as the html artifact (include-hidden-files: true, if-no-files-found: error, 1 day), and then _build/.jupyter_cache for pdf-check, as before. It carries the pdf-check output. deploy (new): needs: build, ubuntu-latest, no container, contents: read and pull-requests: write, the provider secrets. Its steps are checkout (persist-credentials: false, with fetch-depth: 0 as a commented option for private repositories), actions/setup-node@v7 with Node 24 and package-manager-cache: false, the artifact download, and preview-netlify (or the commented preview-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, not preview).
templates/cache.yml, templates/publish.yml persist-credentials: false on the checkout. Both run only local git log after it.
.github/workflows/test-actions.yml Two new jobs, preview-site-handoff and preview-deploy-job, beside the pdf-check-* jobs and in harness-summary's needs: (below). The pdf-check-* comments say build job where they said preview job.
templates/README.md The ci.yml section gains a table of the three jobs and what each holds. New section, "Why the Preview Deploys From Its Own Job": the reason, persist-credentials: false, what a private repository needs, and the artifact's retention. "The PDF Check" says build where it said preview. The diagram, Secrets table and standard-runner note follow the new shape.
docs/user/actions/preview-netlify.md, preview-cloudflare.md "When to use it" and the main example show the two-job shape, which replaces the one-job "Minimal" example: "A build job and a deploy job". Requirements say what the change-detection fetch needs: nothing for a public repository, and fetch-depth: 0 for 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.md The pdf-check paragraph under "In the templates" says build job, and to require build.
CHANGELOG.md One entry under [Unreleased], Changed.

No action code changes.

Design choices

The jobs are named build and deploy, and no job is called preview any more. pdf-check and deploy are both skipped when build fails, and GitHub counts a skipped required check as passed. If the deploy job kept the name preview, a site that already requires preview (as v0.14.0's template advised, alongside pdf-check) would see both required checks skipped on a broken build, and the pull request would be mergeable with nothing to say so. With no preview job, such a site's pull requests wait for a check that never reports, until the site switches the requirement to build. That fails loudly, and the fix is stated below.

Both uploads are in build, so deploy and pdf-check start together. A job can't start before every job it needs has finished, so wherever the execution cache is uploaded, it has to be by the job that has it, which is build. The cost is that the preview link now waits for the .jupyter_cache upload too, before deploy can start. The gain is that pdf-check no longer waits for the deploy. The site is uploaded first.

include-hidden-files: true on the site. upload-artifact leaves out a file whose name starts with a dot, and Sphinx writes one, _build/html/.buildinfo. netlify-cli skips dotfiles on its own, but wrangler uploads 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: false on setup-node. Since v5, setup-node restores and saves an npm cache by itself when the repository's package.json names 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 in scripts/preview-decide.sh (#227). Repeating that in the job's if: 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.sh fetches the base and head commits and deepens until it finds the merge base (#242). With persist-credentials: false that 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 sets fetch-depth: 0 on the deploy job's checkout, which then has the merge base, and the script fetches nothing (the existing preview-change-detection job's full case covers that path). The template's checkout comment, its Prerequisites, the README and both chapters say so.

What I checked, and how

  • The new harness jobs run the template's hand-off on this PR:
    • preview-site-handoff writes a site with .buildinfo and 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-job checks out as the template's deploy job does and downloads the artifact. It asserts that both hidden files arrived and that the manifest matches. On pull_request, it then asserts that git has no extraheader or credential helper configured, and that the checkout is shallow. It runs the PR's own scripts/detect-changed-lectures.sh with no token in its environment, using the manual's docs/ 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-base exists), and that its changed-files equals GitHub's own list of the PR's files (pulls/{n}/files) after the script's filters. This PR changes three .md files under docs/, so the comparison isn't empty here.
    • On 3f97e8d, in run 41975329712, the script compared dc7f339...3f97e8d and listed docs/user/actions/build-lectures.md, preview-cloudflare.md and preview-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.
  • That each new test can fail. I pushed a temporary commit, f719e8f, with two deliberate breaks, then force-pushed back to 3f97e8d. The first set include-hidden-files: false on the stand-in's upload. The second pointed origin at 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-job failed 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, then change 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 without fetch-depth: 0.
  • The gate's actionlint and shellcheck pass on the new templates/ci.yml and on the manual's examples, which include two new complete workflows. So do python scripts/generate-docs.py --check and --check-examples locally: the generated docs are current, and 50 quantecon/actions steps 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 own run: 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.
  • The pin check. The new steps use actions/setup-node@v7, actions/upload-artifact@v7 and actions/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:

  • Required status checks. If branch protection or a ruleset requires the old preview check, the merge button stays greyed out, with preview shown as "Expected — Waiting for status to be reported". Under Settings → Branches (the rule for main, "Require status checks to pass") or Settings → Rules → Rulesets ("Require status checks to pass"), remove preview and add build. Keep pdf-check if it was required, and add deploy only if a failed deploy should block a merge. Require build beside either of them, since both are skipped when it fails.
  • A private repository uncomments fetch-depth: 0 on the deploy job's checkout, or its preview comment lists no lectures.
  • A GPU site changes runs-on on build only. deploy and pdf-check stay on ubuntu-latest.
  • Extra build steps (the jupyter and pdflatex builds for downloads, html-copy-*) go in build, before the upload.
  • The secrets stay the same, under the same names.

What to watch after merge

Not in this PR

Closes #232. Part of #239.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WT8bMYb5kQXUExhE6SQ65R

Copilot AI balanced review requested due to automatic review settings November 5, 2026 05:34
@mmcky
mmcky force-pushed the feat/232-preview-deploy-job branch 2 times, most recently from 2fcbbab to 3f97e8d Compare November 5, 2026 05:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.yml into build (no secrets), deploy (secrets + deploy from downloaded artifact), and pdf-check (runs alongside deploy; consumes build outputs).
  • Set persist-credentials: false on 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

@mmcky

mmcky commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Copilot's review (on 6708030) opened no inline threads, but its summary table flags three notes. Taking each:

  1. The jupyter-cache upload has no if-no-files-found. That step comes from feat(templates): a pdf-check job in ci.yml that each site can switch off (#230) #241. This PR moves it from the old preview job into build without changing it. Setting if-no-files-found: error would fail build on a site whose build left no execution cache. A failed build skips deploy, so the site would lose its preview over the PDF check. I've left it at the default, warn. pdf-check then fails at its download step, with an error that names the jupyter-cache artifact. No change.
  2. Path drift in the manual's examples: the upload takes steps.build.outputs.build-path, while the deploy job uses _build/html. The two paths are independent. An artifact holds the files under the path it was uploaded from, and download-artifact writes them under whatever path the downloading job gives. A custom output-dir in the build job changes only where the upload reads from. In the deploy job, _build/html is both the download's path and the preview action's build-dir, and those two stay in step. No change.
  3. "Broken quoting" in echo "manifest=$(sha256sum <<< "$manifest" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT". In bash, quotes inside $( … ) open a new quoting context, so this is one well-formed word. In run 41975329712, preview-site-handoff set the output and preview-deploy-job matched it. No change.

Claude Code (on behalf of mmcky)

@mmcky
mmcky force-pushed the feat/232-preview-deploy-job branch from f719e8f to 3f97e8d Compare November 5, 2026 05:45
… 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
@mmcky
mmcky force-pushed the feat/232-preview-deploy-job branch from 3f97e8d to 9b6db22 Compare November 5, 2026 05:48
@mmcky
mmcky merged commit cf791ae into main Nov 5, 2026
46 checks passed
@mmcky
mmcky deleted the feat/232-preview-deploy-job branch November 5, 2026 05:57
mmcky added a commit that referenced this pull request Nov 5, 2026
…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]>
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.

templates: deploy pull request previews from a job that runs no notebook code, and stop persisting checkout credentials

2 participants