ci: alchemy-provisioned CI/CD (scoped token, fix deploy flags, PR previews)#19
Open
cansirin wants to merge 1 commit into
Open
ci: alchemy-provisioned CI/CD (scoped token, fix deploy flags, PR previews)#19cansirin wants to merge 1 commit into
cansirin wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Introduces an alchemy-provisioned CI/CD workflow for the @phoenix/web Cloudflare Worker stack, including a one-shot stack to mint a scoped Cloudflare API token and provision GitHub Actions secrets, plus PR-preview deployments with a sticky preview URL comment.
Changes:
- Added
apps/web/stacks/github.tsone-shot stack to mint a scoped Cloudflare API token and write required repo secrets (CLOUDFLARE_API_TOKEN,CLOUDFLARE_ACCOUNT_ID,ALCHEMY_PASSWORD). - Updated
.github/workflows/deploy.ymlto fix pnpm flag-forwarding by building the SPA first and then runningpnpm ... exec alchemy deploy/destroy --stage ... --yes, with PR stage previews and cleanup on PR close. - Updated
apps/web/alchemy.run.tsto optionally mergeGitHub.providers()and post/update aGitHub.Commentwith the preview URL whenPULL_REQUESTis set; added documentation under.patterns/.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| apps/web/tsconfig.worker.json | Includes stacks/ in the worker TS project so the new alchemy entry is typechecked with the same .ts import settings. |
| apps/web/stacks/github.ts | New admin-only bootstrap stack to mint a scoped Cloudflare token and provision required GitHub Actions secrets. |
| apps/web/alchemy.run.ts | Adds PR-preview comment support gated on PULL_REQUEST, and conditionally composes GitHub + Cloudflare providers. |
| .patterns/index.md | Links the new CI/CD pattern doc from the patterns index. |
| .patterns/alchemy-ci-cd.md | Documents the CI/CD workflow, bootstrap procedure, and key gotchas (pnpm flag forwarding, --yes, preview comment gating). |
| .github/workflows/deploy.yml | Reworks deploy/cleanup jobs to support prod and pr-<n> stages, fix pnpm flag swallowing, and run PR preview comment lifecycle via the stack. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c273821 to
b81eca8
Compare
- stacks/github.ts: one-shot (run under an `admin` profile) that mints a scoped
Cloudflare API token + a stable BETTER_AUTH_SECRET (Random), and pushes the
four repo secrets CI reads: CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID,
ALCHEMY_PASSWORD, BETTER_AUTH_SECRET.
- deploy.yml: fix the bug that keeps Deploy red — `pnpm --filter X deploy
--stage …` makes pnpm eat the flags ("Unknown options: 'stage','yes'"); use
`exec alchemy deploy --stage "$STAGE" --yes`. push→prod, PR→pr-<n>,
close→destroy. Passes BETTER_AUTH_SECRET at deploy AND destroy (config.ts
reads it `Effect.orDie`). node 26.2.0 to match the volta pin.
- .patterns/alchemy-ci-cd.md: the workflow + the human-run bootstrap.
Rebased onto umut/alchemy-effect-patterns. The Random-secret and baseURL bugs
are already fixed on that branch (secret_text binding + harness URL fix), so
the two earlier bug-fix commits are dropped. The in-stack GitHub.Comment preview
is dropped too (clashes with the tightened stack provider types).
typecheck + lint + `alchemy plan` clean (node 26.2.0).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
b81eca8 to
01f1c0e
Compare
usirin
added a commit
that referenced
this pull request
Jun 1, 2026
…tion The previous deploy failed with Cloudflare error 10000 not because the token was expired (the integration job used the same token against real D1 minutes earlier) but because it was scoped to D1 only — a worker deploy needs Workers Scripts Write + KV + Tail + Account-Settings-Read. Bring in #19's solution (Can Sirin / @cansirin): `stacks/github.ts`, a one-shot run from an admin profile that mints a *scoped, non-expiring* Cloudflare API token and pushes the four repo secrets (CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID, ALCHEMY_PASSWORD, BETTER_AUTH_SECRET). The deploy workflow is replaced with #19's version (single deploy job + cleanup with a prod-destroy safety check); the only adaptation is the preview-ENVIRONMENT comment, since #12 already deleted the admin seed/importer routes it referenced. Also add `retry: 2` to the integration vitest project: D1 is always remote, so reads occasionally hit a transient `D1_ERROR: Network connection lost` from a CI runner — retry the idempotent black-box assertions instead of reddening the suite. `stacks/` is added to tsconfig.worker.json so the new entry typechecks, and `.patterns/alchemy-ci-cd.md` documents the flow (indexed). Co-Authored-By: Can Sirin <8138047+cansirin@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Stacked on #12. Adopts the alchemy CI/CD model (tutorial Part 5), adapted to phoenix (pnpm + node, not bun).
What
apps/web/stacks/github.ts(new) — a one-shot, run once under anadminprofile, that mints a scoped Cloudflare API token and writesCLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_ID/ALCHEMY_PASSWORDas repo secrets. No personal Cloudflare key in GitHub..github/workflows/deploy.yml— fixes the bug that kept Deploy red (pnpm --filter X deploy --stage …makes pnpm eat the flags →Unknown options: 'stage', 'yes'). Now builds the SPA, thenexec alchemy deploy --stage "$STAGE" --yes. push→prod, PR→pr-<n>isolated preview, close→destroy(with a prod safety check). Drops the deadsecrets.BETTER_AUTH_SECRET.apps/web/alchemy.run.ts— posts the preview URL as a nativeGitHub.Comment, gated onPULL_REQUESTsoGitHub.providers()stays out of the offlinealchemy dev/ Vitest loop. Providers composed withprovideMerge, notmergeAll(effect TS377035)..patterns/alchemy-ci-cd.md— the workflow + the human-run bootstrap.Why BETTER_AUTH_SECRET is not a CI secret
BetterAuthLivemints it via aRandomresource and persists it in state; CI only needsALCHEMY_PASSWORDto read it back on re-deploy.Verified / not
pnpm typecheck(0 diagnostics) +pnpm lint.stacks/github.tsunderadmin) + real Cloudflare creds. CI stays red until that one-shot runs.🤖 Generated with Claude Code