Skip to content

ci: deploy a preview of each labelled PR - #289

Open
acoyfellow wants to merge 3 commits into
cloudflare:mainfrom
acoyfellow:jcoeyman/preview-deploys
Open

acoyfellow wants to merge 3 commits into
cloudflare:mainfrom
acoyfellow:jcoeyman/preview-deploys

Conversation

@acoyfellow

Copy link
Copy Markdown
Contributor

Deploys a preview of a PR so the team can test it before release, with real accounts and no local setup.

How it works

  • A maintainer adds the preview label. The workflow deploys the PR head as cloudflare-api-mcp-pr-<n> on pr-<n>.<PREVIEW_DOMAIN_SUFFIX>, checks that /mcp answers 401 without a token, and comments the URL and a codex mcp add line on the PR.
  • New commits remove the label, so each update needs a fresh review before it deploys again.
  • Closing the PR deletes the Worker.
  • The MCP host allowlist also accepts the HTTPS hostname in MCP_RESOURCE. Each deployment trusts only its own hostname. Production and staging behave as before.

Security

  • pull_request_target runs PR code with the deploy secret, so deploys run only on the preview label, which only maintainers can add. npm ci --ignore-scripts keeps install scripts from running. The config script is read from the base branch, not the PR.
  • Previews have no workers.dev or preview URLs. They hold no Cloudflare credential of their own: every call uses the tester's token.

Setup (one time, for maintainers)

  • Secret PREVIEW_DEPLOY_TOKEN: Workers Scripts Edit and Workers Custom Domains Edit on the preview account.
  • Variables: PREVIEW_ACCOUNT_ID, PREVIEW_DOMAIN_SUFFIX (a zone on that account), PREVIEW_KV_ID, PREVIEW_BUCKET (seeded with scripts/seed-r2.ts).
  • Not included: OAuth sign-in. Testers use an API token until a preview OAuth client exists for pr-*.<suffix>.

Verified on acoyfellow/mcp

  • Test PR preview workflow test (do not merge) acoyfellow/mcp#2 (feat(apps): render show_attention as an MCP App panel and sidebar entry #282's code), with the preview label added: run 38584100072 deployed https://pr-2.mcp-preview.ax.cloudflare.dev/mcp and commented the URL.
  • Through that URL: initialize 200, tools/list includes show_attention with its UI resource, and show_attention returned the real items on a test account. Codex CLI called the tool through it.
  • A push removed the label and posted the re-review comment.
  • Closing the PR: run 38584302491 deleted the Worker (wrangler deployments list says it doesn't exist), and the URL stopped answering.
  • npm test 486 passed, plus a new tests/mcp-deployed-host.test.ts. tsc, format:check, lint (1 warning, also on main) and actionlint pass.

A maintainer adds the preview label to deploy the PR head to
pr-<number>.<suffix> on a preview account. The workflow checks the server
answers with 401, comments the URL on the PR, and deletes the Worker when the
PR closes. New commits remove the label, so each update needs a fresh review.

The MCP host allowlist also accepts the HTTPS hostname in MCP_RESOURCE, so a
deployment trusts only its own hostname.
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.

1 participant