From e6fae9995508891399f6f74afb2f4afbd398d5d6 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Sun, 19 Jul 2026 18:40:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8Dunit=5Ftests=20set?= =?UTF-8?q?=20-e=20=E9=80=80=E5=87=BA=E9=97=AE=E9=A2=98=20+=20=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E4=BE=9D=E8=B5=96=E5=AE=89=E8=A3=85=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ci/run_unit_tests.sh | 2 ++ scripts/ci/step_frontend_install.sh | 42 +++++------------------------ scripts/ci/step_frontend_run.sh | 4 +-- 3 files changed, 10 insertions(+), 38 deletions(-) diff --git a/scripts/ci/run_unit_tests.sh b/scripts/ci/run_unit_tests.sh index 70d4acdbc..fd7ac155d 100755 --- a/scripts/ci/run_unit_tests.sh +++ b/scripts/ci/run_unit_tests.sh @@ -26,10 +26,12 @@ if [ "${GITHUB_EVENT_NAME:-}" = "pull_request" ] && [ -n "${GITHUB_TOKEN:-}" ]; API_URL="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/files?limit=300" CHANGED_FILES=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "$API_URL" | python3 -c "import sys,json; [print(f['filename']) for f in json.load(sys.stdin) if f['status'] != 'removed']") echo "改动文件数: $(echo "$CHANGED_FILES" | grep -c . || echo 0)" + set +e CHANGED_FILES="$CHANGED_FILES" \ SELECTED_TESTS_OUTPUT=/tmp/selected_tests.txt \ python3 scripts/ci/select_unit_tests.py SELECT_EXIT=$? + set -e if [ $SELECT_EXIT -eq 0 ]; then UNIT_TEST_MODE="incremental" TEST_FILES=$(cat /tmp/selected_tests.txt | tr '\n' ' ') diff --git a/scripts/ci/step_frontend_install.sh b/scripts/ci/step_frontend_install.sh index b0f16a0e6..ae59af2f2 100755 --- a/scripts/ci/step_frontend_install.sh +++ b/scripts/ci/step_frontend_install.sh @@ -1,46 +1,18 @@ #!/bin/sh -# CI 公共步骤:前端依赖安装(在 docker node 容器中运行,带缓存) +# CI 公共步骤:前端依赖安装(在 docker node 容器中运行) # 用法:step_frontend_install.sh [模式] # 模式: full (默认) - 完整安装所有依赖 -# vitest - 仅安装vitest相关依赖(用于轻量单测job) +# vitest - 同full(保持接口兼容) set -eu MODE="${1:-full}" -NPM_CACHE_VOLUME="xiaoxia-npm-cache" echo "=== 前端依赖安装开始 (模式: $MODE) ===" -# 确保缓存卷存在 -docker volume create "$NPM_CACHE_VOLUME" > /dev/null 2>&1 || true - -if [ "$MODE" = "vitest" ]; then - # 轻量模式:检查缓存中是否已有node_modules,有则跳过npm ci - echo "检查 vitest 依赖缓存..." - HAS_CACHE=$(docker run --rm \ - -v "$NPM_CACHE_VOLUME:/cache" \ - docker.m.daocloud.io/library/node:20 \ - sh -c 'test -d /cache/node_modules && test -f /cache/package-lock.json && echo "yes" || echo "no"') - - if [ "$HAS_CACHE" = "yes" ]; then - echo "✅ 缓存命中,跳过 npm ci" - else - echo "⚠️ 缓存未命中,执行 npm ci..." - docker run --rm \ - -v "$PWD:/workspace" \ - -v "$NPM_CACHE_VOLUME:/workspace/apps/web/node_modules" \ - -w /workspace/apps/web \ - docker.m.daocloud.io/library/node:20 \ - sh -lc "npm ci --no-audit --no-fund" - fi -else - # 完整模式:执行 npm ci - echo "执行 npm ci (完整模式)..." - docker run --rm \ - -v "$PWD:/workspace" \ - -v "$NPM_CACHE_VOLUME:/workspace/apps/web/node_modules" \ - -w /workspace/apps/web \ - docker.m.daocloud.io/library/node:20 \ - sh -lc "npm ci --no-audit --no-fund" -fi +docker run --rm \ + -v "$PWD:/workspace" \ + -w /workspace/apps/web \ + docker.m.daocloud.io/library/node:20 \ + sh -lc "npm ci --no-audit --no-fund" echo "=== 前端依赖安装完成 ===" diff --git a/scripts/ci/step_frontend_run.sh b/scripts/ci/step_frontend_run.sh index 619f2deea..6dcae42cc 100755 --- a/scripts/ci/step_frontend_run.sh +++ b/scripts/ci/step_frontend_run.sh @@ -1,14 +1,12 @@ #!/bin/sh -# CI 公共步骤:前端命令执行(在 docker node 容器中运行,带缓存) +# CI 公共步骤:前端命令执行(在 docker node 容器中运行) # 用法:step_frontend_run.sh "要执行的命令" set -eu CMD="${1:-echo 'no command'}" -NPM_CACHE_VOLUME="xiaoxia-npm-cache" docker run --rm \ -v "$PWD:/workspace" \ - -v "$NPM_CACHE_VOLUME:/workspace/apps/web/node_modules" \ -w /workspace/apps/web \ docker.m.daocloud.io/library/node:20 \ sh -lc "$CMD"