From f766c658a39114b19e772c8a68de9d6bbaba2f81 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Fri, 3 Jul 2026 22:19:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20CI=20Validate=E6=94=B9=E7=94=A8docker=20?= =?UTF-8?q?run=E6=89=8B=E5=8A=A8=E5=90=AF=E5=8A=A8PostgreSQL=EF=BC=88host?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8D=E6=94=AF=E6=8C=81services=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci-cd.yml | 50 ++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 15 deletions(-) mode change 100755 => 100644 .gitea/workflows/ci-cd.yml diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml old mode 100755 new mode 100644 index fb6388924..d6bc3003a --- a/.gitea/workflows/ci-cd.yml +++ b/.gitea/workflows/ci-cd.yml @@ -19,21 +19,6 @@ jobs: name: Validate Code Quality And Tests runs-on: ubuntu-22.04 - services: - postgres: - image: postgres:16 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: xiaoxia_saas - ports: - - 5433:5432 - options: >- - --health-cmd "pg_isready -U postgres" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - env: DATABASE_URL: postgresql+psycopg://postgres:postgres@127.0.0.1:5433/xiaoxia_saas USE_IN_MEMORY_DB: "false" @@ -139,6 +124,34 @@ jobs: set -eu PYTHONPATH="$PWD/apps/api:$PWD" python3 -m pytest tests/unit -q + - name: Start PostgreSQL for integration tests + shell: sh + run: | + set -eu + # 清理可能残留的旧容器 + docker rm -f ci-pg-validate 2>/dev/null || true + # 启动 PG 容器 + docker run -d --name ci-pg-validate \ + -e POSTGRES_USER=postgres \ + -e POSTGRES_PASSWORD=postgres \ + -e POSTGRES_DB=xiaoxia_saas \ + -p 5433:5432 \ + --health-cmd "pg_isready -U postgres" \ + --health-interval 5s \ + --health-timeout 5s \ + --health-retries 12 \ + postgres:16 + # 等待健康检查通过 + for i in $(seq 1 30); do + if docker inspect --format='{{.State.Health.Status}}' ci-pg-validate 2>/dev/null | grep -q healthy; then + echo "PostgreSQL is ready" + break + fi + echo "Waiting for PostgreSQL... ($i/30)" + sleep 2 + done + docker inspect --format='{{.State.Health.Status}}' ci-pg-validate | grep -q healthy + - name: Apply migrations for integration tests shell: sh run: | @@ -151,6 +164,13 @@ jobs: set -eu PYTHONPATH="$PWD/apps/api:$PWD" python3 -m pytest tests/integration -q --timeout=60 -x + - name: Cleanup PostgreSQL + if: always() + shell: sh + run: | + docker rm -f ci-pg-validate 2>/dev/null || true + echo "PostgreSQL container cleaned up" + - name: Build summary if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' shell: sh