Skip to content

ci(preview): isolate preview deploys per PR (fix shared-URL overwrite)#262

Merged
jlian merged 3 commits into
mainfrom
fix/per-pr-preview-urls
Jul 21, 2026
Merged

ci(preview): isolate preview deploys per PR (fix shared-URL overwrite)#262
jlian merged 3 commits into
mainfrom
fix/per-pr-preview-urls

Conversation

@jlian

@jlian jlian commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Problem

After the Pages → Workers migration, every PR overwrites the same preview deployment.

The CI deploy step ran wrangler deploy --env preview, which always targets the single Worker named wingdex-app-preview (from [env.preview] + top-level name = "wingdex-app"). So all open PRs deploy to the same URL — wingdex-app-preview.lianguanlun.workers.dev — and last-deploy-wins. They also shared the preview D1 (wingdex-db-dev) and R2 buckets, so "the preview" reflected whichever PR deployed most recently, not the PR you were looking at.

Pages used to give per-branch preview URLs for free; the migration silently dropped that isolation.

Fix

Use per-PR aliased preview URLs:

  • Deploy step now runs wrangler versions upload --env preview --preview-alias pr-<PR#>. This creates a version with a stable alias URL of the form pr-<PR#>-wingdex-app-preview.<subdomain>.workers.dev (needs preview_urls = true, already set). Unlike deploy, it does not change the live/deployed version — each PR only gets its own isolated preview URL.
  • The GitHub deployment status + a sticky PR comment surface the per-PR URL (parsed from wrangler's output, with a deterministic fallback).

Result

No more stomping. Each in-flight PR has an independent preview.

Notes / caveats

  • Shared preview state remains. All previews still point at the same wingdex-db-dev and the wingdex-range-priors / wingdex-models R2 buckets (these bindings are account-global). This PR isolates the code/URL, not the data. Fully isolating per-PR D1/R2 is a bigger change; flagging it but out of scope here.
  • Preview aliases don't need explicit cleanup — re-uploading with the same pr-<N> alias reuses it, and old versions age out per Cloudflare retention. The existing cleanup-preview.yml (deactivates GitHub deployment records on PR close) is unchanged.
  • Prod is unaffected: production deploys happen via release.yml on merge to main, not this step.

Priority: merge first, then the two in-flight PRs (#258, #259) get correct isolated previews once rebased/updated onto this.

Previously every PR ran `wrangler deploy --env preview`, which deploys to the
single `wingdex-app-preview` Worker. Concurrent PRs overwrote each other at the
same shared URL (wingdex-app-preview.lianguanlun.workers.dev) and shared the
preview D1 + R2 state, so 'the preview' reflected whichever PR deployed last.

Switch to per-PR aliased preview URLs:
- `wrangler versions upload --env preview --preview-alias pr-<N>` creates a
  version with a stable alias URL pr-<N>-wingdex-app-preview.<subdomain>.workers.dev
  (requires preview_urls = true, already set). Unlike `deploy`, it does not
  change the live deployed version.
- The deployment status + a sticky PR comment surface the per-PR URL, parsed
  from wrangler's output with a deterministic fallback.

Each in-flight PR now has an isolated preview that no longer stomps the others.
Copilot AI review requested due to automatic review settings July 21, 2026 06:32
@github-actions
github-actions Bot temporarily deployed to preview (#262) July 21, 2026 06:35 Inactive
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

🔎 Preview for this PR: https://pr-262-wingdex-app-preview.lianguanlun.workers.dev

Isolated per-PR alias, no longer shared/overwritten across PRs. Updates on every push.

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.

Pull request overview

Updates the CI preview deployment flow to prevent concurrent pull requests from overwriting a single shared Cloudflare Workers preview URL, restoring per-PR preview isolation after the Pages → Workers migration.

Changes:

  • Switch preview deployment from wrangler deploy --env preview to wrangler versions upload --env preview --preview-alias pr-<PR#> to create stable per-PR alias URLs.
  • Parse the per-PR alias URL from Wrangler output (with a deterministic fallback) and publish it via GitHub deployment status.
  • Add/update a sticky PR comment containing the per-PR preview URL for reviewer convenience.

Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread .github/workflows/ci.yml
- Replace em-dashes with ASCII punctuation (CONTRIBUTING.md style guide) in the
  workflow comment and the sticky PR-comment body.
- Paginate listComments via github.paginate so the sticky preview-URL marker is
  found on busy PRs instead of creating a duplicate comment.
Copilot AI review requested due to automatic review settings July 21, 2026 06:38

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread .github/workflows/ci.yml Outdated
@github-actions
github-actions Bot temporarily deployed to preview (#262) July 21, 2026 06:41 Inactive
The Branch preview deployment step set core.setOutput('preview_url', ...) but
nothing consumed it (the sticky-comment step re-parses the URL independently).
Remove the dead output to avoid confusion.
Copilot AI review requested due to automatic review settings July 21, 2026 06:41

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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@jlian
jlian merged commit 8c5785b into main Jul 21, 2026
3 checks passed
@jlian
jlian deleted the fix/per-pr-preview-urls branch July 21, 2026 06:47
jlian added a commit that referenced this pull request Jul 21, 2026
)

Follow-up to #262. Two cleanups + address the Node 20 deprecation
notices.

## 1. Remove the preview sticky-comment step

The `Comment preview URL on PR` step auto-posted (and re-posted on every
push) a comment like [this
one](#262 (comment)).
It's redundant: the per-PR preview URL is already surfaced on the PR via
the **GitHub deployment / Environments UI** (the `Branch preview
deployment` step sets `environment_url`). Removing the comment cuts the
noise. Also drops the now-unused `pull-requests: write` permission from
the CI job (least privilege).

## 2. Fix Node 20 deprecation warnings

CI was emitting:
> Node 20 is being deprecated. This workflow is running with Node 24 by
default...

Source: actions still pinned to Node 20 runtimes. Bumped to Node 24:
- `cloudflare/wrangler-action@v3` → `@v4` (ci.yml, release.yml). v4's
only major change is `wranglerVersion` input flexibility (version
ranges/tags); no behavior change for our exact-command usage.
- `actions/github-script@v7` → `@v9` (ci.yml, cleanup-preview.yml,
rotate-apple-secret.yml). v9 runs on node24.

All other actions (`checkout@v6`, `setup-node@v6`, `cache@v5`) were
already on Node 24.

## Verification
- All 9 workflow files validated as parseable YAML.
- No `@v3` wrangler-action / `@v7` github-script references remain.
- Preview isolation (from #262) is unchanged: still `versions upload
--preview-alias pr-<N>`.

_Note: separately, the Copilot review comments on #259 are being handled
on that PR._
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.

2 participants