Skip to content

Commit 19978ef

Browse files
DennisAlundCopilot
andcommitted
ci: add deploy workflow with migration step
GitHub Actions runs D1 migrations before wrangler deploy, ensuring schema changes land before new worker code goes live. README documents both GitHub Actions and Workers Builds paths, with a note that Workers Builds must use 'yarn deploy' to include the migration step. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 883ccbd commit 19978ef

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

.github/workflows/deploy.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: false
10+
11+
jobs:
12+
deploy:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 24
21+
22+
- name: Install dependencies
23+
run: yarn install --frozen-lockfile
24+
25+
- name: Apply database migrations
26+
run: yarn db:migrate:remote
27+
env:
28+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
29+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
30+
31+
- name: Deploy worker
32+
run: node scripts/resolve-d1-id.js && wrangler deploy
33+
env:
34+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
35+
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ yarn deploy # applies migrations and deploys the Worker
4242

4343
### Continuous deployment
4444

45-
The deploy button sets up [Workers Builds](https://developers.cloudflare.com/workers/ci-cd/builds/) automatically. Cloudflare detects the `deploy` script in `package.json` and uses it as the deploy command. Each push to your production branch applies pending D1 migrations and redeploys the Worker.
45+
The recommended approach is the included GitHub Actions workflow at `.github/workflows/deploy.yml`. It runs D1 migrations before deploying the Worker, which guarantees schema changes land before new code goes live.
46+
47+
To use it, add two secrets to your GitHub repository under **Settings > Secrets and variables > Actions**:
48+
49+
- `CLOUDFLARE_API_TOKEN`: a Cloudflare API token with Worker and D1 edit permissions
50+
- `CLOUDFLARE_ACCOUNT_ID`: your Cloudflare account ID
51+
52+
Every push to `main` then applies pending migrations and redeploys automatically.
53+
54+
**If you use Cloudflare Workers Builds (the deploy button):** by default it runs `wrangler deploy` directly, which skips migrations. Change the build command to `yarn deploy` in your Workers Builds configuration to include the migration step. Go to your Worker in the Cloudflare dashboard, open **Settings > Builds**, and set the deploy command to `yarn deploy`.
4655

4756
## Access Control
4857

0 commit comments

Comments
 (0)