monorepo-template / ops
Cursor rule18 starsChanged 2 months agoApache-2.0View on GitHub
Cloudflare Worker Previews pipeline - credential-free Preview build then cf previews deploy, Wrangler-only delete and secrets, Access before arming, agent loop.
In this repository60 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .agents/skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- hooks/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- hooks/CLAUDE.mdCLAUDE.md
- .cursor/rules/backend/hono-gateway.mdcCursor rule
- .cursor/rules/backend/ports.mdcCursor rule
- .cursor/rules/backend/service-bindings.mdcCursor rule
- .cursor/rules/backend/workers-cache.mdcCursor rule
- .cursor/rules/backend/workers-config.mdcCursor rule
- .cursor/rules/contracts/contracts.mdcCursor rule
- .cursor/rules/core/agent-instructions.mdcCursor rule
- .cursor/rules/core/boundaries.mdcCursor rule
- .cursor/rules/core/guardrails.mdcCursor rule
- .cursor/rules/core/turborepo.mdcCursor rule
- .cursor/rules/core/worktrees.mdcCursor rule
- .cursor/rules/frontend/react.mdcCursor rule
- .cursor/rules/frontend/tailwind.mdcCursor rule
- .cursor/rules/frontend/tanstack-query.mdcCursor rule
- .cursor/rules/frontend/tanstack-router.mdcCursor rule
- .cursor/rules/frontend/vite-config.mdcCursor rule
- .cursor/rules/ops/cd.mdcCursor rule
- .cursor/rules/ops/changesets.mdcCursor rule
- .cursor/rules/ops/ci.mdcCursor rule
- .cursor/rules/ops/quality-report.mdcCursor rule
- .cursor/rules/ops/release.mdcCursor rule
- .cursor/rules/quality/code-style.mdcCursor rule
- .cursor/rules/quality/comments.mdcCursor rule
- .cursor/rules/quality/knip.mdcCursor rule
- .cursor/rules/quality/lint-config.mdcCursor rule
- .cursor/rules/quality/markdown-style.mdcCursor rule
- .cursor/rules/quality/naming.mdcCursor rule
- .cursor/rules/quality/simplicity.mdcCursor rule
- .cursor/rules/quality/testing.mdcCursor rule
- .cursor/rules/quality/typescript-config.mdcCursor rule
- .cursor/rules/tests/front-react.mdcCursor rule
- .cursor/rules/tests/hono-workers.mdcCursor rule
- cfSkill
- changesetSkill
- front-vitestSkill
- git-commitSkill
- honoSkill
- monorepo-agent-setupSkill
- playwright-cliSkill
- pnpmSkill
- react-doctorSkill
- reviewSkill
- review-stackSkill
- run-appSkill
- security-auditSkill
- skills-updateSkill
- tanstack-configSkill
- tanstack-devtoolsSkill
- tanstack-querySkill
- tanstack-routerSkill
- turborepoSkill
- ui-ux-design-best-practicesSkill
- vercel-react-best-practicesSkill
- workers-best-practicesSkill
- skills-updateSkill
The file
Files
--- description: "Cloudflare Worker Previews pipeline - credential-free Preview build then cf previews deploy, Wrangler-only delete and secrets, Access before arming, agent loop." alwaysApply: false globs: .github/workflows/preview.yml,.github/actions/previews/**,.github/actions/lib/smoke.mjs --- # Worker Previews Branch and PR testing uses [Worker Previews](https://developers.cloudflare.com/workers/previews/): an isolated Preview **under the production Worker** (`<app>-production`), with its own bindings, URL (`<preview>-<app>-production.<subdomain>.workers.dev`), and observability, built from each app's `ctx.isPreview` branch ([workers-config.mdc](../backend/workers-config.mdc), Preview branch) and deployed with `cf previews deploy`. The pipeline is [`.github/workflows/preview.yml`](../../../.github/workflows/preview.yml), the scripts `.github/actions/previews/`; read them for the steps. Never use Version URLs (`cf workers versions create --preview-alias`) or an extra mode for branch testing: both run on shared resources. ## Build, deploy, delete - **Every `cf` Preview command carries `--mode production`** (`cf build`, `cf previews deploy`). The Wrangler-only ones (`preview delete`, `preview secret put`) name the Worker with `--worker-name <app>-production` instead, since no Wrangler config exists. - `deploy-previews.sh` walks the apps in `monorepo.deployOrder`. Each app is built **without credentials** - `env -u CLOUDFLARE_API_TOKEN -u CLOUDFLARE_ACCOUNT_ID -u CF_ACCESS_CLIENT_ID -u CF_ACCESS_CLIENT_SECRET CLOUDFLARE_PREVIEW_BUILD=true pnpm --filter=<app> exec cf build --mode production`, plus the `VITE_*` values for a frontend - then deployed with credentials: `pnpm --filter=<app> exec cf previews deploy <name> --prebuilt --mode production`. - `CLOUDFLARE_PREVIEW_BUILD=true` is cf's internal, undocumented variable that makes a build a Preview build (`ctx.isPreview`, recorded as `buildContext.isPreview`). `cf previews deploy --prebuilt` refuses Build Output that is not a Preview build, so if cf drops the variable the deploy fails loudly instead of shipping production values to a Preview; conversely `cf deploy`, `cf workers versions create`, and `cf workers triggers deploy` refuse a Preview build. - `cf previews deploy` prints one JSON object on stdout (`type: "preview"`, `preview_urls`, `deployment_id`, …) and build logs on stderr; the URL is `.preview_urls[0]`. It takes no `--message`. - The SPA's `VITE_API_BASE_URL` is the gateway **Preview** URL, which is why the gateway is previewed first and the frontend built afterwards. - **One smoke, after the last deploy**: `deploy-previews.sh` hands every Preview URL to `.github/actions/lib/smoke.mjs`, the same smoke as CD and skill `run-app`, so the gateway check also proves its CORS allowlist admits the SPA Preview origin. A `--url` target is retried for ~25 s on an error, a 404, or a 52x while the new hostname starts serving. A broken gateway therefore costs one SPA build before the run fails. - **The PR comment is `changesets/action/pr-comment`** (`update-id: worker-previews`), fed by the deploy step's `body` output; locally the same URL table goes to stdout. It searches only the first 30 comments ([quality-report.mdc](quality-report.mdc)). - cf has no Preview delete or list. `delete-previews.sh` runs `pnpm exec wrangler preview delete --worker-name <app>-production --name <preview> -y` for every app, attempting each even when one fails, with no config file. Locally it authenticates through Wrangler (`pnpm exec wrangler login`, or exported `CLOUDFLARE_API_TOKEN` / `CLOUDFLARE_ACCOUNT_ID`); `cf auth login` does not cover it. ## Exposure and credentials - **`previewUrls: true` is applied by `cf workers triggers deploy`**, never by `cf workers versions create` or `cf workers deployments create`, which is all CD runs: apply it once per app with `pnpm --filter=<app> exec cf workers triggers deploy --mode production`. It also exposes production Version URLs. - **Preview URLs are public by default.** Enable Cloudflare Access on the `front-app` Preview URLs before arming `PREVIEWS_ENABLED`. Access on the **gateway** Preview hostname redirects the SPA's cross-origin `fetch` to a login page and breaks it: the gateway Preview relies on its `CORS_ORIGINS` allowlist, unless the Access application's CORS settings are configured and the SPA sends credentials. The workflow's `CF_ACCESS_CLIENT_ID` / `CF_ACCESS_CLIENT_SECRET` service token passes Access only once a **Service Auth** policy includes it. - Credentials live on the `preview` GitHub Environment, step-scoped exactly as in [cd.mdc](cd.mdc). The token edits the production Worker's scripts, so it is as powerful as the CD token: account-scoped Workers Scripts Edit, never a Global API Key. Fork and Dependabot PRs never run the job; never switch to `pull_request_target`. - A Preview that needs a real secret gets it from `pnpm exec wrangler preview secret put <KEY> --name <preview> --worker-name <app>-production`, never a production value. ## Limits 100 Previews per Worker (Free) / 500 (Paid), 100 deployments per Preview; the least-recently-deployed Preview is evicted first. Closed PRs delete theirs (`cleanup` job); branch Previews created locally are yours to delete. ## Agent loop 0. Once per account: set `corsOrigins` on `PREVIEW` in `apps/worker-api/cloudflare.config.ts`, and apply `previewUrls` (above). Empty `CORS_ORIGINS` makes the gateway smoke answer **503**; a missing `previewUrls` leaves the Preview without a URL. The script names both fixes. 1. `pnpm preview:deploy` creates a Preview named after the branch (or `PREVIEW_NAME=…`), smokes each app's `monorepo.healthPath`, and prints the URLs. `.claude/settings.json` denies it to agents: hand it to the user as `! pnpm preview:deploy`, or push the branch and read the Previews comment the workflow posts (`gh pr view <n> --comments`). 2. Probe and render the Preview with skill `run-app`; behind Access, its smoke sends `CF_ACCESS_CLIENT_ID` / `CF_ACCESS_CLIENT_SECRET` from the environment. The sandbox allowlist must name the account's `*.<subdomain>.workers.dev`, and `NODE_USE_ENV_PROXY=1` must be set so Node's `fetch` uses the sandbox proxy. 3. Logs and traces: the `cloudflare-observability` MCP server (authenticate once with `/mcp`) filtered by the `X-Request-Id` the smoke printed, or the Preview's Observability tab; `wrangler tail` cannot target Previews. 4. Patch, rerun step 1 (the same name updates the same Preview), then `pnpm preview:delete`.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

