fix(ci): Validate job增加独立PG容器,修复alembic迁移检查失败\n\n根因:alembic upgrade head --sql需要连接数据库读取alembic_version表,\n但Validate job没有启动PostgreSQL容器,DATABASE_URL指向不存在的端口。\n\n修复:在Validate Alembic migrations步骤前启动一个独立PG容器,\n用随机端口映射,通过GITHUB_ENV更新DATABASE_URL。\n步骤结束后自动清理容器(always()确保失败也清理)。\n\n参考PR #399的实现,最小改动版本,不拆分job。
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 43s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m17s
CI/CD Pipeline / Frontend Lint (push) Successful in 35s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 1m1s
CI/CD Pipeline / Unit Tests (push) Successful in 2m8s
CI/CD Pipeline / Integration Tests (push) Successful in 1m21s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 16m56s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m18s
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Failing after 1488h16m35s
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Failing after 1488h16m37s
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Failing after 1488h16m38s
CI Build & Deploy Pipeline / Deploy Production (pull_request) Failing after 1488h16m37s
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Failing after 1488h16m38s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 1488h16m38s
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Failing after 1488h16m40s
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Failing after 1488h16m40s
CI Build & Deploy Pipeline / Production Browser E2E (push) Failing after 1488h17m10s
CI Build & Deploy Pipeline / Staging API Integration Tests (push) Failing after 1488h17m11s
CI Build & Deploy Pipeline / Staging E2E Tests (push) Failing after 1488h17m11s
CI Build & Deploy Pipeline / Build Production API Image (push) Failing after 1488h17m12s
CI Build & Deploy Pipeline / Build Production Worker Image (push) Failing after 1488h17m12s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Failing after 1488h17m12s
CI Build & Deploy Pipeline / Build Staging Worker Image (push) Failing after 1488h17m13s
CI Build & Deploy Pipeline / Build Staging Web Image (push) Failing after 1488h17m13s
CI Build & Deploy Pipeline / Build Staging API Image (push) Failing after 1488h17m13s
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Failing after 1488h48m31s
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Failing after 1488h48m28s
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Failing after 1488h48m29s
CI Build & Deploy Pipeline / Deploy Production (push) Failing after 1488h49m2s
CI Build & Deploy Pipeline / Build Production Web Image (push) Failing after 1488h49m3s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 43s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m17s
CI/CD Pipeline / Frontend Lint (push) Successful in 35s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 1m1s
CI/CD Pipeline / Unit Tests (push) Successful in 2m8s
CI/CD Pipeline / Integration Tests (push) Successful in 1m21s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 16m56s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m18s
CI Build & Deploy Pipeline / Production Browser E2E (pull_request) Failing after 1488h16m35s
CI Build & Deploy Pipeline / Staging E2E Tests (pull_request) Failing after 1488h16m37s
CI Build & Deploy Pipeline / Build Production Worker Image (pull_request) Failing after 1488h16m38s
CI Build & Deploy Pipeline / Deploy Production (pull_request) Failing after 1488h16m37s
CI Build & Deploy Pipeline / Build Production API Image (pull_request) Failing after 1488h16m38s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 1488h16m38s
CI Build & Deploy Pipeline / Build Staging Web Image (pull_request) Failing after 1488h16m40s
CI Build & Deploy Pipeline / Build Staging API Image (pull_request) Failing after 1488h16m40s
CI Build & Deploy Pipeline / Production Browser E2E (push) Failing after 1488h17m10s
CI Build & Deploy Pipeline / Staging API Integration Tests (push) Failing after 1488h17m11s
CI Build & Deploy Pipeline / Staging E2E Tests (push) Failing after 1488h17m11s
CI Build & Deploy Pipeline / Build Production API Image (push) Failing after 1488h17m12s
CI Build & Deploy Pipeline / Build Production Worker Image (push) Failing after 1488h17m12s
CI Build & Deploy Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Failing after 1488h17m12s
CI Build & Deploy Pipeline / Build Staging Worker Image (push) Failing after 1488h17m13s
CI Build & Deploy Pipeline / Build Staging Web Image (push) Failing after 1488h17m13s
CI Build & Deploy Pipeline / Build Staging API Image (push) Failing after 1488h17m13s
CI Build & Deploy Pipeline / Build Staging Worker Image (pull_request) Failing after 1488h48m31s
CI Build & Deploy Pipeline / Staging API Integration Tests (pull_request) Failing after 1488h48m28s
CI Build & Deploy Pipeline / Build Production Web Image (pull_request) Failing after 1488h48m29s
CI Build & Deploy Pipeline / Deploy Production (push) Failing after 1488h49m2s
CI Build & Deploy Pipeline / Build Production Web Image (push) Failing after 1488h49m3s
This commit is contained in:
@@ -129,6 +129,10 @@ jobs:
|
||||
bash -n scripts/init_production_env.sh
|
||||
|
||||
'
|
||||
- name: Start PostgreSQL for validate (isolated container)
|
||||
shell: sh
|
||||
run: "set -eu\nPG_CONTAINER=\"ci-pg-validate-${GITHUB_RUN_ID:-$$}\"\necho \"PG_CONTAINER=$PG_CONTAINER\" >> \"$GITHUB_ENV\"\ndocker rm -f \"$PG_CONTAINER\" 2>/dev/null || true\ndocker run -d --name \"$PG_CONTAINER\" \\\n --shm-size=256m \\\n -e POSTGRES_USER=postgres \\\n -e POSTGRES_PASSWORD=postgres \\\n -e POSTGRES_DB=xiaoxia_saas \\\n -P \\\n --health-cmd \"pg_isready -U postgres\" \\\n --health-interval 3s \\\n --health-timeout 3s \\\n --health-retries 20 \\\n postgres:16-alpine\nPG_PORT=$(docker port \"$PG_CONTAINER\" 5432/tcp | cut -d: -f2)\necho \"PostgreSQL port: $PG_PORT\"\necho \"DATABASE_URL=postgresql+psycopg://postgres:postgres@127.0.0.1:$PG_PORT/xiaoxia_saas\" >> \"$GITHUB_ENV\"\nfor i in $(seq 1 30); do\n if docker inspect --format='{{.State.Health.Status}}' \"$PG_CONTAINER\" 2>/dev/null | grep -q healthy; then\n echo \"PostgreSQL is ready on port $PG_PORT\"\n break\n fi\n echo \"Waiting for PostgreSQL... ($i/30)\"\n sleep 2\ndone\ndocker inspect --format='{{.State.Health.Status}}' \"$PG_CONTAINER\" | grep -q healthy\n"
|
||||
|
||||
- name: Validate Alembic migrations
|
||||
shell: sh
|
||||
run: 'set -eu
|
||||
@@ -147,6 +151,14 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
run: "set -eu\npython3 scripts/check_migration_safety.py --allow-medium-risk --diff-against origin/develop\n"
|
||||
- name: Cleanup PostgreSQL (validate)
|
||||
if: always()
|
||||
shell: sh
|
||||
run: 'set +e
|
||||
docker rm -f "${PG_CONTAINER:-ci-pg-validate}" 2>/dev/null || true
|
||||
echo "PostgreSQL container cleaned up"
|
||||
'
|
||||
|
||||
- name: Job duration summary
|
||||
if: always()
|
||||
shell: sh
|
||||
|
||||
Reference in New Issue
Block a user