52ab7a91e0
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 1m7s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 1m8s
CI/CD Pipeline / Frontend Unit Tests (push) Failing after 2m22s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 3m1s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 5m15s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 6m2s
CI/CD Pipeline / Integration Tests (push) Successful in 2m6s
CI/CD Pipeline / Unit Tests (push) Successful in 10m29s
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / CI Gate (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Build Staging API Image (push) Successful in 12m41s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 40s
CI/CD Pipeline / Staging API Integration Tests (push) Failing after 18s
CI/CD Pipeline / Canary Release to Production (push) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 32s
CI/CD Pipeline / Staging E2E Tests (push) Failing after 53s
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
81 lines
2.4 KiB
Bash
Executable File
81 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Vitest 增量执行脚本(在Docker Node容器中运行)
|
|
# PR模式下只跑与改动文件相关的测试,大幅节省时间
|
|
set -eu
|
|
|
|
# 如果不是PR事件,直接全量跑
|
|
if [ "${GITHUB_EVENT_NAME:-}" != "pull_request" ]; then
|
|
echo "非PR模式,全量执行Vitest"
|
|
bash scripts/ci/step_frontend_run.sh "npx vitest run --coverage"
|
|
exit $?
|
|
fi
|
|
|
|
# 获取PR改动的文件列表
|
|
PR_NUMBER=$(echo "${GITHUB_REF:-}" | sed 's|refs/pull/||; s|/.*||')
|
|
if [ -z "$PR_NUMBER" ]; then
|
|
echo "无法获取PR编号,全量执行Vitest"
|
|
bash scripts/ci/step_frontend_run.sh "npx vitest run --coverage"
|
|
exit $?
|
|
fi
|
|
|
|
API_URL="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?limit=100"
|
|
CHANGED_FILES=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$API_URL" | python3 -c "
|
|
import json, sys
|
|
try:
|
|
files = json.load(sys.stdin)
|
|
web_files = []
|
|
for f in files:
|
|
fname = f['filename']
|
|
if fname.startswith('apps/web/src/') and fname.endswith(('.ts', '.tsx', '.js', '.jsx')) and f['status'] != 'removed':
|
|
web_files.append(fname.replace('apps/web/', ''))
|
|
print(' '.join(web_files))
|
|
except Exception as e:
|
|
print('')
|
|
")
|
|
|
|
if [ -z "$CHANGED_FILES" ]; then
|
|
echo "PR未改动前端源码文件,跳过Vitest"
|
|
exit 0
|
|
fi
|
|
|
|
FILE_COUNT=$(echo "$CHANGED_FILES" | wc -w)
|
|
echo "PR改动了 $FILE_COUNT 个前端文件"
|
|
|
|
# 如果改动文件太多(超过30个),全量跑更可靠
|
|
if [ "$FILE_COUNT" -gt 30 ]; then
|
|
echo "改动文件较多,全量执行Vitest"
|
|
bash scripts/ci/step_frontend_run.sh "npx vitest run --coverage"
|
|
exit $?
|
|
fi
|
|
|
|
echo ""
|
|
echo "=== 增量执行 Vitest(只跑相关测试)==="
|
|
echo "相关源文件: $CHANGED_FILES"
|
|
echo ""
|
|
|
|
# 在Docker Node容器中执行增量测试
|
|
set +e
|
|
VITEST_OUTPUT=$(bash scripts/ci/step_frontend_run.sh "npx vitest run related $CHANGED_FILES" 2>&1)
|
|
VITEST_EXIT=$?
|
|
set -e
|
|
echo "$VITEST_OUTPUT"
|
|
|
|
# 如果没有找到测试文件,视为通过(改动的文件没有对应测试)
|
|
# 先用 sed 去掉 ANSI 转义码,避免干扰 grep 匹配
|
|
CLEAN_OUTPUT=$(echo "$VITEST_OUTPUT" | sed 's/\x1b\[[0-9;]*m//g')
|
|
if echo "$CLEAN_OUTPUT" | grep -q "No test files found"; then
|
|
echo ""
|
|
echo "⚠️ 未找到相关测试文件,跳过(非失败)"
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$VITEST_EXIT" -eq 0 ]; then
|
|
echo ""
|
|
echo "✅ 增量测试通过"
|
|
exit 0
|
|
else
|
|
echo ""
|
|
echo "❌ 增量测试失败"
|
|
exit $VITEST_EXIT
|
|
fi
|