Skip to content

Commit 6815e05

Browse files
committed
ci: 并行化测试检查、缓存 Next.js 与 Electron 构建并精简 standalone 追踪
1 parent 5d39fc5 commit 6815e05

5 files changed

Lines changed: 98 additions & 18 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
cache: 'npm'
5959

6060
- name: Install dependencies
61-
run: npm ci
61+
run: npm ci --no-audit --no-fund
6262

6363
- name: Lint
6464
run: npm run lint
@@ -69,7 +69,8 @@ jobs:
6969
integration-test:
7070
runs-on: ubuntu-latest
7171
name: Integration Tests
72-
needs: unit-test
72+
needs: publication-check
73+
if: "!startsWith(github.ref, 'refs/tags/')"
7374
steps:
7475
- name: Checkout repository
7576
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
@@ -81,7 +82,7 @@ jobs:
8182
cache: 'npm'
8283

8384
- name: Install dependencies
84-
run: npm ci
85+
run: npm ci --no-audit --no-fund
8586

8687
- name: Generate Prisma Client
8788
run: npx prisma generate
@@ -92,7 +93,8 @@ jobs:
9293
coverage:
9394
runs-on: ubuntu-latest
9495
name: Test Coverage
95-
needs: unit-test
96+
needs: publication-check
97+
if: "!startsWith(github.ref, 'refs/tags/')"
9698
steps:
9799
- name: Checkout repository
98100
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
@@ -104,7 +106,7 @@ jobs:
104106
cache: 'npm'
105107

106108
- name: Install dependencies
107-
run: npm ci
109+
run: npm ci --no-audit --no-fund
108110

109111
- name: Generate Prisma Client
110112
run: npx prisma generate
@@ -135,7 +137,8 @@ jobs:
135137
build-check:
136138
runs-on: ubuntu-latest
137139
name: Build Check
138-
needs: integration-test
140+
needs: publication-check
141+
if: "!startsWith(github.ref, 'refs/tags/')"
139142
steps:
140143
- name: Checkout repository
141144
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
@@ -146,8 +149,17 @@ jobs:
146149
node-version: '24'
147150
cache: 'npm'
148151

152+
- name: Cache Next.js build
153+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
154+
with:
155+
path: ${{ github.workspace }}/.next/cache
156+
key: nextjs-${{ runner.os }}-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
157+
restore-keys: |
158+
nextjs-${{ runner.os }}-${{ hashFiles('package-lock.json') }}-
159+
nextjs-${{ runner.os }}-
160+
149161
- name: Install dependencies
150-
run: npm ci
162+
run: npm ci --no-audit --no-fund
151163

152164
- name: Generate Prisma Client
153165
run: npx prisma generate
@@ -158,7 +170,7 @@ jobs:
158170
e2e-test:
159171
runs-on: ubuntu-latest
160172
name: E2E Tests
161-
needs: build-check
173+
needs: [unit-test, integration-test, build-check]
162174
timeout-minutes: 60
163175
env:
164176
DATABASE_URL: "file:./e2e.db"
@@ -174,11 +186,20 @@ jobs:
174186
node-version: '24'
175187
cache: 'npm'
176188

189+
- name: Cache Next.js build
190+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
191+
with:
192+
path: ${{ github.workspace }}/.next/cache
193+
key: nextjs-${{ runner.os }}-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
194+
restore-keys: |
195+
nextjs-${{ runner.os }}-${{ hashFiles('package-lock.json') }}-
196+
nextjs-${{ runner.os }}-
197+
177198
- name: Install dependencies
178-
run: npm ci
199+
run: npm ci --no-audit --no-fund
179200

180201
- name: Install Playwright Browsers
181-
run: npx playwright install --with-deps
202+
run: npx playwright install --with-deps chromium
182203

183204
- name: Setup Database
184205
run: |

‎.github/workflows/packages.yml‎

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ jobs:
3737
echo "PACKAGE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
3838
fi
3939
40-
- run: npm ci
40+
- name: Cache Next.js build
41+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
42+
with:
43+
path: ${{ github.workspace }}/.next/cache
44+
key: nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
45+
restore-keys: |
46+
nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-
47+
nextjs-${{ runner.os }}-${{ runner.arch }}-
48+
49+
- run: npm ci --no-audit --no-fund
4150

4251
- name: Build bundle and npm package
4352
run: |
@@ -152,7 +161,23 @@ jobs:
152161
sudo gem install --no-document fpm
153162
echo "USE_SYSTEM_FPM=true" >> "$GITHUB_ENV"
154163
155-
- run: npm ci
164+
- name: Cache Next.js and Electron binaries
165+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
166+
with:
167+
path: |
168+
${{ github.workspace }}/.next/cache
169+
~/.cache/electron
170+
~/.cache/electron-builder
171+
~/Library/Caches/electron
172+
~/Library/Caches/electron-builder
173+
~/AppData/Local/electron/Cache
174+
~/AppData/Local/electron-builder/Cache
175+
key: desktop-${{ matrix.name }}-${{ hashFiles('package-lock.json', 'packaging/desktop/package.json') }}-${{ github.sha }}
176+
restore-keys: |
177+
desktop-${{ matrix.name }}-${{ hashFiles('package-lock.json', 'packaging/desktop/package.json') }}-
178+
desktop-${{ matrix.name }}-
179+
180+
- run: npm ci --no-audit --no-fund
156181

157182
- name: Build bundle
158183
run: node scripts/package/build.mjs bundle
@@ -270,7 +295,16 @@ jobs:
270295
echo "${{ matrix.sha256 }} /usr/local/bin/fnpack" | sha256sum -c -
271296
chmod +x /usr/local/bin/fnpack
272297
273-
- run: npm ci
298+
- name: Cache Next.js build
299+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
300+
with:
301+
path: ${{ github.workspace }}/.next/cache
302+
key: nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
303+
restore-keys: |
304+
nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-
305+
nextjs-${{ runner.os }}-${{ runner.arch }}-
306+
307+
- run: npm ci --no-audit --no-fund
274308

275309
- name: Build fpk
276310
run: |
@@ -314,7 +348,16 @@ jobs:
314348
echo "PACKAGE_VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
315349
fi
316350
317-
- run: npm ci
351+
- name: Cache Next.js build
352+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
353+
with:
354+
path: ${{ github.workspace }}/.next/cache
355+
key: nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-${{ github.sha }}
356+
restore-keys: |
357+
nextjs-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}-
358+
nextjs-${{ runner.os }}-${{ runner.arch }}-
359+
360+
- run: npm ci --no-audit --no-fund
318361

319362
# 单机版内置的服务端与其他安装包相同
320363
- name: Build bundle

‎Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ WORKDIR /app
1212
COPY package.json package-lock.json ./
1313
COPY prisma/schema.prisma ./prisma/schema.prisma
1414
RUN --mount=type=cache,target=/root/.npm \
15-
npm ci && npx prisma generate
15+
npm ci --no-audit --no-fund && npx prisma generate
1616

1717
# Pre-compile runtime scripts and initialize seed database in an isolated stage
1818
# so code-only changes reuse the cached database layer and BuildKit can run it in parallel.

‎next.config.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ export const securityHeaders = [
1717
const nextConfig: NextConfig = {
1818
output: 'standalone',
1919
serverExternalPackages: ['@prisma/client', 'bcryptjs'],
20+
// 排除因 process.cwd() 动态路径被文件追踪误扫入 standalone 的开发、测试与打包目录
21+
outputFileTracingExcludes: {
22+
'*': [
23+
'./src/**/*',
24+
'./e2e/**/*',
25+
'./tests/**/*',
26+
'./coverage/**/*',
27+
'./packaging/**/*',
28+
'./dist/**/*',
29+
'./dist-scripts/**/*',
30+
'./doc/**/*',
31+
'./perf/**/*',
32+
'./scripts/**/*',
33+
'./.git/**/*',
34+
],
35+
},
2036
// 禁止 next dev 自动向 AGENTS.md / CLAUDE.md 写入 agent-rules 段落
2137
agentRules: false,
2238
poweredByHeader: false,

‎scripts/package/build.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ function buildBundle() {
192192
log('组装 dist/bundle');
193193
rm(BUNDLE);
194194
copy(standalone, BUNDLE);
195-
// standalone 可能带入本机的 .env、配置文件和数据库,全部移除,避免把密钥打进安装包
195+
// standalone 仅保留运行时必需的顶层项,移除可能带入的本机配置、数据库及开发目录
196+
const allowedTopLevel = new Set(['server.js', 'package.json', '.next', 'node_modules']);
196197
for (const entry of fs.readdirSync(BUNDLE)) {
197-
if (entry.startsWith('.env') || /\.(db|db-journal|sqlite)$/.test(entry)) rm(path.join(BUNDLE, entry));
198+
if (!allowedTopLevel.has(entry)) rm(path.join(BUNDLE, entry));
198199
}
199-
for (const dir of ['config', 'data', 'prisma', 'certs', 'dist-scripts']) rm(path.join(BUNDLE, dir));
200200
// 外部包别名链接由 launcher.js 在运行时解析(见 installExternalAliasResolver)
201201
rm(path.join(BUNDLE, '.next', 'node_modules'));
202202

0 commit comments

Comments
 (0)