mirror of
https://github.com/Smile-QWQ/SubTracker.git
synced 2026-06-02 06:59:30 +08:00
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
This commit is contained in:
41
.github/workflows/cf-worker-ci.yml
vendored
41
.github/workflows/cf-worker-ci.yml
vendored
@@ -1,41 +0,0 @@
|
||||
name: CF Worker CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- feat/cf-worker
|
||||
pull_request:
|
||||
branches:
|
||||
- feat/cf-worker
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
verify:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Prisma generate
|
||||
run: npm run prisma:generate
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
- name: Test
|
||||
run: npm test
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
VITE_APP_VERSION: ${{ github.ref_name }}
|
||||
run: npm run build
|
||||
@@ -1,17 +1,74 @@
|
||||
name: Deploy to Cloudflare
|
||||
name: Lite CI and Deploy
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- feat/cf-worker
|
||||
- lite
|
||||
pull_request:
|
||||
branches:
|
||||
- lite
|
||||
|
||||
concurrency:
|
||||
group: deploy-cloudflare-${{ github.repository }}
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
guard:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
run_lite: ${{ steps.branch_check.outputs.run_lite }}
|
||||
|
||||
steps:
|
||||
- name: Check branch scope
|
||||
id: branch_check
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ github.ref_name }}" = "lite" ]; then
|
||||
echo "run_lite=true" >> "$GITHUB_OUTPUT"
|
||||
echo "Running lite workflow for branch: ${{ github.ref_name }}"
|
||||
else
|
||||
echo "run_lite=false" >> "$GITHUB_OUTPUT"
|
||||
echo "::notice::This workflow only deploys the lite branch. Re-run it with branch 'lite'."
|
||||
fi
|
||||
|
||||
verify:
|
||||
if: needs.guard.outputs.run_lite == 'true'
|
||||
needs: guard
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: npm
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Prisma generate
|
||||
run: npm run prisma:generate
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
- name: Test
|
||||
run: npm test
|
||||
|
||||
- name: Build
|
||||
env:
|
||||
VITE_APP_VERSION: ${{ github.ref_name }}
|
||||
run: npm run build
|
||||
|
||||
deploy:
|
||||
if: needs.guard.outputs.run_lite == 'true' && github.event_name != 'pull_request'
|
||||
needs:
|
||||
- guard
|
||||
- verify
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
@@ -34,23 +91,17 @@ jobs:
|
||||
shell: bash
|
||||
run: |
|
||||
NAME_PREFIX="${{ vars.WORKER_NAME_PREFIX }}"
|
||||
ENABLE_KV="${{ vars.ENABLE_KV }}"
|
||||
ENABLE_R2="${{ vars.ENABLE_R2 }}"
|
||||
|
||||
if [ -z "$NAME_PREFIX" ]; then
|
||||
NAME_PREFIX="subtracker"
|
||||
fi
|
||||
|
||||
if [ -z "$ENABLE_KV" ]; then
|
||||
ENABLE_KV="true"
|
||||
fi
|
||||
|
||||
if [ -z "$ENABLE_R2" ]; then
|
||||
ENABLE_R2="false"
|
||||
fi
|
||||
|
||||
echo "name_prefix=$NAME_PREFIX" >> "$GITHUB_OUTPUT"
|
||||
echo "enable_kv=$ENABLE_KV" >> "$GITHUB_OUTPUT"
|
||||
echo "enable_r2=$ENABLE_R2" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Setup Node.js
|
||||
@@ -65,12 +116,6 @@ jobs:
|
||||
- name: Prisma generate
|
||||
run: npm run prisma:generate
|
||||
|
||||
- name: Lint
|
||||
run: npm run lint
|
||||
|
||||
- name: Test
|
||||
run: npm test
|
||||
|
||||
- name: Verify Cloudflare secrets
|
||||
shell: bash
|
||||
env:
|
||||
@@ -87,7 +132,6 @@ jobs:
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
ENABLE_KV: ${{ steps.deploy_options.outputs.enable_kv }}
|
||||
run: >
|
||||
npm run deploy:worker --
|
||||
--name-prefix ${{ steps.deploy_options.outputs.name_prefix }}
|
||||
@@ -98,7 +142,6 @@ jobs:
|
||||
env:
|
||||
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
|
||||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
||||
ENABLE_KV: ${{ steps.deploy_options.outputs.enable_kv }}
|
||||
run: >
|
||||
npm run deploy:worker:r2 --
|
||||
--name-prefix ${{ steps.deploy_options.outputs.name_prefix }}
|
||||
@@ -2,6 +2,7 @@ import Fastify from 'fastify'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const routeMocks = vi.hoisted(() => ({
|
||||
bumpCacheVersions: vi.fn(async () => 0),
|
||||
prisma: {
|
||||
$transaction: vi.fn(async () => {
|
||||
throw new Error('interactive transaction should not be used in worker routes')
|
||||
@@ -39,6 +40,10 @@ vi.mock('../../src/db', () => ({
|
||||
prisma: routeMocks.prisma
|
||||
}))
|
||||
|
||||
vi.mock('../../src/services/cache-version.service', () => ({
|
||||
bumpCacheVersions: routeMocks.bumpCacheVersions
|
||||
}))
|
||||
|
||||
vi.mock('../../src/services/subscription-order.service', () => ({
|
||||
appendSubscriptionOrder: routeMocks.appendSubscriptionOrder,
|
||||
removeSubscriptionOrder: routeMocks.removeSubscriptionOrder,
|
||||
|
||||
@@ -2,6 +2,7 @@ import Fastify from 'fastify'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const tagRouteMocks = vi.hoisted(() => ({
|
||||
bumpCacheVersions: vi.fn(async () => 0),
|
||||
prisma: {
|
||||
subscriptionTag: {
|
||||
deleteMany: vi.fn(async () => ({ count: 1 }))
|
||||
@@ -19,6 +20,10 @@ vi.mock('../../src/db', () => ({
|
||||
prisma: tagRouteMocks.prisma
|
||||
}))
|
||||
|
||||
vi.mock('../../src/services/cache-version.service', () => ({
|
||||
bumpCacheVersions: tagRouteMocks.bumpCacheVersions
|
||||
}))
|
||||
|
||||
describe('tag routes D1 compatibility', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
|
||||
@@ -12,6 +12,7 @@ const serviceMocks = vi.hoisted(() => ({
|
||||
delete: vi.fn()
|
||||
}
|
||||
},
|
||||
bumpCacheVersions: vi.fn(async () => 0),
|
||||
getBaseCurrency: vi.fn(async () => 'CNY'),
|
||||
ensureExchangeRates: vi.fn(async () => ({
|
||||
baseCurrency: 'CNY',
|
||||
@@ -31,6 +32,10 @@ vi.mock('../../src/services/exchange-rate.service', () => ({
|
||||
ensureExchangeRates: serviceMocks.ensureExchangeRates
|
||||
}))
|
||||
|
||||
vi.mock('../../src/services/cache-version.service', () => ({
|
||||
bumpCacheVersions: serviceMocks.bumpCacheVersions
|
||||
}))
|
||||
|
||||
vi.mock('../../src/services/settings.service', () => ({
|
||||
getAppTimezone: serviceMocks.getAppTimezone
|
||||
}))
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { defineConfig } from 'vitest/config'
|
||||
import path from 'node:path'
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
'@subtracker/shared': path.resolve(__dirname, '../../packages/shared/src/index.ts')
|
||||
}
|
||||
},
|
||||
test: {
|
||||
include: ['tests/**/*.test.ts'],
|
||||
environment: 'node'
|
||||
|
||||
@@ -6,7 +6,8 @@ export default defineConfig({
|
||||
plugins: [vue()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src')
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
'@subtracker/shared': path.resolve(__dirname, '../../packages/shared/src/index.ts')
|
||||
}
|
||||
},
|
||||
test: {
|
||||
|
||||
Reference in New Issue
Block a user