From 6ea8ae6b0cc06d452169582550e6b0445ce684cc Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Thu, 23 Jul 2026 18:36:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20P0=E7=B3=BB=E7=BB=9F=E6=80=A7?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20-=20concurrency/UnitTests/=E9=97=A8?= =?UTF-8?q?=E7=A6=81=E5=90=8C=E6=AD=A5\n\n-=20=E4=BB=BB=E5=8A=A11:=20devel?= =?UTF-8?q?op=20push=E4=BA=8B=E4=BB=B6=E5=85=B3=E9=97=ADcancel-in-progress?= =?UTF-8?q?=EF=BC=8CPR=E4=BA=8B=E4=BB=B6=E4=BF=9D=E7=95=99\n-=20=E4=BB=BB?= =?UTF-8?q?=E5=8A=A12:=20Unit=20Tests=E4=BF=AE=E5=A4=8D=20-=20PYTHONPATH?= =?UTF-8?q?=E5=8A=A0packages=E7=9B=AE=E5=BD=95+numpy=E5=8F=8C=E4=BF=9D?= =?UTF-8?q?=E9=99=A9\n-=20=E4=BB=BB=E5=8A=A14:=20auto=5Fapprove/auto=5Fmer?= =?UTF-8?q?ge=E5=90=8C=E6=AD=A5=E6=96=B0=E5=A2=9E5=E4=B8=AArequired=20chec?= =?UTF-8?q?ks\n\n=E4=BB=BB=E5=8A=A13=EF=BC=88=E5=88=86=E6=94=AF=E4=BF=9D?= =?UTF-8?q?=E6=8A=A4=E9=97=A8=E7=A6=81=EF=BC=89=E5=B7=B2=E9=80=9A=E8=BF=87?= =?UTF-8?q?Gitea=20API=E7=9B=B4=E6=8E=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci-pipeline.yml | 3 ++- scripts/ci/auto_approve.sh | 5 +++++ scripts/ci/auto_merge.sh | 5 +++++ scripts/ci/run_unit_tests.sh | 7 +++++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/ci-pipeline.yml b/.gitea/workflows/ci-pipeline.yml index c2545a97e..535f49e97 100755 --- a/.gitea/workflows/ci-pipeline.yml +++ b/.gitea/workflows/ci-pipeline.yml @@ -22,7 +22,8 @@ permissions: contents: read concurrency: group: ci-pipeline-${{ gitea.event_name }}-${{ gitea.ref }} - cancel-in-progress: true + # PR事件取消进行中的旧run,push事件不取消(确保完整CI跑完) + cancel-in-progress: ${{ gitea.event_name == 'pull_request' }} jobs: check-frontend-only: name: Check if frontend-only change diff --git a/scripts/ci/auto_approve.sh b/scripts/ci/auto_approve.sh index 0c4f94bc8..5736898f1 100644 --- a/scripts/ci/auto_approve.sh +++ b/scripts/ci/auto_approve.sh @@ -32,6 +32,11 @@ else "CI/CD Pipeline / Validate - Type Check (mypy) (pull_request)" "CI/CD Pipeline / Validate - Migration (alembic) (pull_request)" "CI/CD Pipeline / Frontend Lint (pull_request)" + "CI/CD Pipeline / Unit Tests (pull_request)" + "CI/CD Pipeline / Frontend Unit Tests (pull_request)" + "CI/CD Pipeline / PR Build API Image (pull_request)" + "CI/CD Pipeline / PR Build Web Image (pull_request)" + "CI/CD Pipeline / PR Build Worker Image (pull_request)" ) fi diff --git a/scripts/ci/auto_merge.sh b/scripts/ci/auto_merge.sh index 3b36f3b74..d251b9820 100644 --- a/scripts/ci/auto_merge.sh +++ b/scripts/ci/auto_merge.sh @@ -32,6 +32,11 @@ else "CI/CD Pipeline / Validate - Type Check (mypy) (pull_request)" "CI/CD Pipeline / Validate - Migration (alembic) (pull_request)" "CI/CD Pipeline / Frontend Lint (pull_request)" + "CI/CD Pipeline / Unit Tests (pull_request)" + "CI/CD Pipeline / Frontend Unit Tests (pull_request)" + "CI/CD Pipeline / PR Build API Image (pull_request)" + "CI/CD Pipeline / PR Build Web Image (pull_request)" + "CI/CD Pipeline / PR Build Worker Image (pull_request)" ) echo "检查required门禁(与分支保护一致)" fi diff --git a/scripts/ci/run_unit_tests.sh b/scripts/ci/run_unit_tests.sh index 146798a3b..f6613c8c1 100755 --- a/scripts/ci/run_unit_tests.sh +++ b/scripts/ci/run_unit_tests.sh @@ -42,6 +42,9 @@ for i in 1 2 3; do done pytest --version +# 双保险:确保numpy已安装 +python3 -m pip install -q numpy==1.26.4 || true + # --- 增量测试选择(仅PR) --- UNIT_TEST_MODE="full" SELECTED_TEST_FILES="tests/unit" @@ -75,7 +78,7 @@ echo "=== 运行单元测试 (模式: $UNIT_TEST_MODE) ===" if [ "$UNIT_TEST_MODE" = "incremental" ]; then echo "=== 增量测试模式 ===" - PYTHONPATH="$PWD/apps/api:$PWD/apps/worker:$PWD" python3 -m coverage run \ + PYTHONPATH="$PWD/apps/api:$PWD/apps/worker:$PWD/packages:$PWD" python3 -m coverage run \ --source=apps/api/app,apps/worker/worker_app,packages \ --omit="*/migrations/*,*/tests/*,*/test_*.py,*/site-packages/*" \ --branch \ @@ -84,7 +87,7 @@ if [ "$UNIT_TEST_MODE" = "incremental" ]; then python3 -m coverage xml -o coverage.xml python3 -m coverage report --fail-under=10 > /dev/null || true else - PYTHONPATH="$PWD/apps/api:$PWD/apps/worker:$PWD" python3 -m coverage run \ + PYTHONPATH="$PWD/apps/api:$PWD/apps/worker:$PWD/packages:$PWD" python3 -m coverage run \ --source=apps/api/app,apps/worker/worker_app,packages \ --omit="*/migrations/*,*/tests/*,*/test_*.py,*/site-packages/*" \ --branch \ -- 2.54.0