From f06f635ca67a41863fddb4ec36bbfb53b02e4784 Mon Sep 17 00:00:00 2001 From: SmileQWQ Date: Sun, 26 Apr 2026 20:42:36 +0800 Subject: [PATCH] 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 --- .github/workflows/cf-worker-ci.yml | 41 ---------- ...rker-deploy.yml => lite-ci-and-deploy.yml} | 75 +++++++++++++++---- .../integration/subscriptions-routes.test.ts | 5 ++ .../api/tests/integration/tags-routes.test.ts | 5 ++ .../tests/unit/subscription.service.test.ts | 5 ++ apps/api/vitest.config.ts | 6 ++ apps/web/vitest.config.ts | 3 +- 7 files changed, 82 insertions(+), 58 deletions(-) delete mode 100644 .github/workflows/cf-worker-ci.yml rename .github/workflows/{cf-worker-deploy.yml => lite-ci-and-deploy.yml} (66%) diff --git a/.github/workflows/cf-worker-ci.yml b/.github/workflows/cf-worker-ci.yml deleted file mode 100644 index 8b56573..0000000 --- a/.github/workflows/cf-worker-ci.yml +++ /dev/null @@ -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 diff --git a/.github/workflows/cf-worker-deploy.yml b/.github/workflows/lite-ci-and-deploy.yml similarity index 66% rename from .github/workflows/cf-worker-deploy.yml rename to .github/workflows/lite-ci-and-deploy.yml index 37f5493..3ac3f24 100644 --- a/.github/workflows/cf-worker-deploy.yml +++ b/.github/workflows/lite-ci-and-deploy.yml @@ -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 }} diff --git a/apps/api/tests/integration/subscriptions-routes.test.ts b/apps/api/tests/integration/subscriptions-routes.test.ts index 777d71a..633014b 100644 --- a/apps/api/tests/integration/subscriptions-routes.test.ts +++ b/apps/api/tests/integration/subscriptions-routes.test.ts @@ -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, diff --git a/apps/api/tests/integration/tags-routes.test.ts b/apps/api/tests/integration/tags-routes.test.ts index 23f3195..3182c0e 100644 --- a/apps/api/tests/integration/tags-routes.test.ts +++ b/apps/api/tests/integration/tags-routes.test.ts @@ -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() diff --git a/apps/api/tests/unit/subscription.service.test.ts b/apps/api/tests/unit/subscription.service.test.ts index 3ba427b..a66a642 100644 --- a/apps/api/tests/unit/subscription.service.test.ts +++ b/apps/api/tests/unit/subscription.service.test.ts @@ -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 })) diff --git a/apps/api/vitest.config.ts b/apps/api/vitest.config.ts index ec9809a..51b6636 100644 --- a/apps/api/vitest.config.ts +++ b/apps/api/vitest.config.ts @@ -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' diff --git a/apps/web/vitest.config.ts b/apps/web/vitest.config.ts index 1518f97..7f56189 100644 --- a/apps/web/vitest.config.ts +++ b/apps/web/vitest.config.ts @@ -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: {