Skip to content

Commit aec96f3

Browse files
authored
Merge pull request #157 from mahata/opencode/witty-lagoon
feat: add automated deployment workflow for prod branch
2 parents 70d94dd + 5e6162b commit aec96f3

2 files changed

Lines changed: 146 additions & 2 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Deploy to Production
2+
3+
on:
4+
push:
5+
branches: [prod]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-24.04
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v5
14+
15+
- name: Enable corepack
16+
run: corepack enable
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v5
20+
with:
21+
node-version-file: ".node-version"
22+
cache: "pnpm"
23+
cache-dependency-path: "pnpm-lock.yaml"
24+
25+
- name: Install dependencies
26+
run: pnpm install --frozen-lockfile
27+
28+
- name: Run tests
29+
run: pnpm test:run
30+
31+
- name: Run linter (without build artifacts)
32+
run: rm -rf dist && rm -f hono/static/*.js hono/static/*.js.map && pnpm lint
33+
34+
- name: Run build
35+
run: pnpm build
36+
37+
e2e:
38+
runs-on: ubuntu-24.04
39+
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@v5
43+
44+
- name: Enable corepack
45+
run: corepack enable
46+
47+
- name: Setup Node.js
48+
uses: actions/setup-node@v5
49+
with:
50+
node-version-file: ".node-version"
51+
cache: "pnpm"
52+
cache-dependency-path: "pnpm-lock.yaml"
53+
54+
- name: Install dependencies
55+
run: pnpm install --frozen-lockfile
56+
57+
- name: Install Playwright Browsers
58+
run: pnpm exec playwright install --with-deps chromium
59+
60+
- name: Build JavaScript files
61+
run: pnpm build
62+
63+
- name: Run database migrations
64+
run: pnpm db:migrate
65+
66+
- name: Seed database
67+
run: pnpm db:seed
68+
69+
- name: Run Playwright tests
70+
env:
71+
SESSION_SECRET: ${{ secrets.SESSION_SECRET }}
72+
E2E_GMAIL_ACCOUNT: ${{ secrets.E2E_GMAIL_ACCOUNT }}
73+
E2E_GMAIL_PASSWORD: ${{ secrets.E2E_GMAIL_PASSWORD }}
74+
run: pnpm test:e2e
75+
76+
- name: Upload test artifacts
77+
uses: actions/upload-artifact@v5
78+
if: failure()
79+
with:
80+
name: playwright-report
81+
path: playwright-report/
82+
retention-days: 30
83+
84+
deploy:
85+
needs: [test, e2e]
86+
runs-on: ubuntu-24.04
87+
88+
steps:
89+
- name: Checkout code
90+
uses: actions/checkout@v5
91+
92+
- name: Enable corepack
93+
run: corepack enable
94+
95+
- name: Setup Node.js
96+
uses: actions/setup-node@v5
97+
with:
98+
node-version-file: ".node-version"
99+
cache: "pnpm"
100+
cache-dependency-path: "pnpm-lock.yaml"
101+
102+
- name: Install dependencies
103+
run: pnpm install --frozen-lockfile
104+
105+
- name: Apply D1 database migrations
106+
run: pnpm db:migrate:prod
107+
env:
108+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
109+
110+
- name: Deploy to Cloudflare Workers
111+
run: pnpm run deploy
112+
env:
113+
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,40 @@ pnpm lint:fix
153153
pnpm run deploy
154154
```
155155

156-
### Subsequent Deployments
156+
### Automated Deployment (CI/CD)
157157

158-
After the initial setup, deploy with:
158+
Production deployments are automated via GitHub Actions. Pushing to the `prod` branch triggers the deployment pipeline defined in `.github/workflows/deploy.yml`.
159+
160+
**Pipeline overview:**
161+
162+
1. **`test` job** — Runs unit tests, linter, and full build
163+
2. **`e2e` job** — Runs Playwright E2E tests (in parallel with `test`)
164+
3. **`deploy` job** — Applies D1 migrations and deploys to Cloudflare Workers (only runs after both `test` and `e2e` pass)
165+
166+
**Typical workflow:**
167+
168+
```bash
169+
# Merge main into prod to trigger a deployment
170+
git checkout prod
171+
git merge main
172+
git push origin prod
173+
```
174+
175+
**Required GitHub secret:**
176+
177+
The deploy job authenticates with Cloudflare using the `CLOUDFLARE_API_TOKEN` repository secret. To set it up:
178+
179+
1. Go to [Cloudflare Dashboard > API Tokens](https://dash.cloudflare.com/profile/api-tokens) and create a token with these permissions:
180+
- **Workers Scripts: Edit**
181+
- **D1: Edit**
182+
- **Account Settings: Read**
183+
2. Add the token as `CLOUDFLARE_API_TOKEN` in your GitHub repository under **Settings > Secrets and variables > Actions > New repository secret**
184+
185+
The E2E job reuses the existing `SESSION_SECRET`, `E2E_GMAIL_ACCOUNT`, and `E2E_GMAIL_PASSWORD` secrets already configured for CI.
186+
187+
### Manual Deployment
188+
189+
You can still deploy manually if needed:
159190

160191
```bash
161192
pnpm run deploy

0 commit comments

Comments
 (0)