fix: CI动态端口+超时控制 #24
@@ -12,6 +12,7 @@ jobs:
|
|||||||
e2e-test:
|
e2e-test:
|
||||||
runs-on: test
|
runs-on: test
|
||||||
needs: unit-test
|
needs: unit-test
|
||||||
|
timeout-minutes: 5
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -23,24 +24,41 @@ jobs:
|
|||||||
|
|
||||||
- name: E2E tests
|
- name: E2E tests
|
||||||
run: |
|
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
|
# Start backend
|
||||||
DB_PATH=/tmp/ci_oil_test.db FRONTEND_DIR=/dev/null \
|
DB_PATH="$DB_FILE" FRONTEND_DIR=/dev/null \
|
||||||
/tmp/ci-venv/bin/uvicorn backend.main:app --port 8000 &
|
/tmp/ci-venv/bin/uvicorn backend.main:app --port $BE_PORT &
|
||||||
|
BE_PID=$!
|
||||||
|
|
||||||
# Start frontend (in subshell to not change cwd)
|
# Start frontend with proxy to dynamic backend port
|
||||||
(cd frontend && npx vite --port 5173) &
|
(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
|
for i in $(seq 1 30); do
|
||||||
if curl -sf http://localhost:8000/api/version > /dev/null 2>&1 && \
|
if curl -sf http://localhost:$BE_PORT/api/oils > /dev/null 2>&1 && \
|
||||||
curl -sf http://localhost:5173/ > /dev/null 2>&1; then
|
curl -sf http://localhost:$FE_PORT/ > /dev/null 2>&1; then
|
||||||
echo "Both servers ready"
|
echo "Both servers ready in ${i}s"
|
||||||
|
READY=1
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
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
|
cd frontend
|
||||||
npx cypress run --spec "\
|
npx cypress run --spec "\
|
||||||
cypress/e2e/recipe-detail.cy.js,\
|
cypress/e2e/recipe-detail.cy.js,\
|
||||||
@@ -50,13 +68,12 @@ jobs:
|
|||||||
cypress/e2e/category-modules.cy.js,\
|
cypress/e2e/category-modules.cy.js,\
|
||||||
cypress/e2e/notification-flow.cy.js,\
|
cypress/e2e/notification-flow.cy.js,\
|
||||||
cypress/e2e/registration-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=$?
|
EXIT_CODE=$?
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
pkill -f "uvicorn backend" || true
|
kill $BE_PID $FE_PID 2>/dev/null
|
||||||
pkill -f "node.*vite" || true
|
rm -f "$DB_FILE"
|
||||||
rm -f /tmp/ci_oil_test.db
|
|
||||||
exit $EXIT_CODE
|
exit $EXIT_CODE
|
||||||
|
|
||||||
build-check:
|
build-check:
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ export default defineConfig({
|
|||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': 'http://localhost:8000',
|
'/api': `http://localhost:${process.env.VITE_API_PORT || 8000}`,
|
||||||
'/uploads': 'http://localhost:8000'
|
'/uploads': `http://localhost:${process.env.VITE_API_PORT || 8000}`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
|||||||
Reference in New Issue
Block a user