Fix PR-preview deploys: write metadata after checkout (survives git clean)#913
Conversation
The "Save PR metadata" step ran before `actions/checkout@v5`, whose default
`clean: true` runs `git clean -ffdx` and deletes untracked files in the
workspace — including the `_preview_upload/` directory the metadata step had
just created. As a result `_preview_upload/meta/{pr-number,action}.txt` never
made it into the `pr-preview-site` artifact (only `site/`, staged after
checkout, survived).
Downstream, preview-deploy.yml's "Read PR metadata" then `cat`-ed missing
files, leaving `pr-number`/`action` empty, so the deploy step's
`if: steps.meta.outputs.action == 'deploy'` guard was false and the deploy was
silently skipped — while the job still reported success. Net effect: every
deploy-path (non-closed) PR preview stopped publishing, with green checks.
Move the metadata step to run after checkout. It stays unguarded, so the
'closed'/remove path (which skips checkout) is unaffected.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
|
Claude finished @d-morrison's task in 2m 15s —— View job Code Review: Fix PR-preview deploys
Verdict: Correct fix. Approve. The root cause is accurately diagnosed and the fix is minimal and sound. Here's the full analysis: What changed
Correctness analysis
Both paths are correct before and after the fix; only the deploy path was broken. Findings
The 10-line comment explaining the ordering constraint is justified here. The bug was a subtle ordering dependency with no other in-file signal, and the comment prevents a future "let me clean this up" revert from reintroducing the regression.
- name: Read PR metadata
id: meta
run: |
echo "pr-number=$(cat _preview_download/meta/pr-number.txt)" >> "$GITHUB_OUTPUT"
echo "action=$(cat _preview_download/meta/action.txt)" >> "$GITHUB_OUTPUT"When Consider hardening this in a follow-up: run: |
pr_number=$(cat _preview_download/meta/pr-number.txt) || { echo "::error::Missing pr-number.txt"; exit 1; }
action=$(cat _preview_download/meta/action.txt) || { echo "::error::Missing action.txt"; exit 1; }
echo "pr-number=$pr_number" >> "$GITHUB_OUTPUT"
echo "action=$action" >> "$GITHUB_OUTPUT"Not a blocker for this PR — that file isn't changed here and it's a pre-existing issue.
echo "${{ github.event.action == 'closed' && 'remove' || 'deploy' }}" > _preview_upload/meta/action.txtGitHub Actions ternary idiom ( SummaryThe fix is correct, minimal, and the inline comment prevents the ordering constraint from being accidentally reverted. The one follow-up worth tracking is hardening |
Harden the "Read PR metadata" step so a missing pr-number.txt/action.txt errors out instead of producing empty outputs and exit 0. Previously a bare `$(cat missing)` inside `echo` left the outputs empty and the deploy step's `action == 'deploy'` guard silently false — the same silent-skip pathology the metadata-after-checkout fix addresses on the build side. This is a defensive net for any future corrupt/partial artifact. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: d-morrison <2474437+d-morrison@users.noreply.github.com>
|
Thanks — and the fix is validated end-to-end: this PR's own preview published at https://d-morrison.github.io/rme/pr-preview/pr-913/ (200; On the one finding:
@claude review |
|
Claude finished @d-morrison's task in 1m 22s —— View job Code Review: Fix PR-preview deploys (updated)
Verdict: Correct and complete. Approve. The previous finding (silent-failure risk in
|
|
👀 Picked up by workflow run #27795652122. R/Quarto/renv setup runs first (~3-5 min); Claude itself responds after that. |
|
Re the empty- |
2026-06-19 01:00 UTC |
Problem
PR-preview deploys silently stopped publishing: preview builds pass and the
pr-preview-siteartifact uploads (~27 MB), but the preview never appears ongh-pagesand all checks stay green. Affects every deploy-path (non-closed) PR — e.g. #912 builds fine buthttps://d-morrison.github.io/rme/pr-preview/pr-912/404s, andpr-912/is absent fromgh-pages. Thepr-preview/pr-NNNdirs currently ongh-pagesare stale (from before this regression).Root cause
In
preview.ymlthe steps ran:mkdir -p _preview_upload/meta, writepr-number.txt/action.txt— before checkoutactions/checkout@v5(defaultclean: true) runsgit clean -ffdx, deleting the untracked_preview_upload/(incl.meta/)_preview_upload/site/(after checkout, so it survives)pr-preview-site=_preview_upload/→ contains onlysite/, nometa/Then
preview-deploy.yml's "Read PR metadata"cats the missing files:→
pr-number/actionoutputs empty →if: steps.meta.outputs.action == 'deploy'is false → Deploy step skipped, but the failedcatdoesn't fail the step, so the job reports success.Evidence
27786018099) logs the twocat: … No such filelines, then skips the deploy step; job = success.pr-preview-siteartifact from the build directly shows a top level ofsite/only — nometa/.Fix
Move Save PR metadata to run after "Check out repository", so the files are created after
git cleanand survive into the artifact. It only needsgithub.event.pull_request.number, available regardless of checkout. The step stays unguarded, so theclosed/remove path (which skips checkout) is unaffected. Added a comment so the load-bearing ordering isn't reverted.Validation
This PR's own preview build runs the fixed
preview.yml(head-branch version), so if the deploy publishespr-preview/pr-<this-PR>/, the fix is confirmed end-to-end. Note: open PRs like #912 will needmainmerged in (or a re-run) to pick up the fixed workflow for their own previews.🤖 Generated with Claude Code