Repository navigation
fix(website): deploy previews before commenting, and purge the CDN cache - #888
Merged
Merged
Conversation
A comment must never prevent a deploy. The preview workflow's comment steps ran first, so a pull request opened from a fork -- whose GITHUB_TOKEN is read-only whatever `permissions:` grants -- failed at `GraphQL: Resource not accessible by integration (addComment)` and skipped the deploy entirely (run 39134047965), leaving the previous build served. - Deploy the preview worker first; purge, then update the comment. - Every GitHub-comment step is `continue-on-error`. - Grant `issues: write`: PR conversation comments are issue comments, and `pull-requests: write` alone does not cover them. - Purge the CDN cache after deploying, scoped to `https://ema.tnsor.network/preview/<n>/` via `prefixes`; the production workflow purges its whole zone after the router deploy. Both skip with a notice when `CLOUDFLARE_ZONE_ID` is unset for the environment. - A router change now refreshes previews too: `deploy-website.yml` and `website/site/worker/**` joined the preview trigger paths.
🦋 Changeset detectedLatest commit: 826d43c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
🧹 Site preview for this PR was deleted (PR closed). |
[High impact] The PR appears safe to merge; all previous findings are addressed and no new blocking issues were found.
|
…comment Three review findings, each verified before the fix. 1. The purge prefix carried a scheme. Cloudflare's purge-by-prefix takes a hostname and path - `www.example.com/foo` - and a value beginning with `https://` is rejected outright, so the purge would have failed on every preview once a zone id existed, silently, as a ::warning:: in a run nobody reads. Now `ema.tnsor.network/preview/<n>/`. Checked against the documented format, and the body parses with no scheme. 2. A fork PR could still reach `wrangler deploy`. The reorder stopped a comment from killing the deploy; it did not stop a run that can never deploy from trying. A `pull_request` run from a fork receives no repository secrets, so the guard now skips fork runs with a notice before any setup, instead of failing at the deploy with an empty token. Serving forks needs a `workflow_run` deployment on a trusted branch; that is not something this workflow can fake, and it does not pretend to. 3. The "rendering" comment step is removed. It ran after the deploy but overwrote the link with "still rendering", then relied on a second API write to restore it - so a failed second write or a cancelled run left a finished preview reading as unfinished. The comment is now written once, in its final state, after the deploy. actionlint: clean apart from the four pre-existing checkout@v3/setup-node@v3 warnings. Guard truth table exercised: fork head -> skip, same-repo head -> the environment check as before.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two fixes to the website preview deploy, from one measured failure on 2026-10-18.
A comment can no longer prevent a deploy. Run 39134047965 failed at 14:01Z in Mark the preview comment as rendering with
GraphQL: Resource not accessible by integration (addComment), and every later step — including Deploy the preview worker — was skipped. The preview therefore kept serving the previous build.The cause is not a missing
issues: writegrant alone. Run 39134047965 was triggered byPriyanshubhartistmfrom the forkPriyanshubhartistm/nostream, and apull_requestrun from a fork receives a read-onlyGITHUB_TOKENwhatever thepermissions:block says. Same-repo runs under the identical permissions block have been writing that comment successfully all afternoon (PR #884 at 14:16Z,marked comment 6250682147 as rendering).continue-on-error: true.issues: writeas well — PR conversation comments are issue comments, andpull-requests: writedoes not cover them; the same-repo runs only worked because the repository's default token already included it.The CDN cache is purged after deploying. At 14:01:53Z
https://ema.tnsor.network/preview/885/returned production HTML — nox-preview-pr,cache-control: public, max-age=0, must-revalidate— and answered correctly three minutes later. A stale window, not a broken deploy.POST /zones/<id>/purge_cachewith{"prefixes":["https://ema.tnsor.network/preview/<n>/"]}, so one PR's purge cannot touch the production site or another preview.deploy-website.yml):purge_everythingafter the router deploy — it is the same domain and the whole build changes.::notice::whenCLOUDFLARE_ZONE_IDis unset for their environment, and both arecontinue-on-error, so an unconfigured or under-scoped credential costs a purge, never a deploy. This mirrors the existingwebsite-previewenvironment guard.A router change now also refreshes previews:
deploy-website.ymlandwebsite/site/worker/**joined the trigger paths, because the production deploy ships the router that serves/preview/*.Configuration this needs (not a code change)
CLOUDFLARE_ZONE_IDmust exist as an environment variable on both thewebsite-previewandwebsiteenvironments (Settings → Environments → … → Environment variables). It is theema.tnsor.networkzone id. Until it is set, both purge steps skip with a notice and previews deploy exactly as they do now.The
CLOUDFLARE_API_TOKENin each environment is the one already used forwrangler deploy. A Workers-Scripts-only token cannot purge a zone cache; the purge step reportsHTTP <code>with the API's message as a::warning::if the scope is missing, so the gap is visible in the run rather than silent.Verification
Both workflows parse (
js-yaml) and lint clean underactionlint1.7.12 apart from four pre-existingactions/checkout@v3/actions/setup-node@v3runner-age warnings that this PR does not introduce.Step order in
deploy-website-preview.ymlafter this change:Every
run:block was extracted, templated withn=885, and shell-syntax-checked.The purge step was executed against the live API on both paths: with no zone id it prints the notice and exits 0; with a zone id and a bad token it prints
::warning::cache purge answered HTTP 401 — {"success":false,"errors":[{"code":10000,"message":"Authentication error"}]}and exits 0.Not verified here: a real end-to-end run, which needs a preview run to fire on the branch.
Thanks to @Priyanshubhartistm — the fork PR (#885) is what surfaced this.