Repository navigation
feat(preview-*): comment-key and toc-file, for several sites on one pull request (#336) - #345
Conversation
…ull request (#336) Two inputs on preview-netlify, preview-cloudflare and preview-workers, so that a repository building several sites from one folder of lectures, as QuantEcon/lectures builds its sites from its pool, can preview each site on one pull request. comment-key puts the key after both headings and into the hidden marker, <!-- quantecon-preview:<provider>:<key> -->, and the action then finds and updates only the comment with its key; the heading-only fallback, for comments from before the marker, is for the comment with no key alone. Lowercase words joined by single dashes, at most 28 characters, refused otherwise on every event. toc-file names a site's _toc.yml: a changed .md is listed only when the toc names it, in lectures-dir or in the toc's own folder, and linked at its page; the root page is left out. The placeholder and the deploy's change detection read the toc with one reader in scripts/preview-comment.cjs, which detect-changed-lectures.sh runs with node, so the two lists cannot differ. A toc that cannot be read, or names no page, is a warning, and no lectures are listed. A toc-file with a line break, a leading /, or a ., .. or empty part is refused. Both default to empty, which keeps every existing comment, marker and link: the byte-exact fixtures and change-detection cases pass unchanged. New fixtures: copies of QuantEcon/lectures' dp and jax tocs and one pull request that both harness jobs assert the same lists from. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMbYHesw3N4TiJHFiHq
…-key-toc-file Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMbYHesw3N4TiJHFiHq
There was a problem hiding this comment.
🟡 Changes recommended
A page-name delimiter collision can break change detection and skip deployment, while overlapping TOC paths can produce incorrect and duplicate preview links.
2 open issues
What changed in this PR
Adds multi-site preview support to QuantEcon’s three preview actions, allowing sites built from a shared lecture pool to keep separate pull request comments and site-specific lecture links.
Changes:
- Adds optional
comment-keyandtoc-fileinputs, preserving existing behavior when unset. - Shares toc-based page selection between placeholder comments and deployment change detection.
- Extends fixtures, harness checks, and documentation for multi-site previews and input validation.
| File | Description |
|---|---|
scripts/preview-comment.cjs |
Adds keyed comments and shared toc selection. |
scripts/detect-changed-lectures.sh |
Filters changes through the toc and outputs page paths. |
preview-workers/action.yml |
Validates and wires the new inputs for Workers. |
preview-netlify/action.yml |
Validates and wires the new inputs for Netlify. |
preview-cloudflare/action.yml |
Validates and wires the new inputs for Pages. |
docs/user/actions/preview-workers.md |
Documents Workers multi-site previews. |
docs/user/actions/preview-netlify.md |
Documents toc rules and matrix-based previews. |
docs/user/actions/preview-cloudflare.md |
Documents Pages multi-site previews. |
docs/dev/TESTING.md |
Describes the expanded preview coverage. |
CHANGELOG.md |
Records the new preview inputs. |
.github/workflows/test-actions.yml |
Adds toc-selection checks and input-wiring assertions. |
.github/fixtures/preview-toc/sites/jax/_toc.yml |
Supplies the jax site's toc fixture. |
.github/fixtures/preview-toc/sites/dp/_toc.yml |
Supplies the dp site's toc fixture. |
.github/fixtures/preview-toc/jax.tsv |
Defines expected jax file-to-page selections. |
.github/fixtures/preview-toc/dp.tsv |
Defines expected dp file-to-page selections. |
.github/fixtures/preview-toc/changes.tsv |
Supplies shared pull request changes for both harnesses. |
.github/fixtures/preview-comment/workers-keyed.md |
Defines the expected keyed Workers comment. |
.github/fixtures/preview-comment/test.cjs |
Expands rendering, lookup, toc, and validation checks. |
.github/fixtures/preview-comment/netlify-toc.md |
Defines an unkeyed toc-filtered comment. |
.github/fixtures/preview-comment/netlify-pending-keyed.md |
Defines a keyed placeholder without lecture links. |
.github/fixtures/preview-comment/netlify-pending-keyed-toc.md |
Defines a keyed, toc-filtered Netlify placeholder. |
.github/fixtures/preview-comment/netlify-keyed-toc.md |
Defines a keyed, toc-filtered Netlify deployment comment. |
.github/fixtures/preview-comment/cloudflare-pending-keyed-toc.md |
Defines a keyed, toc-filtered Pages placeholder. |
.github/fixtures/preview-comment/cloudflare-keyed.md |
Defines the expected keyed Pages deployment comment. |
Review effort: Balanced (adaptive)
| { | ||
| echo "changed-pages<<EOF" | ||
| echo "$changed_pages" | ||
| echo "EOF" | ||
| } >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
Fixed in e568936. The script writes its outputs through a small helper, which keeps the EOF delimiter unless EOF is one of the value's lines, and then takes EOF_<random>. So every output that could be written before is byte-identical, and a page called EOF no longer ends changed-pages early. changed-files could not collide, since each of its lines ends in .md, but it goes through the same helper. The toc step in preview-change-detection now reads GITHUB_OUTPUT as the runner does, failing on a malformed line or an unterminated block, and has a case for a toc page called EOF. That case fails on the commit before the fix, with both the malformed output and the missing page, and passes on this one.
Claude Code (on behalf of mmcky)
| } | ||
| const named = new Set(pages); | ||
| const tocDir = path.posix.dirname(tocFile); | ||
| const prefixes = [`${lecturesDir}/`, tocDir === '.' ? '' : `${tocDir}/`]; |
There was a problem hiding this comment.
Fixed in e568936, a little differently from the suggestion. Trying the toc-relative path first and then falling back to lectures-dir would still read lectures/a.md as the page a when a root toc lists only a, because the fallback matches. So a file inside the toc's own folder is now the page at its path there, and only a file outside that folder is read from lectures-dir. For a toc at the root, a.md is a and lectures/a.md is lectures/a, with no duplicate. For QuantEcon/lectures' tocs in sites/<key>/, and for a toc in lectures-dir, the lists are unchanged: the shared dp.tsv and jax.tsv cases pass as before. Two cases are new in test.cjs: your example, and a root toc naming only a with lectures/a.md changed. Both failed before the change. The chapter's Behaviour section states the rule.
Claude Code (on behalf of mmcky)
…'s list (#336) From Copilot's review of #345. detect-changed-lectures.sh wrote changed-pages as a heredoc ended by EOF, so a toc page called EOF ended the block early and failed the step. Its outputs now keep EOF unless EOF is a line of the value, and take another delimiter then; every output that could be written before is byte-identical. The harness reads GITHUB_OUTPUT as the runner does, and a page called EOF is a case. tocSelect tried lectures-dir before the toc's folder, so a toc at the repository root read lectures/a.md as the page a. A file in the toc's own folder is now the page at its path there, and only a file outside it is read from lectures-dir. QuantEcon/lectures' tocs, in sites/<key>/, and a toc in lectures-dir list as before; two root-toc cases are new. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMbYHesw3N4TiJHFiHq
…guarantees (#336) From the merge session's review of #345. The toc-file description said the toc is read at the pull request's head; the deploy reads it from the checkout, by default GitHub's merge commit, and only the placeholder reads the head. The scripts' comments said the deploy's and the placeholder's lists cannot differ; they read a toc alike, but their file lists can differ where git quotes a non-ASCII path and the API does not. The chapter's toc rules say the reader takes quotes, a .md and a trailing comment off, not that the toc must lack them, and one input-check case's name no longer claims a root toc it does not test. Wording, generated docs and a test name only. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMbYHesw3N4TiJHFiHq
CHANGELOG: #345's `### Added` first, then this pull request's `### Changed`, under [Unreleased]; the released sections are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMZz3f9g9nSCqCaQjHg
Cuts v0.22.0, a minor release: #357 and #345 add features, and nothing in it is marked⚠️ BREAKING. It carries #357's `deploy-release` reusable workflow, #345's `comment-key` and `toc-file`, and #346's images, whose CHANGELOG entries are already under `[Unreleased]`, and Dependabot's #348, #352 and #347, whose entries this PR writes. `v0` is on v0.21.1, and moves to v0.22.0 only after the release gate and the staging below have passed it. ## What's in it | Change | PR | |---|---| | `deploy-release`, the first reusable workflow for lecture repositories, and its caller, `templates/deploy-release.yml`: on a release published for a `publish-*` tag it deploys that release's site to GitHub Pages, and on a dispatch with a tag it deploys that tag's release, which is the rollback. Its `### Added` entry is already under `[Unreleased]` | #357 | | `comment-key` and `toc-file` in `preview-netlify`, `preview-cloudflare` and `preview-workers`, for several sites on one pull request. Both are empty by default, which leaves the comment, its marker and its links as they were. Its `### Added` entry is already under `[Unreleased]` | #345 | | Chrome for Testing 158 in both images, and kaleido 1.5.2. Its `### Changed` entry is already under `[Unreleased]`. `:latest` has carried it since 2026-11-19, so this release only records it | #346 | | wrangler 4.166.0 in `preview-cloudflare`, `preview-workers` and `deploy-cloudflare`, up from 4.162.0; netlify-cli 27.20.1 in `preview-netlify`, up from 27.19.0. Neither raises its minimum Node, which stays at 22.12 for wrangler and 22.13 for netlify-cli. One entry for both | #348, #352 | | Both images on the `ubuntu:24.04` image of 2026-11-10, pinned by digest. `:latest` has carried it since 2026-11-20, so this release only records it | #347 | Also merged since v0.21.1, with no entry of its own: #344 (PLAN), #350 (CI and docs: the canary watcher reads the canary's scheduled `ci.yml` and `publish.yml` runs) and #351 (PyYAML 6.0.4 in `scripts/requirements.txt`, CI only). ## Changes in this PR | File | Change | |---|---| | `CHANGELOG.md` | `## [0.22.0] - 2026-11-28` below an empty `## [Unreleased]`. Under `### Changed`, the entry for #348 and #352 first; then #346's, with one line added (both images rebuilt and smoke-tested, and `:latest` moved on 2026-11-19, before this release); then #347's. `### Added` keeps #357's and #345's entries as they were | | `docs/dev/PLAN.md` | The release line: the latest release is v0.22.0, and `@v0` is on v0.21.1 until the gate has passed it. The line counting the actions names the reusable workflow, `deploy-release`. The rows for `lecture-jax`, `lecture-python-intro`, `lecture-python-advanced.myst`, `lecture-python-programming`, `lecture-python-programming.fr` and `continuous_time_mcs` are on `@v0`, where PLAN said `@v0.12.0`, and the paragraph on their exact pins goes with them. QuantEcon/lectures' row names `setup-environment` too, which its `site-build.yml` runs on its full-image legs, `intro` and `advanced`, and counts the six sites it builds now. Two rollout lines that still named exact pins say `@v0`: `publish-gh-pages`' 8/8, and `lecture-jax`'s previews | The date is today's in UTC. ## What I checked - **The CHANGELOG:** the diff adds 12 lines and deletes none, and everything from `## [0.21.1]` down is byte-identical to `main`. Every PR merged since v0.21.1 has its entry, or is listed above. The lockfiles on `main` pin wrangler 4.166.0 (engines `>=22.12.0`) in all three Cloudflare actions and netlify-cli 27.20.1 (`>=22.13.0`). - **The consumers,** read today from each repository's default-branch workflows: `lecture-jax` and `lecture-python-programming.fr` call `preview-netlify@v0` (`ci.yml`) and `publish-gh-pages@v0` (`publish.yml`); `lecture-python-intro`, `lecture-python-advanced.myst`, `lecture-python-programming` and `continuous_time_mcs` call `publish-gh-pages@v0` (`publish.yml`). No other workflow in them names this repository. QuantEcon/lectures' `site-build.yml` runs `setup-environment@v0` on the legs whose `site.yml` gives a container runner and `environment: base`, which are `intro` and `advanced`, and `build-lectures@v0` on every leg. - **The build actions,** `setup-environment`, `setup-latex`, `build-lectures`, `build-jupyter-cache`, `restore-jupyter-cache`, `publish-gh-pages` and `restore-gh-pages`, are byte-identical to v0.21.1 at `19fdc20`, and none calls a script that has changed since. `deploy-cloudflare` changes only in its `package.json` and `package-lock.json` (#348, #352). - **`generate-docs.py --check --check-examples --actionlint`:** 24 files current; 75 `quantecon/actions` steps and 20 complete workflows checked, clean under actionlint 1.7.12. `actionlint` finds `.github/workflows/` clean, and `scripts/lint-shell.py`, with shellcheck 0.11.0, finds 74 `run:` scripts in 11 `action.yml` files, 216 in 9 workflows, and 16 `scripts/*.sh` clean. - **The harness skips this PR's files,** since the gate's `IGNORED` covers `CHANGELOG.md` and `docs/`. The evidence is `main`'s full harness at `19fdc20`, #351's merge commit, which comes after #352's lockfile changes: dispatched run https://github.com/QuantEcon/actions/actions/runs/46131794415, green on its first attempt, with 70 jobs passed and 5 skipped. ## Staging, after the tag As CONTRIBUTING's Staged Releases says, apart from the departures in steps 3 and 5: 1. **The release gate:** `gate.yml` on the canary's `main`, with `candidate=v0.22.0` and the self-test off, outside Sunday 00:00 to 03:00 UTC. It must be green, with each site serving the marker for the release commit, and its log must show both preview deploys running the new CLIs, wrangler 4.166.0 and netlify-cli 27.20.1. The run is linked here. 2. **A canary PR for #345's pull-request half,** which the gate doesn't reach: a branch `staged-v0.22.0` in the canary with every `quantecon/actions/...` step pinned `@v0.22.0`, inputs as `templates/` has them (no `comment-key`, no `toc-file`), and a one-line change to one lecture. Checked by hand: each provider's placeholder comment lists the changed lecture, and its deploy then replaces that same comment, with its marker as before; each `pr-<N>` preview serves the build's marker and the changed lecture, by content; a second push updates the same two comments. The PR is closed unmerged with a results note, and linked here. 3. **`deploy-release` on the canary,** which the gate doesn't reach and the harness checks only as a file: a caller on the canary's `main`, `templates/deploy-release.yml` with its `uses:` pinned `@v0.22.0`, merged on review; a release made by the canary's `publish.yml` on a new `publish-*` tag, which starts no `deploy-release` run; then a dispatch with `tag=publish-check-310`, the rollback path, and that new release published again, the release path. Each is checked by its upload job's `commit` and by the site serving, by content, a file whose bytes differ between the two releases. This departs from CONTRIBUTING, which stages on a canary branch: GitHub dispatches only a workflow that is on the default branch, and the canary's `github-pages` environment admits only `main` and `publish*` tags. The post-move PR updates CONTRIBUTING to match. The runs are linked here. 4. **No lecture matrix at the candidate:** the build actions are unchanged, and #346's and #347's images are already `:latest`. Monday's scheduled run 45098004558, on `main` at `06b493f` with `:latest` of 2026-11-20, ran this build path green on all 8 legs. 5. **Nothing staged by hand for `deploy-cloudflare` and `preview-workers`,** which the gate doesn't reach. Neither has an `@v0` consumer: the two `deploy-cloudflare` callers pin `v0.12.0`, and `preview-workers` has none yet (#299). The harness installs the pinned wrangler for both and runs it ("pinned CLIs install from their lockfiles and run", each action's "the pinned wrangler accepts the generated config", and `deploy-cloudflare` on Node 22.11 and 22.12), and covers #345's keyed and toc paths in its fixtures, all green in the run above. 6. **Once `v0` has moved,** which is asked for on its own: the canary's `cache.yml`, then `ci.yml`, on its `main`; its `deploy-release` caller moved to `@v0` and dispatched once more; then its `publish.yml`, so the site ends on a marked build; then a post-move PR here for PLAN's `v0` line, the canary drift check's workflow list, and TESTING's and CONTRIBUTING's lines on the reusable workflow. The move reaches the `@v0` callers of `preview-netlify` on default inputs, and QuantEcon/lectures' site build, whose `setup-environment` and `build-lectures` this release doesn't change. The runs are linked here. Copilot: not requested (Matt, 2026-11-22). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01WT8bMYECPyC5K5RvEg6uiq

Closes #336
Two inputs on
preview-netlify,preview-cloudflareandpreview-workers,comment-keyandtoc-file, so that a repository that builds several sites from one folder of lectures can preview each site on one pull request. QuantEcon/lectures builds its sites from its pool this way (QuantEcon/project-monorepo#77), and itssite-build.ymllists posting a preview, with this issue, among what it doesn't do yet. Both inputs are empty by default, and then every existing caller gets the comment, marker and links it gets today. Built to the decisions and design agreed on #336 (the comment).Why. Two of the scripts the three actions share stood in the way.
scripts/preview-comment.cjsfinds its comment by one marker per provider, so a second site's preview on the same provider replaced the first's comment.scripts/detect-changed-lectures.shlists every changed.mdunderlectures-dir, so each site's comment would list every changed pool lecture, mostly links to pages that site doesn't build, and never a change to a site's own page insites/<key>/.Changes
scripts/preview-comment.cjscomment-keyreaches the marker,<!-- quantecon-preview:<provider>:<key> -->, and both headings, which end(<key>). A keyed run finds only comments that start with its own marker, compared whole, sodpnever takesdp-2's. The heading-only fallback, for comments from before the marker existed, is for unkeyed runs alone. A key the input check would refuse throws, as an unknownPROVIDERdoes. The toc reader is new:readTocreads thefile:entries one to a line, leaving out theroot:page, and dropping quotes, a.mdand a trailing comment.tocSelectmatches the changed files to the toc's pages, inlectures-diror in the toc's own folder. The placeholder reads the toc at the head throughgetContent. Anode preview-comment.cjs toc-selectentry lets the deploy's change detection use the same readerscripts/detect-changed-lectures.shTOC_FILE, it gathers the added and modified.mdfiles and lets the shared reader choose, run withnode. Node is on the PATH wherever a deploy can run, since each action installs its CLI withnpm. It writes a new internal output,changed-pages, besidechanged-files. A toc that can't be read, or that names no page, and a failingnode, each give a warning and list nothing, as a git failure does. WithoutTOC_FILE, nothing changespreview-netlify/action.yml,preview-cloudflare/action.yml,preview-workers/action.ymltoc-fileandcomment-key. The first step refuses both on every event: throughsingle_line, and for a key that isn't lowercase words joined by single dashes, at most 28 characters, or atoc-filethat starts with/or has a.,..or empty part. It warns whentoc-fileis set withlectures-dir: ''. The new env goes to the detect and comment steps, and thechanged-filesdescription coverstoc-filedocs/user/actions/preview-*.mdglob:,url:, one-line forms, commented lines), and that a lecture added to the toc but not edited gets no link. What fails the job lists the two inputs' refusals, and Permissions the toc read.github/fixtures/preview-toc/(new)sites/dp/_toc.ymlandsites/jax/_toc.ymlat868773d: dp has a trailing# site additioncomment, and jax a commented-out# - file:line. Also one pull request's files (changes.tsv), and what each toc must list from them (dp.tsv,jax.tsv).github/fixtures/preview-comment/test.cjs, 7 new*.mddp,dp-2,d); placeholder and deploy handing over per key; each site's list against<site>.tsv; a toc not at the head, a failinggetContentand a root-only toc; the reader's own forms; and each action's input check for every refused form. The new env is pinned inWIRING, the detect step's included. The existing*.mdfixtures and the literalMARKERtable are not edited.github/workflows/test-actions.ymlpreview-change-detectiongets a second step. It builds the pull request fromchanges.tsvas two commits, and assertsdp.tsvandjax.tsvfrom the deploy's script: file and page, the same lists the placeholder must give. It also checks a toc not in the checkout, a failingnode, the same pull request with notoc-file, listed by today's rules, and a page calledEOF, which reaches the outputs whole.preview-comment's step reader also reads the detect step's env. No new job, soharness-summaryis unchangeddocs/dev/TESTING.mdpreview-*row and the fixture listCHANGELOG.md### Addedunder[Unreleased]. NotOne addition to the decision. #336's decision refuses a
toc-filewith a line break, an absolute path or... This PR also refuses a.part (./sites/dp/_toc.yml) and an empty one (sites//dp,sites/dp/). The checkout would accept those paths, but the placeholder's API read and the folder match wouldn't, so the two halves could disagree. Dropping the two refusals changes one regex in each action.What I checked, and how
The issue. It was checked against
mainbefore any code: facts, callers, and mystmd's slug rule, read from themyst-cli1.13.0 source. The comment on #336 records the check and the decisions.The new checks fail on today's code. A throwaway workflow on
scratch/336-red, frommainatf2a0333, ran the newpreview-commentharness and the new toc step againstmain's actions and scripts (run 44504646705). Both jobs were red:preview-comment: 90 of the 99 new cases failed. The other 9 passed: they are valid inputs, whichmainaccepts by ignoring them. All 91 existing cases passed too. The refusals failed becausemainaccepts a bad key and a badtoc-file("comment-key [DP]: exited 0, not 1"). Every keyed and toc render failed, becausemain's comment step doesn't pass the inputs. The reader cases failed, becausemainhas no reader.sites/dp/_toc.yml,main's script listed six pool lectures, two of them neither site's, but notsites/dp/status.md, against dp's expected four. For jax it listed the same six, the missing-toc and failing-nodecases gave no warning, and each listed lectures.The branch is deleted. This PR's run shows both green. Two root-toc cases and the
EOFcase came after that run, from Copilot's review, and each fails on the commit before its fix.Unchanged for existing callers. All 91 cases that ran before this PR pass unchanged. That includes the byte-exact comment fixtures from v0.14.0 and
preview-workers' own, rendered with the new inputs unset, andpreview-wiring's step with an existing caller's inputs. All ofpreview-change-detection's original cases pass too, against the changed script. Callers:@v0), and QuantEcon/iuj_feb_2026 (@main), set neither input.v0.12.0.Locally:
test.cjspasses all 192 cases, against both halves.preview-change-detectionpass, run from the workflow's own text.python3 scripts/generate-docs.py --check --check-examples --actionlint …,actionlintandpython3 scripts/lint-shell.py.main,CHANGELOG.mdgains one entry and loses no line.main(docs(plan): v0 is on v0.21.1 #344) is merged in.What to watch after merge
preview-netlify@main, so it gets this at merge, not at release. It sets neither input, so its comment is unchanged. The repository was last pushed on 2026-08-05.ci.ymlat@vX.Y.Z:As is, the Netlify and Cloudflare comments should be exactly the last release's: the same markers, headings and links.
On that branch only, add a keyed
preview-netlifyplaceholder and deploy beside the unkeyed ones, withcomment-key: secondandtoc-file: sites/second/_toc.yml. Addsites/second/_toc.yml, the canary's toc less one lecture, andsites/second/extra.md. Edit one lecture both tocs name, and the one the second omits.## 📖 Netlify Preview Ready! (second), lists the shared lecture andextra, with no folder in either link.The keyed deploy goes to the same site and alias, so it redeploys the same build, and
extra's link is a 404. That is expected: only the comment is under test. No new secret or project is needed.Not in this PR
link-stylewaits for build-lectures: anengineinput,jb1ormyst#337 and a mystmd site that needs a preview, so that its rule can be checked against a real build. mystmd's page addresses aren't file names (mccall_model.mdis served at/mccall-model/).glob:andurl:entries and YAML's one-line forms are not read, and the chapters say so.scripts/preview-decide.sh.🤖 Generated with Claude Code
https://claude.ai/code/session_01WT8bMbYHesw3N4TiJHFiHq