Skip to content

Commit 6f0d588

Browse files
committed
ci: streamline lite workflow and test wiring
- merge the lite verify and deploy flow into a single workflow entry - rename the workflow file to Lite CI and Deploy and drop the old cf-worker path - fix route and service tests plus Vitest shared-package resolution for clean CI runs
1 parent 814464b commit 6f0d588

7 files changed

Lines changed: 60 additions & 58 deletions

File tree

.github/workflows/cf-worker-ci.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,52 @@
1-
name: Deploy to Cloudflare
1+
name: Lite CI and Deploy
22

33
on:
44
workflow_dispatch:
55
push:
66
branches:
7-
- feat/cf-worker
7+
- lite
8+
pull_request:
9+
branches:
10+
- lite
811

912
concurrency:
1013
group: deploy-cloudflare-${{ github.repository }}
1114
cancel-in-progress: false
1215

1316
jobs:
17+
verify:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 20
28+
cache: npm
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Prisma generate
34+
run: npm run prisma:generate
35+
36+
- name: Lint
37+
run: npm run lint
38+
39+
- name: Test
40+
run: npm test
41+
42+
- name: Build
43+
env:
44+
VITE_APP_VERSION: ${{ github.ref_name }}
45+
run: npm run build
46+
1447
deploy:
48+
if: github.event_name != 'pull_request'
49+
needs: verify
1550
runs-on: ubuntu-latest
1651
permissions:
1752
contents: read
@@ -34,23 +69,17 @@ jobs:
3469
shell: bash
3570
run: |
3671
NAME_PREFIX="${{ vars.WORKER_NAME_PREFIX }}"
37-
ENABLE_KV="${{ vars.ENABLE_KV }}"
3872
ENABLE_R2="${{ vars.ENABLE_R2 }}"
3973
4074
if [ -z "$NAME_PREFIX" ]; then
4175
NAME_PREFIX="subtracker"
4276
fi
4377
44-
if [ -z "$ENABLE_KV" ]; then
45-
ENABLE_KV="true"
46-
fi
47-
4878
if [ -z "$ENABLE_R2" ]; then
4979
ENABLE_R2="false"
5080
fi
5181
5282
echo "name_prefix=$NAME_PREFIX" >> "$GITHUB_OUTPUT"
53-
echo "enable_kv=$ENABLE_KV" >> "$GITHUB_OUTPUT"
5483
echo "enable_r2=$ENABLE_R2" >> "$GITHUB_OUTPUT"
5584
5685
- name: Setup Node.js
@@ -65,12 +94,6 @@ jobs:
6594
- name: Prisma generate
6695
run: npm run prisma:generate
6796

68-
- name: Lint
69-
run: npm run lint
70-
71-
- name: Test
72-
run: npm test
73-
7497
- name: Verify Cloudflare secrets
7598
shell: bash
7699
env:
@@ -87,7 +110,6 @@ jobs:
87110
env:
88111
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
89112
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
90-
ENABLE_KV: ${{ steps.deploy_options.outputs.enable_kv }}
91113
run: >
92114
npm run deploy:worker --
93115
--name-prefix ${{ steps.deploy_options.outputs.name_prefix }}
@@ -98,7 +120,6 @@ jobs:
98120
env:
99121
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
100122
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
101-
ENABLE_KV: ${{ steps.deploy_options.outputs.enable_kv }}
102123
run: >
103124
npm run deploy:worker:r2 --
104125
--name-prefix ${{ steps.deploy_options.outputs.name_prefix }}

apps/api/tests/integration/subscriptions-routes.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Fastify from 'fastify'
22
import { beforeEach, describe, expect, it, vi } from 'vitest'
33

44
const routeMocks = vi.hoisted(() => ({
5+
bumpCacheVersions: vi.fn(async () => 0),
56
prisma: {
67
$transaction: vi.fn(async () => {
78
throw new Error('interactive transaction should not be used in worker routes')
@@ -39,6 +40,10 @@ vi.mock('../../src/db', () => ({
3940
prisma: routeMocks.prisma
4041
}))
4142

43+
vi.mock('../../src/services/cache-version.service', () => ({
44+
bumpCacheVersions: routeMocks.bumpCacheVersions
45+
}))
46+
4247
vi.mock('../../src/services/subscription-order.service', () => ({
4348
appendSubscriptionOrder: routeMocks.appendSubscriptionOrder,
4449
removeSubscriptionOrder: routeMocks.removeSubscriptionOrder,

apps/api/tests/integration/tags-routes.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Fastify from 'fastify'
22
import { beforeEach, describe, expect, it, vi } from 'vitest'
33

44
const tagRouteMocks = vi.hoisted(() => ({
5+
bumpCacheVersions: vi.fn(async () => 0),
56
prisma: {
67
subscriptionTag: {
78
deleteMany: vi.fn(async () => ({ count: 1 }))
@@ -19,6 +20,10 @@ vi.mock('../../src/db', () => ({
1920
prisma: tagRouteMocks.prisma
2021
}))
2122

23+
vi.mock('../../src/services/cache-version.service', () => ({
24+
bumpCacheVersions: tagRouteMocks.bumpCacheVersions
25+
}))
26+
2227
describe('tag routes D1 compatibility', () => {
2328
beforeEach(() => {
2429
vi.resetModules()

apps/api/tests/unit/subscription.service.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const serviceMocks = vi.hoisted(() => ({
1212
delete: vi.fn()
1313
}
1414
},
15+
bumpCacheVersions: vi.fn(async () => 0),
1516
getBaseCurrency: vi.fn(async () => 'CNY'),
1617
ensureExchangeRates: vi.fn(async () => ({
1718
baseCurrency: 'CNY',
@@ -31,6 +32,10 @@ vi.mock('../../src/services/exchange-rate.service', () => ({
3132
ensureExchangeRates: serviceMocks.ensureExchangeRates
3233
}))
3334

35+
vi.mock('../../src/services/cache-version.service', () => ({
36+
bumpCacheVersions: serviceMocks.bumpCacheVersions
37+
}))
38+
3439
vi.mock('../../src/services/settings.service', () => ({
3540
getAppTimezone: serviceMocks.getAppTimezone
3641
}))

apps/api/vitest.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { defineConfig } from 'vitest/config'
2+
import path from 'node:path'
23

34
export default defineConfig({
5+
resolve: {
6+
alias: {
7+
'@subtracker/shared': path.resolve(__dirname, '../../packages/shared/src/index.ts')
8+
}
9+
},
410
test: {
511
include: ['tests/**/*.test.ts'],
612
environment: 'node'

apps/web/vitest.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export default defineConfig({
66
plugins: [vue()],
77
resolve: {
88
alias: {
9-
'@': path.resolve(__dirname, './src')
9+
'@': path.resolve(__dirname, './src'),
10+
'@subtracker/shared': path.resolve(__dirname, '../../packages/shared/src/index.ts')
1011
}
1112
},
1213
test: {

0 commit comments

Comments
 (0)