From d458bd05cde037a87ff6234028ede2d92a27a5c0 Mon Sep 17 00:00:00 2001 From: Hera Zhao Date: Sat, 11 Apr 2026 11:08:19 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20CI=E5=8A=A8=E6=80=81=E7=AB=AF=E5=8F=A3+?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E6=8E=A7=E5=88=B6=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?e2e=E5=8D=A1=E6=AD=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 后端端口随机9000-9999,前端4000-4999 - 数据库文件按端口号隔离 - vite proxy支持VITE_API_PORT环境变量 - 服务启动超时30秒,失败即退出 - Cypress: defaultCommandTimeout=5s, pageLoadTimeout=10s - 整个e2e job timeout 5分钟 Co-Authored-By: Claude Opus 4.6 (1M context) --- .gitea/workflows/test.yml | 43 +++++++++++++++++++++++++++------------ frontend/vite.config.js | 4 ++-- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index f2b55b9..49dfb19 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -12,6 +12,7 @@ jobs: e2e-test: runs-on: test needs: unit-test + timeout-minutes: 5 steps: - uses: actions/checkout@v4 @@ -23,24 +24,41 @@ jobs: - name: E2E tests run: | + # Dynamic ports to avoid conflicts + BE_PORT=$(shuf -i 9000-9999 -n 1) + FE_PORT=$(shuf -i 4000-4999 -n 1) + DB_FILE="/tmp/ci_oil_test_${BE_PORT}.db" + echo "Using backend=$BE_PORT frontend=$FE_PORT db=$DB_FILE" + # Start backend - DB_PATH=/tmp/ci_oil_test.db FRONTEND_DIR=/dev/null \ - /tmp/ci-venv/bin/uvicorn backend.main:app --port 8000 & + DB_PATH="$DB_FILE" FRONTEND_DIR=/dev/null \ + /tmp/ci-venv/bin/uvicorn backend.main:app --port $BE_PORT & + BE_PID=$! - # Start frontend (in subshell to not change cwd) - (cd frontend && npx vite --port 5173) & + # Start frontend with proxy to dynamic backend port + (cd frontend && VITE_API_PORT=$BE_PORT npx vite --port $FE_PORT) & + FE_PID=$! - # Wait for both servers + # Wait for both servers (max 30s, fail fast) + READY=0 for i in $(seq 1 30); do - if curl -sf http://localhost:8000/api/version > /dev/null 2>&1 && \ - curl -sf http://localhost:5173/ > /dev/null 2>&1; then - echo "Both servers ready" + if curl -sf http://localhost:$BE_PORT/api/oils > /dev/null 2>&1 && \ + curl -sf http://localhost:$FE_PORT/ > /dev/null 2>&1; then + echo "Both servers ready in ${i}s" + READY=1 break fi sleep 1 done - # Run core cypress specs (proven stable) + if [ "$READY" = "0" ]; then + echo "ERROR: Servers failed to start within 30s" + kill $BE_PID $FE_PID 2>/dev/null + rm -f "$DB_FILE" + exit 1 + fi + + # Run core cypress specs with timeouts cd frontend npx cypress run --spec "\ cypress/e2e/recipe-detail.cy.js,\ @@ -50,13 +68,12 @@ jobs: cypress/e2e/category-modules.cy.js,\ cypress/e2e/notification-flow.cy.js,\ cypress/e2e/registration-flow.cy.js\ - " --config video=false + " --config "video=false,defaultCommandTimeout=5000,pageLoadTimeout=10000,baseUrl=http://localhost:$FE_PORT" EXIT_CODE=$? # Cleanup - pkill -f "uvicorn backend" || true - pkill -f "node.*vite" || true - rm -f /tmp/ci_oil_test.db + kill $BE_PID $FE_PID 2>/dev/null + rm -f "$DB_FILE" exit $EXIT_CODE build-check: diff --git a/frontend/vite.config.js b/frontend/vite.config.js index 32d8d86..9112151 100644 --- a/frontend/vite.config.js +++ b/frontend/vite.config.js @@ -10,8 +10,8 @@ export default defineConfig({ plugins: [vue()], server: { proxy: { - '/api': 'http://localhost:8000', - '/uploads': 'http://localhost:8000' + '/api': `http://localhost:${process.env.VITE_API_PORT || 8000}`, + '/uploads': `http://localhost:${process.env.VITE_API_PORT || 8000}` } }, build: {