Repository navigation
feat(restore-gh-pages): restore a GitHub Pages site from a release (#27) - #306
Conversation
A new action, restore-gh-pages, and a template, templates/restore.yml, that put a site back as one of the repository's releases holds it, without a build. The action reads the archive, checksum and manifest that publish-gh-pages attaches on a tag: it downloads the archive and checksum with gh, checks the archive's SHA-256 before anything is extracted, refuses an archive holding anything but files and directories, and gives the extracted site as build-dir and the manifest's commit as commit. The template, run by hand on the default branch with the release's tag, hands the site to publish-gh-pages to deploy, in publish.yml's pages concurrency group. The harness restores releases packed by publish-gh-pages' own packing script, served by a stand-in gh, and refuses each bad input, release, checksum and archive with no site left behind. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMZoMxRqb5P73bRTeCY
…, and shellcheck the stand-in gh A release with no archive for the tag no longer suggests asset-name, which cannot help; two or more still does. The symlink refusal no longer reads "holds 1 entries". The stand-in gh passes shellcheck at style severity. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMZoMxRqb5P73bRTeCY
…one line Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WT8bMZoMxRqb5P73bRTeCY
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.
🟡 Changes recommended
A critical security concern remains because the tar extraction safety check can be bypassed via hard-link entries that appear as regular files, potentially allowing publication of linked content outside the restored tree.
1 open issue
What changed in this PR
Introduces a new restore-gh-pages composite action and restore.yml workflow template to restore a GitHub Pages site directly from release assets (archive + checksum + optional manifest), avoiding rebuilds while reusing the existing publish-gh-pages deployment path.
Changes:
- Add
restore-gh-pagesaction to validate inputs, download release assets viagh, verify SHA-256 checksums, safely extract, and expose the restoredbuild-dir(and optional commit). - Add
templates/restore.ymlworkflow for manual restore+deploy with appropriate permissions and shared Pages concurrency. - Extend CI harness/fixtures and update user/dev docs plus changelog to document and test the new restore flow.
| File | Description |
|---|---|
| templates/restore.yml | Adds a workflow_dispatch template that restores a site from a release tag and deploys it via publish-gh-pages using the Pages concurrency group and required permissions. |
| templates/README.md | Updates the templates index to include restore.yml and describe its purpose alongside existing templates. |
| scripts/generate-docs.py | Registers restore-gh-pages in the documentation generation ordering so it appears in the intended sequence. |
| restore-gh-pages/README.md | Adds a generated README that points users to the full user manual documentation for the new action. |
| restore-gh-pages/action.yml | Introduces the composite action that validates inputs, discovers/downloads release assets, verifies checksums, extracts safely, and outputs the restored build directory (and commit when available). |
| docs/user/security.md | Documents the permissions model and security considerations for running restore.yml (contents read plus Pages/id-token write for deployment). |
| docs/user/README.md | Updates the generated user documentation index to include the new restore-gh-pages action. |
| docs/user/getting-started.md | Adds restore.yml to the getting-started guidance and tables describing where/how workflows run and when to use them. |
| docs/user/actions/restore-gh-pages.md | Adds a new user manual chapter describing restore-gh-pages usage, inputs/outputs, behavior, and troubleshooting messages. |
| docs/user/actions/publish-gh-pages.md | Adds a cross-reference noting that restore-gh-pages consumes the release assets produced by publish-gh-pages. |
| docs/dev/TESTING.md | Documents the new restore-focused harness coverage and the release-stub fixture used to test gh interactions deterministically. |
| docs/dev/PLAN.md | Updates the dev plan to include restore-gh-pages and reflect completion of the related work item. |
| docs/dev/ARCHITECTURE.md | Updates architecture documentation to include the new action and restore.yml template in the overall system description. |
| CHANGELOG.md | Adds an Unreleased changelog entry describing the addition of the new restore action and workflow template. |
| .github/workflows/test-actions.yml | Extends the CI workflow with restore round-trip and refusal test jobs and wires them into the harness summary and input-validation coverage. |
| .github/fixtures/release-stub/gh | Adds a stub gh script fixture to emulate gh release view/download for repeatable CI testing of the restore action. |
Review effort: Balanced
| find "$SITE" ! -type f ! -type d -print0 > "$DIR/other" | ||
| if [ -s "$DIR/other" ]; then | ||
| echo "Neither files nor directories:" | ||
| N=0 | ||
| while IFS= read -r -d '' path; do | ||
| N=$((N + 1)) | ||
| if [ "$N" -le 20 ]; then | ||
| printf ' %q\n' "${path#"$SITE"/}" | ||
| fi | ||
| done < "$DIR/other" | ||
| rm -rf "$SITE" | ||
| annotate error "$ARCHIVE holds something other than files and directories, such as a symlink ($N in all, listed above). publish-gh-pages makes no such archive, so it was not restored" | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
No change needed: a hard link here can only point at a file the archive itself put in the site. The archive is extracted into a fresh, empty directory, and tar confines hard-link targets to it by default. GNU tar, on the hosted runners, strips a leading / and any ../ components from a hard-link target. A test with bsdtar, building archives with Python's tarfile:
- target
/…/outside/secret.txt(absolute): re-rooted inside the extraction directory, "Hard-link target … does not exist", tar exits 1; - target
../outside/secret.txt: "Path contains '..'", refused, tar exits 1.
Either way the step fails before build-dir is set. A link through a symlink is covered too: GNU tar holds symlinks to an absolute or .. path back until the end of extraction, bsdtar won't extract through a symlink, and the check after extraction refuses any symlink left in the tree. A hard link between two of the archive's own files extracts as two copies of one file, which is harmless, and upload-pages-artifact dereferences hard links anyway.
Claude Code (on behalf of mmcky)
#309) restore-round-trip (#306) uploaded the restored site with publish-gh-pages' mode: upload and downloaded the github-pages artifact back by name. So does publish-modes, in the same run, so each download could return the other job's artifact. On main (run 42911209128) restore-round-trip read publish-modes' artifact and failed; publish-modes passes on either, since both hold ./index.html, so its check could be met by the wrong upload. restore-round-trip now only restores: diff -r already shows each restore gives back the exact site. publish-modes keeps the run's only github-pages artifact. The hand-off templates/restore.yml makes to publish-gh-pages is tested in the canary, at the next release. Claude-Session: https://claude.ai/code/session_01WT8bMbZoC2dpGt3sPyBjyd Co-authored-by: Claude Opus 5.5 <[email protected]>

A broken or vanished lecture site is today rebuilt from source, which for
lecture-python.mystmeans a GPU build, and a rebuild with today's packages may not give back the same site. Yet eight lecture repositories already attach the exact site to everypublish*release, throughpublish-gh-pages'create-release-assets, and nothing reads those archives. This PR adds the consumer #27 asked for:restore-gh-pagesandtemplates/restore.yml, which put the site back as a release holds it, without a build.It follows the check agreed on #27 (the maintainer took all seven recommendations on 2026-11-10). The action downloads and verifies the release and extracts the site.
publish-gh-pages, the next step, deploys it as it deploys a build, so the restore pins no third-party action and the release gate keeps testing the deploy path on every release. A Pages site with a GitHub Actions source can only be deployed from a workflow in its own repository, so each lecture repository runs the restore from the template, by hand.How it works
tag, required: letters, digits,.,_,-, starting with a letter or digit.asset-name, optional: empty finds the release's one*-<tag>.tar.gz, since 4 of the 8 producers use a name other than<repository>-htmlbuild-dir, the extracted site, set only once every check has passed;commit, from the manifest, empty without onecontents: readscripts/workflow-command.sh, a line break included (#267)publish-gh-pageswrites, naming this archive, andsha256sum --check --strictmust passupload-pages-artifactpacks with--dereference, and would publish what a link points at on the runner. GNU tar already refuses..publish-gh-pages' format. The hand-rolledhtml-checksum.txtis not read: all four repositories that hand-roll it deploy from agh-pagesbranch, which this cannot restoreworkflow_dispatchwith a requiredtag,publish.yml'spagesconcurrency group, one job onubuntu-latestwith no container,contents: read,pages: write,id-token: write,environment: github-pages. It runs no repository or notebook code, so one job is enough. The next publish replaces the restored siteChanges
restore-gh-pages/action.yml(new)gh, verify, extract and check the tree, report. Each call works in its ownmktemp -dunder$RUNNER_TEMP. Every value reaches a script throughenv:, and every message that prints one goes throughannotate. The manifest is printed throughjq, never as it is, and a name in the archive is printed escapedtemplates/restore.yml(new)publish.yml'srelease-assetsjob, and a Pages source of GitHub Actionsdocs/user/actions/restore-gh-pages.md(new),restore-gh-pages/README.md(new, generated).github/workflows/test-actions.ymlrestore-round-trip,restore-refuses, arestore-gh-pages: tagcase ininputs-line-break, and both jobs inharness-summary'sneeds:, besidepublish-*. The gate finds the action from itsuses: ./restore-gh-pageslines.github/fixtures/release-stub/gh(new)ghcalls the action makes, serving releases from a directory. A call it does not expect, or one withoutGH_TOKEN, is recorded, and both jobs fail on itscripts/generate-docs.pyrestore-gh-pagesinORDER, afterpublish-gh-pagesdocs/user/README.mddocs/user/actions/publish-gh-pages.mdrestore-gh-pages, as agreed with the organiser. Nothing else inpublish-gh-pages/changesdocs/user/getting-started.md,docs/user/security.mdrestore.yml, as agreedtemplates/README.mdrestore.ymldocs/dev/ARCHITECTURE.mdrestore.ymlamong the templatesdocs/dev/TESTING.mdrestore-gh-pagesrow, and the fixturedocs/dev/PLAN.mdrestore-gh-pagesin the list of actions, and #27 out of "New actions and decisions"CHANGELOG.md[Unreleased],### Added. NotWhat I checked, and how
The issue check (written up for the organiser and agreed on #27) found, against
mainatf627321:create-release-assets: 'true', two at@v0and six at@v0.12.0. Each one's last four releases carry the triple, and every one of their Pages sites has a GitHub Actions source (gh api …/pages:build_type: workflow).main, so the restore reads every release they have made.lecture-dp'spublish-2026sep29. Its checksum verifies withsha256sum --checkas downloaded, and its archive holds 644 files and 59 directories and nothing else, so the not-a-file check refuses no real release.lecture-julia.myst,lecture-python.zh-cn,lecture-intro.zh-cn,lecture-python-programming.fa) all deploy withpeaceiris/actions-gh-pagesto agh-pagesbranch (build_type: legacy).-checksum.txt,html-manifest,gh release download), so not renaming the checksum and manifest by tag breaks nothing, and leavespublish-gh-pagesuntouched.The new jobs fail on today's code, which has no
restore-gh-pages. To show that the refusals can fail, a throwaway branch,scratch/27-restore, ran only these jobs and the gate's lint steps:restore-round-trip,restore-refusesand the line-break case passed. Each of the 13 refusals failed at its own check, with its own message. The gate's actionlint,generate-docs.py --check --check-examples --actionlintandlint-shell.pypassed. A stricter shellcheck of the stand-in found one SC1007, fixed in d62debc.sha256sum --checkand its not-a-file check switched off.restore-refuseswent red on exactlytamperedandsymlink: each restored, and left its site behind. The other eleven refusals, the good release,restore-round-trip, the line-break case and the lint all stayed green. The..case was still refused, by GNU tar itself, with nothing written outside the site.The branch is deleted.
Locally,
python3 scripts/generate-docs.py --check --check-examplesis clean. actionlint andlint-shell.pyran in the scratch run, not locally. Againstmain,CHANGELOG.mdgains one entry and loses no line, and everything from## [0.18.0]down is unchanged.What to watch after merge
Nothing at merge. No workflow uses the action or the template until a lecture repository copies
restore.yml. The PR touches no file the lecture matrix or the container builds watch.At the staged release that carries it, the canary should exercise it end to end, as the maintainer agreed for Q7. v0.18.0's staging left a real recovery point in the canary: the release for
publish-staged-v0180, with the triple made bypublish-gh-pagesitself.templates/restore.ymlon the canary'smain, pinned to the candidate tag.tag: publish-staged-v0180.index.html, compared by content.The run's log should show the archive found by its tag,
OKfromsha256sum, the file count, the manifest, and a deploy bypublish-gh-pages. This exercises the real releases API, and a real Pages deploy of a restored site, which the harness cannot.Not in this PR
Naming the checksum and manifest by tag: dropped on HTML Recovery Tool: Restore lecture sites from GitHub Release assets #27. A restore downloads one release into a directory of its own.
Reading the hand-rolled format: dropped on HTML Recovery Tool: Restore lecture sites from GitHub Release assets #27. Those sites deploy from a branch.
Recovery points for the repositories that make none:
templates/publish.ymlships itsrelease-assetsjob commented out;lecture-dp's dispatched publishes make none;lecture-python-programming.zh-cnis Actions-served with no archive.Each is a separate decision.
Adding
restore.ymlto the lecture repositories: their own pull requests, after a release.Closes #27
🤖 Generated with Claude Code
https://claude.ai/code/session_01WT8bMZoMxRqb5P73bRTeCY