Skip to content

ci: alchemy-provisioned CI/CD (scoped token, fix deploy flags, PR previews)#19

Open
cansirin wants to merge 1 commit into
umut/alchemy-effect-patternsfrom
can/alchemy-cicd
Open

ci: alchemy-provisioned CI/CD (scoped token, fix deploy flags, PR previews)#19
cansirin wants to merge 1 commit into
umut/alchemy-effect-patternsfrom
can/alchemy-cicd

Conversation

@cansirin
Copy link
Copy Markdown
Contributor

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 an admin profile, that mints a scoped Cloudflare API token and writes CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID / ALCHEMY_PASSWORD as 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, then exec alchemy deploy --stage "$STAGE" --yes. push→prod, PR→pr-<n> isolated preview, close→destroy (with a prod safety check). Drops the dead secrets.BETTER_AUTH_SECRET.
  • apps/web/alchemy.run.ts — posts the preview URL as a native GitHub.Comment, gated on PULL_REQUEST so GitHub.providers() stays out of the offline alchemy dev / Vitest loop. Providers composed with provideMerge, not mergeAll (effect TS377035).
  • .patterns/alchemy-ci-cd.md — the workflow + the human-run bootstrap.

Why BETTER_AUTH_SECRET is not a CI secret

BetterAuthLive mints it via a Random resource and persists it in state; CI only needs ALCHEMY_PASSWORD to read it back on re-deploy.

Verified / not

  • pnpm typecheck (0 diagnostics) + pnpm lint.
  • ⚠️ No live deploy yet — needs the secrets bootstrapped (stacks/github.ts under admin) + real Cloudflare creds. CI stays red until that one-shot runs.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 30, 2026 21:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts one-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.yml to fix pnpm flag-forwarding by building the SPA first and then running pnpm ... exec alchemy deploy/destroy --stage ... --yes, with PR stage previews and cleanup on PR close.
  • Updated apps/web/alchemy.run.ts to optionally merge GitHub.providers() and post/update a GitHub.Comment with the preview URL when PULL_REQUEST is 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.

@cansirin cansirin force-pushed the can/alchemy-cicd branch from c273821 to b81eca8 Compare May 31, 2026 01:15
- 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>
@cansirin cansirin force-pushed the can/alchemy-cicd branch from b81eca8 to 01f1c0e Compare May 31, 2026 22:40
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>
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