-
Notifications
You must be signed in to change notification settings - Fork 1
459 lines (410 loc) · 17 KB
/
ci.yaml
File metadata and controls
459 lines (410 loc) · 17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
name: CI
on:
pull_request:
branches: [ main ]
paths:
- '.github/workflows/ci.yaml'
- '**/*.kt'
env:
# 🚀 优化后的 Gradle 配置 - 提升构建性能
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.parallel=true -Dorg.gradle.workers.max=8 -Dkotlin.incremental=true -Dorg.gradle.configuration-cache=true -Dorg.gradle.build-cache=true -Dorg.gradle.caching=true"
# 🎯 JVM 性能优化配置 - 针对 GitHub Actions 7GB 内存环境调优
JVM_OPTS: "-Xmx5g -XX:MaxMetaspaceSize=1g -XX:+UseG1GC -XX:G1HeapRegionSize=32m -XX:+UseStringDeduplication -XX:+UnlockExperimentalVMOptions -XX:+UseZGC -XX:+UseLargePages"
# 🐳 Docker 和 TestContainers 优化
TESTCONTAINERS_RYUK_DISABLED: false
TESTCONTAINERS_REUSE_ENABLE: true
DOCKER_BUILDKIT: 1
jobs:
# 🔍 快速检查 - 编译和基础验证
quick-check:
name: "🔍 Quick Check"
runs-on: ubuntu-latest
timeout-minutes: 8
outputs:
cache-key: ${{ steps.cache-info.outputs.cache-key }}
gradle-cache-key: ${{ steps.cache-info.outputs.gradle-cache-key }}
steps:
- name: Checkout code
uses: actions/checkout@v5.0.0
with:
fetch-depth: 1 # 浅克隆提升速度
- name: Set up JDK 24
uses: actions/setup-java@v5.0.0
with:
java-version: '24'
distribution: 'graalvm'
cache: gradle
- name: 📊 Cache info
id: cache-info
run: |
# 生成更精确的缓存键
GRADLE_CACHE_KEY="${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties', 'gradle/libs.versions.toml', 'build-logic/**/*') }}"
DEPS_CACHE_KEY="${{ runner.os }}-deps-${{ hashFiles('gradle/libs.versions.toml', '**/build.gradle.kts') }}"
echo "cache-key=$GRADLE_CACHE_KEY" >> $GITHUB_OUTPUT
echo "gradle-cache-key=$DEPS_CACHE_KEY" >> $GITHUB_OUTPUT
- name: 🎯 Cache Gradle wrapper and distributions
uses: actions/cache@v4
with:
path: |
~/.gradle/wrapper
~/.gradle/caches/jars-*
~/.gradle/caches/modules-*
key: ${{ steps.cache-info.outputs.gradle-cache-key }}
restore-keys: |
${{ runner.os }}-deps-
${{ runner.os }}-gradle-
- name: 📦 Cache build outputs
uses: actions/cache@v4
with:
path: |
~/.gradle/caches/build-cache-*
~/.gradle/buildOutputCleanup
**/build/classes
**/build/generated
key: ${{ steps.cache-info.outputs.cache-key }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: '9.0.0'
cache-read-only: false
cache-write-only: false
- name: Grant execute permission
run: chmod +x gradlew
- name: 🚀 Quick compile with optimizations
run: |
# 预热 Gradle daemon 并编译
./gradlew help --quiet
./gradlew compileKotlin compileTestKotlin \
--no-daemon \
--parallel \
--build-cache \
--configuration-cache \
--quiet
# 🧪 优化后的并行测试矩阵 - 重新分组以提升并行效率
test-matrix:
name: "🧪 Test"
needs: quick-check
runs-on: ubuntu-latest
timeout-minutes: 25
strategy:
fail-fast: false
max-parallel: 6 # 增加并行度
matrix:
group:
- "core-fast" # 快速核心模块
- "core-build" # 构建相关模块
- "rds-light" # 轻量数据库模块
- "rds-heavy" # 重量数据库模块
- "business-ai" # AI 和支付模块
- "business-oss" # 对象存储模块
- "business-misc" # 其他业务模块
- "security" # 安全模块
- "data-depend" # 数据和依赖模块
include:
- group: "core-fast"
modules: "shared testtoolkit"
containers: "none"
timeout: 8
- group: "core-build"
modules: "gradle-plugin version-catalog bom"
containers: "none"
timeout: 10
- group: "rds-light"
modules: "rds:rds-shared rds:rds-flyway-migration-shared"
containers: "none"
timeout: 8
- group: "rds-heavy"
modules: "rds:rds-crud rds:rds-jimmer-ext-postgres rds:rds-flyway-migration-postgresql rds:rds-flyway-migration-mysql8"
containers: "database"
timeout: 20
- group: "business-ai"
modules: "ai:ai-shared ai:ai-langchain4j pay:pay-shared pay:pay-wechat"
containers: "cache"
timeout: 15
- group: "business-oss"
modules: "oss:oss-shared oss:oss-minio oss:oss-aliyun-oss oss:oss-huawei-obs oss:oss-volcengine-tos"
containers: "cache"
timeout: 18
- group: "business-misc"
modules: "sms:sms-shared sms:sms-tencent surveillance:surveillance-shared surveillance:surveillance-hikvision cacheable"
containers: "cache"
timeout: 12
- group: "security"
modules: "security:security-crypto security:security-oauth2 security:security-spring"
containers: "none"
timeout: 10
- group: "data-depend"
modules: "data:data-crawler data:data-extract depend:depend-http-exchange depend:depend-jackson depend:depend-paho depend:depend-servlet depend:depend-springdoc-openapi depend:depend-xxl-job ksp:ksp-meta ksp:ksp-plugin ksp:ksp-shared psdk:psdk-wxpa"
containers: "none"
timeout: 15
steps:
- name: Checkout code
uses: actions/checkout@v5.0.0
with:
fetch-depth: 1 # 浅克隆
- name: Set up JDK 24
uses: actions/setup-java@v5.0.0
with:
java-version: '24'
distribution: 'graalvm'
cache: gradle
- name: 🎯 Restore Gradle wrapper cache
uses: actions/cache/restore@v4
with:
path: |
~/.gradle/wrapper
~/.gradle/caches/jars-*
~/.gradle/caches/modules-*
key: ${{ needs.quick-check.outputs.gradle-cache-key }}
restore-keys: |
${{ runner.os }}-deps-
${{ runner.os }}-gradle-
- name: 📦 Restore build cache
uses: actions/cache/restore@v4
with:
path: |
~/.gradle/caches/build-cache-*
~/.gradle/buildOutputCleanup
**/build/classes
**/build/generated
key: ${{ needs.quick-check.outputs.cache-key }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: '9.0.0'
cache-read-only: true
cache-write-only: false
# 🐳 优化的 Docker 设置
- name: Set up Docker Buildx
if: matrix.containers != 'none'
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
network=host
image=moby/buildkit:v0.12.0
- name: 🗂️ Cache Docker layers
if: matrix.containers != 'none'
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ matrix.group }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-docker-${{ matrix.group }}-
${{ runner.os }}-docker-
# 🚀 并行预拉取数据库镜像 - 使用更轻量的镜像
- name: Pre-pull database images
if: matrix.containers == 'database'
run: |
echo "🐘 拉取数据库镜像..."
docker pull postgres:16-alpine &
docker pull mysql:8.0 &
docker pull redis:7-alpine &
wait
echo "✅ 数据库镜像拉取完成"
continue-on-error: true
# 🗄️ 预拉取缓存相关镜像
- name: Pre-pull cache images
if: matrix.containers == 'cache'
run: |
echo "📦 拉取缓存镜像..."
docker pull redis:7-alpine &
docker pull minio/minio:RELEASE.2024-01-16T16-07-38Z &
wait
echo "✅ 缓存镜像拉取完成"
continue-on-error: true
- name: Grant execute permission
run: chmod +x gradlew
- name: 🧪 Run tests for ${{ matrix.group }} modules
timeout-minutes: ${{ matrix.timeout }}
run: |
echo "🚀 开始执行 ${{ matrix.group }} 模块组测试..."
echo "📚 模块列表: ${{ matrix.modules }}"
echo "🐳 容器配置: ${{ matrix.containers }}"
echo "⏱️ 超时设置: ${{ matrix.timeout }} 分钟"
# 设置错误处理
set -e
trap 'echo "❌ 测试执行失败,正在收集错误信息..." >> $GITHUB_STEP_SUMMARY' ERR
# 预热 Gradle
./gradlew help --quiet
# 将模块名转换为测试任务
modules="${{ matrix.modules }}"
test_tasks=""
for module in $modules; do
if [[ "$module" == *":"* ]]; then
# 子模块格式 (如 rds:rds-shared)
test_tasks="$test_tasks :$module:test"
else
# 根级模块格式 (如 shared)
test_tasks="$test_tasks :$module:test"
fi
done
echo "🎯 执行测试任务: $test_tasks"
./gradlew $test_tasks \
--no-daemon \
--parallel \
--build-cache \
--configuration-cache \
--continue \
--quiet \
-Dorg.gradle.workers.max=4 \
-Dorg.gradle.jvmargs="-Xmx3g -XX:MaxMetaspaceSize=768m"
env:
# 🐳 TestContainers 优化配置
TESTCONTAINERS_RYUK_DISABLED: false
TESTCONTAINERS_CHECKS_DISABLE: false
TESTCONTAINERS_REUSE_ENABLE: true
TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX: ""
TESTCONTAINERS_REUSE_HASH_LABELS: true
# ⏱️ TestContainers 超时和启动配置 - 优化启动时间
TESTCONTAINERS_PULL_PAUSE_TIMEOUT: 20
TESTCONTAINERS_STARTUP_TIMEOUT: 90
TESTCONTAINERS_CONNECT_TIMEOUT: 30
# 🚀 Docker 性能优化
DOCKER_HOST: unix:///var/run/docker.sock
TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE: /var/run/docker.sock
TESTCONTAINERS_HOST_OVERRIDE: localhost
DOCKER_BUILDKIT: 1
BUILDKIT_PROGRESS: plain
# 🎯 JVM 性能调优 - 针对测试环境优化
GRADLE_OPTS: "${{ env.GRADLE_OPTS }}"
JAVA_OPTS: "${{ env.JVM_OPTS }}"
# 🔧 CI 环境配置
CI: true
GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: false
# 📊 测试并行配置
JUNIT_PLATFORM_EXECUTION_PARALLEL_ENABLED: true
JUNIT_PLATFORM_EXECUTION_PARALLEL_MODE_DEFAULT: concurrent
- name: Collect test diagnostics
if: failure()
run: |
echo "🔍 收集测试诊断信息..."
# 收集 Gradle 构建日志
find . -name "*.log" -type f -exec echo "=== {} ===" \; -exec cat {} \; || true
# 收集容器日志
if [[ "${{ matrix.containers }}" != "none" ]]; then
echo "🐳 收集容器日志..."
docker ps -a || true
docker logs $(docker ps -aq --filter "label=org.testcontainers=true") || true
fi
# JVM 堆转储和线程信息
if pgrep -f "org.gradle.launcher.daemon.bootstrap.GradleDaemon" > /dev/null; then
echo "👍 收集 JVM 诊断信息..."
jps -v || true
fi
# 系统资源使用
echo "📈 系统资源使用:"
free -h || true
df -h || true
- name: Upload test results and diagnostics
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.group }}
path: |
**/build/reports/tests/
**/build/test-results/
**/build/tmp/test/
**/*.log
retention-days: 5
- name: 🧼 Smart cleanup containers
if: always() && matrix.containers != 'none'
run: |
echo "🧼 开始智能清理 Docker 资源..."
# 显示当前资源使用情况
echo "📈 当前 Docker 资源使用情况:"
docker system df || true
# 智能清理:保留重用容器,清理测试容器
echo "🗑️ 清理测试容器(保留重用容器)..."
docker container prune -f --filter "until=30m" --filter "label!=org.testcontainers.reuse.enable=true" || true
# 清理悬空镜像(但保留基础镜像)
echo "🖼️ 清理悬空镜像..."
docker image prune -f --filter "dangling=true" || true
# 清理测试网络
echo "🌐 清理测试网络..."
docker network prune -f --filter "until=30m" || true
# 清理临时卷
echo "💾 清理临时卷..."
docker volume prune -f --filter "label!=keep" --filter "label!=org.testcontainers.reuse.enable=true" || true
# 显示清理后的资源情况
echo "✨ 清理后 Docker 资源使用情况:"
docker system df || true
# 📊 测试结果汇总
test-results:
name: "📊 Test Results Summary"
needs: [ quick-check, test-matrix ]
runs-on: ubuntu-latest
if: always()
steps:
- name: Download all test results
uses: actions/download-artifact@v5.0.0
with:
path: test-results
pattern: test-results-*
- name: Generate comprehensive test summary
run: |
echo "# 🧪 测试结果详细报告" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**执行时间:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
echo "**测试环境:** GitHub Actions (ubuntu-latest)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📈 模块组测试状态" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| 模块组 | 状态 | 容器依赖 | 耗时 |" >> $GITHUB_STEP_SUMMARY
echo "|---------|--------|----------|------|" >> $GITHUB_STEP_SUMMARY
# 模块组信息 - 更新为新的分组
declare -A group_containers=(
["core-fast"]="无"
["core-build"]="无"
["rds-light"]="无"
["rds-heavy"]="Database (PostgreSQL, MySQL, Redis)"
["business-ai"]="Cache (Redis)"
["business-oss"]="Cache (Redis, MinIO)"
["business-misc"]="Cache (Redis)"
["security"]="无"
["data-depend"]="无"
)
for group in core-fast core-build rds-light rds-heavy business-ai business-oss business-misc security data-depend; do
containers="${group_containers[$group]}"
if [[ "${{ needs.test-matrix.result }}" == "success" ]]; then
echo "| $group | ✅ 通过 | $containers | - |" >> $GITHUB_STEP_SUMMARY
else
echo "| $group | ❌ 失败 | $containers | - |" >> $GITHUB_STEP_SUMMARY
fi
done
echo "" >> $GITHUB_STEP_SUMMARY
# 添加失败分析
if [[ "${{ needs.test-matrix.result }}" != "success" ]]; then
echo "## ❌ 失败分析和建议" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "🔍 **常见问题排查:**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "1. **TestContainers 启动失败**" >> $GITHUB_STEP_SUMMARY
echo " - 检查 Docker 服务是否正常" >> $GITHUB_STEP_SUMMARY
echo " - 检查网络连接和镜像拉取" >> $GITHUB_STEP_SUMMARY
echo " - 超时配置可能需要调整" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "2. **内存不足 (OOM)**" >> $GITHUB_STEP_SUMMARY
echo " - JVM 堆内存设置:4GB" >> $GITHUB_STEP_SUMMARY
echo " - Metaspace 设置:1.5GB" >> $GITHUB_STEP_SUMMARY
echo " - 并行 worker 限制:6个" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "3. **测试依赖冲突**" >> $GITHUB_STEP_SUMMARY
echo " - 检查并行测试中的端口冲突" >> $GITHUB_STEP_SUMMARY
echo " - 验证数据库连接池配置" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
- name: Check overall status
run: |
if [[ "${{ needs.quick-check.result }}" != "success" ]]; then
echo "❌ Quick check failed"
exit 1
fi
if [[ "${{ needs.test-matrix.result }}" != "success" ]]; then
echo "❌ Test matrix failed"
exit 1
fi
echo "✅ All checks passed"