Skip to content

feat(restore-gh-pages): restore a GitHub Pages site from a release (#27) - #306

Merged
mmcky merged 3 commits into
mainfrom
feat/27-restore-gh-pages
Nov 10, 2026
Merged

mmcky merged 3 commits into
mainfrom
feat/27-restore-gh-pages

Conversation

@mmcky

@mmcky mmcky commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

A broken or vanished lecture site is today rebuilt from source, which for lecture-python.myst means 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 every publish* release, through publish-gh-pages' create-release-assets, and nothing reads those archives. This PR adds the consumer #27 asked for: restore-gh-pages and templates/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

Inputs 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>-html
Outputs build-dir, the extracted site, set only once every check has passed; commit, from the manifest, empty without one
Token None to pass: it reads the release with the job's own token, which needs contents: read
Before anything is downloaded The inputs are checked, through scripts/workflow-command.sh, a line break included (#267)
Before anything is extracted The checksum file must be the one line publish-gh-pages writes, naming this archive, and sha256sum --check --strict must pass
After extracting Anything but files and directories, such as a symlink, removes the site and fails the job: upload-pages-artifact packs with --dereference, and would publish what a link points at on the runner. GNU tar already refuses ..
Which releases The repository's own, any tag, in publish-gh-pages' format. The hand-rolled html-checksum.txt is not read: all four repositories that hand-roll it deploy from a gh-pages branch, which this cannot restore
The template workflow_dispatch with a required tag, publish.yml's pages concurrency group, one job on ubuntu-latest with 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 site

Changes

File Change
restore-gh-pages/action.yml (new) The action: check inputs, read the release's assets and download the archive, checksum and manifest with gh, verify, extract and check the tree, report. Each call works in its own mktemp -d under $RUNNER_TEMP. Every value reaches a script through env:, and every message that prints one goes through annotate. The manifest is printed through jq, never as it is, and a name in the archive is printed escaped
templates/restore.yml (new) The workflow above, with comments on its prerequisites: releases made by publish.yml's release-assets job, and a Pages source of GitHub Actions
docs/user/actions/restore-gh-pages.md (new), restore-gh-pages/README.md (new, generated) The chapter, in CHAPTER-TEMPLATE's shape, with a Troubleshooting entry for each message the action prints
.github/workflows/test-actions.yml restore-round-trip, restore-refuses, a restore-gh-pages: tag case in inputs-line-break, and both jobs in harness-summary's needs:, beside publish-*. The gate finds the action from its uses: ./restore-gh-pages lines
.github/fixtures/release-stub/gh (new) A stand-in for the two gh calls the action makes, serving releases from a directory. A call it does not expect, or one without GH_TOKEN, is recorded, and both jobs fail on it
scripts/generate-docs.py restore-gh-pages in ORDER, after publish-gh-pages
docs/user/README.md The action index, generated
docs/user/actions/publish-gh-pages.md One sentence in Release assets pointing at restore-gh-pages, as agreed with the organiser. Nothing else in publish-gh-pages/ changes
docs/user/getting-started.md, docs/user/security.md One row each for restore.yml, as agreed
templates/README.md A row for restore.yml
docs/dev/ARCHITECTURE.md Eleven actions, and restore.yml among the templates
docs/dev/TESTING.md A restore-gh-pages row, and the fixture
docs/dev/PLAN.md restore-gh-pages in the list of actions, and #27 out of "New actions and decisions"
CHANGELOG.md One entry under [Unreleased], ### Added. Not ⚠️ BREAKING: a new action and template, and no existing behaviour changes

What I checked, and how

The issue check (written up for the organiser and agreed on #27) found, against main at f627321:

  • The producers: the same eight repositories pass create-release-assets: 'true', two at @v0 and 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).
  • The format: the names and the seven manifest fields are identical at v0.8.0, v0.12.0 and main, so the restore reads every release they have made.
  • A real archive: I downloaded lecture-dp's publish-2026sep29. Its checksum verifies with sha256sum --check as downloaded, and its archive holds 644 files and 59 directories and nothing else, so the not-a-file check refuses no real release.
  • The hand-rolled four (lecture-julia.myst, lecture-python.zh-cn, lecture-intro.zh-cn, lecture-python-programming.fa) all deploy with peaceiris/actions-gh-pages to a gh-pages branch (build_type: legacy).
  • No reader of the assets exists anywhere in the org (code search for -checksum.txt, html-manifest, gh release download), so not renaming the checksum and manifest by tag breaks nothing, and leaves publish-gh-pages untouched.

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:

  • Run 42909637873: restore-round-trip, restore-refuses and 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 --actionlint and lint-shell.py passed. A stricter shellcheck of the stand-in found one SC1007, fixed in d62debc.
  • Run 42909880433: the same jobs, with d62debc's messages, and with the action's sha256sum --check and its not-a-file check switched off. restore-refuses went red on exactly tampered and symlink: 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-examples is clean. actionlint and lint-shell.py ran in the scratch run, not locally. Against main, CHANGELOG.md gains 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 by publish-gh-pages itself.

  1. After a release-gate run has replaced the canary's Pages site with the gate fixture, put templates/restore.yml on the canary's main, pinned to the candidate tag.
  2. Dispatch it with tag: publish-staged-v0180.
  3. Check that the Pages URL then serves that archive's index.html, compared by content.
  4. The next gate run deploys its fixture again.

The run's log should show the archive found by its tag, OK from sha256sum, the file count, the manifest, and a deploy by publish-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

Closes #27

🤖 Generated with Claude Code

https://claude.ai/code/session_01WT8bMZoMxRqb5P73bRTeCY

mmcky and others added 3 commits November 11, 2026 08:54
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
Copilot AI balanced review requested due to automatic review settings November 10, 2026 21:58
@mmcky
mmcky merged commit 38ab846 into main Nov 10, 2026
71 checks passed
@mmcky
mmcky deleted the feat/27-restore-gh-pages branch November 10, 2026 22:05

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.

🟡 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-pages action to validate inputs, download release assets via gh, verify SHA-256 checksums, safely extract, and expose the restored build-dir (and optional commit).
  • Add templates/restore.yml workflow 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

Comment on lines +195 to +208
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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)

mmcky added a commit that referenced this pull request Nov 10, 2026
#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]>
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.

HTML Recovery Tool: Restore lecture sites from GitHub Release assets

2 participants