All jobs

Set Up GitHub Actions CI and Deploys for a Cloudflare Worker

Yes. An agent adds a GitHub Actions workflow that checks and dry-run builds your Worker on each PR and deploys it with its D1 migrations on main, then opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads the scripts the project already has before writing a workflow around them. In a Worker like the d1-template in cloudflare/templates, package.json pins wrangler 4.136.1 and typescript 5.9.3 and defines the whole lifecycle as scripts: cf-typegen runs wrangler types to regenerate worker-configuration.d.ts, check runs tsc && wrangler deploy --dry-run, seedLocalD1 and predeploy run wrangler d1 migrations apply DB with --local and --remote, and deploy runs wrangler deploy. wrangler.json names the Worker, sets compatibility_date to 2025-10-08, binds the D1 database d1-template-database as DB with its database_id, and turns on observability and upload_source_maps. src/index.ts prepares SELECT * FROM comments LIMIT 3 against env.DB and renders the rows through renderHtml.ts; migrations/0001_create_comments_table.sql creates and seeds the table; tsconfig.json reads the generated types. There is a package-lock.json, so the package manager is npm, and no .github directory.

The workflow the agent writes does on GitHub what those scripts do locally, in two jobs. On every pull request, a check job runs actions/checkout, actions/setup-node on Node 22 with the npm cache, npm ci, npm run cf-typegen followed by git diff --exit-code worker-configuration.d.ts so a binding added to wrangler.json without regenerating the types fails the check, and npm run check, which type-checks and builds the Worker with wrangler deploy --dry-run without needing an account. On a push to main, a deploy job runs the same install and check, then npx wrangler d1 migrations apply DB --remote and npx wrangler deploy, with CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID from repository secrets in the job's env, which are the two variable names turbo.json in the same repository declares for its own deploy task. A concurrency group on the deploy job keeps two pushes from applying migrations at the same time, and permissions: contents: read is set at the top.

Before it pushes, the agent runs the pull-request half itself in the sandbox: npm ci, npm run cf-typegen with the diff check, and npm run check, and pastes the tsc and dry-run output. It also runs npm run seedLocalD1 and wrangler dev to make one request against the local Worker and show the three seeded comments, which confirms the migration file and the binding name agree. The deploy half it cannot run, because it has no token, and the pull request says so and lists the two secrets to add under the repository's Actions settings, plus the API token permissions the deploy needs: Workers Scripts edit and D1 edit on the account.

The agent does not add a test runner in this run. The neighbouring to-do-list-kv-template shows how this repository tests Workers, with vitest and @cloudflare/vitest-pool-workers reading wrangler.jsonc, and the pull request names that as the next step, with the test step already placed in the workflow behind an if that checks for a test script so it starts running the day one is added. It does not change wrangler.json, the migration or the source.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Set up GitHub Actions for this Cloudflare Worker and open a pull request. Read package.json, wrangler.json, tsconfig.json, worker-configuration.d.ts, src/index.ts, the files under migrations/ and the README first. Add .github/workflows/ci.yml with permissions contents read. A check job on pull_request runs actions/checkout, actions/setup-node on Node 22 with npm caching, npm ci, npm run cf-typegen followed by git diff --exit-code on worker-configuration.d.ts, and npm run check. A deploy job on push to main, in a concurrency group, runs the same steps and then npx wrangler d1 migrations apply DB --remote and npx wrangler deploy with CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID from secrets in its env. Add a test step guarded by an if that checks for a test script. Run npm ci, the typegen diff and npm run check in the sandbox, then npm run seedLocalD1 and wrangler dev and request the Worker once to show the seeded rows. Do not change wrangler.json, the migration or the source. In the pull request description paste the check output and the local request, and list the two secrets and the token permissions the deploy job needs.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request that adds one file, .github/workflows/ci.yml. Its description shows the tsc and wrangler deploy --dry-run output from the sandbox, the git diff --exit-code result on the generated types, the local wrangler dev request answering the three seeded comments, and a short list of what to configure before the first push to main: the CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID secrets and the token's permissions. The session keeps every command and its output.

The pull request's own check job is the first run of the workflow on GitHub, so a reviewer sees it green before merging. A reviewer checks that the deploy job is limited to pushes on main, that migrations run before deploy rather than after, that the concurrency group is set, and that no secret is referenced in the pull-request job, which runs on forks without secrets.

Run it on every new Worker repository

Teams that start Workers from a template get the same empty .github each time, so start one run per new repository: a handler on your server that receives GitHub's repository webhook, or a script that reads GET /o/{org}/github for the installation's repositories, calls POST /o/{org}/sessions with this body and the repository URL in resources, with a request_id per repository so a retry returns the run already started.

Give the key a webhook_url and Rush POSTs run.completed, run.failed or run.cancelled when each turn ends, signed per Standard Webhooks, with data.session_url to read for the pull request. A key runs at most max_concurrent sessions at once, 4 by default, and a batch across many Worker repositories can be sent at once: runs past that number are queued with 202 and status: "queued" and start as slots free.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

A Workers deploy workflow is short, and the mistakes are in the order and the gates: migrations after the deploy, secrets exposed to a pull-request job, a stale worker-configuration.d.ts that type-checks against bindings that no longer exist. The agent reads the project's own scripts and wrangler.json, runs the pull-request half in its own sandbox with the real wrangler version from the lock file, and makes a request against the local Worker, so the pull request shows the check passing rather than predicting it.

The result is a workflow that has already run once on the pull request itself, with the deploy half documented down to the two secrets and their permissions. The same request body applies to every Worker a team owns, each in its own sandbox, and adding a vitest job or a staging environment later is a follow-up on the same parked session, with node_modules already installed.

Frequently asked questions

Does the pull-request job need a Cloudflare token?

No. tsc and wrangler deploy --dry-run build the Worker without uploading it, and wrangler types reads only wrangler.json, so the check job runs on forks and without secrets. Only the deploy job on main reads CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID.

Why run the D1 migrations in the workflow?

Because the project's own predeploy script already does it before deploy, and a Worker that ships a query against a table its migration has not created yet fails on its first request. The workflow applies them with --remote before wrangler deploy, in a concurrency group so two pushes cannot interleave.

What happens if I add a binding and forget to regenerate the types?

The check job fails. It runs npm run cf-typegen and then git diff --exit-code worker-configuration.d.ts, so a wrangler.json change that is not reflected in the committed types is caught on the pull request rather than at the first request that reads a binding the Worker does not have.

Will it add tests?

Not in this run. The workflow has a test step that runs only when package.json has a test script, and the pull request points at the vitest and @cloudflare/vitest-pool-workers setup the sibling KV template uses as the way to add one. Writing those tests is a separate request.

More Cloudflare Workers jobs

The same job on other stacks

Keep reading