ci(billing): 启用 PostgreSQL 计费集成门禁
CI verify 启动 PostgreSQL 16、应用全部迁移并注入 AI_GATEWAY_TEST_DATABASE_URL,使钱包、Outbox、幂等和租约集成测试不再因缺少数据库而跳过。
This commit is contained in:
@@ -79,6 +79,37 @@ jobs:
|
||||
printf 'Go files require gofmt:\n%s\n' "$unformatted" >&2
|
||||
exit 1
|
||||
}
|
||||
- name: Start PostgreSQL 16 integration database
|
||||
env:
|
||||
CI_RUN_ID: ${{ github.run_id }}
|
||||
CI_RUN_NUMBER: ${{ github.run_number }}
|
||||
run: |
|
||||
set -eu
|
||||
container="easyai-gateway-test-pg-${CI_RUN_ID}-${CI_RUN_NUMBER}"
|
||||
docker run -d --rm --name "$container" \
|
||||
-e POSTGRES_USER=easyai_test \
|
||||
-e POSTGRES_PASSWORD=easyai_test_only \
|
||||
-e POSTGRES_DB=easyai_gateway_test \
|
||||
postgres:16-alpine
|
||||
for attempt in $(seq 1 60); do
|
||||
if docker exec "$container" pg_isready -U easyai_test -d easyai_gateway_test >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
test "$attempt" -lt 60
|
||||
sleep 1
|
||||
done
|
||||
database_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container")
|
||||
test -n "$database_ip"
|
||||
printf 'AI_GATEWAY_TEST_DATABASE_URL=postgresql://easyai_test:easyai_test_only@%s:5432/easyai_gateway_test?sslmode=disable\n' "$database_ip" >> "$GITHUB_ENV"
|
||||
printf 'AI_GATEWAY_TEST_POSTGRES_CONTAINER=%s\n' "$container" >> "$GITHUB_ENV"
|
||||
docker exec "$container" psql -v ON_ERROR_STOP=1 -U easyai_test -d easyai_gateway_test \
|
||||
-c 'CREATE TABLE IF NOT EXISTS schema_migrations (version text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())'
|
||||
for migration in apps/api/migrations/*.sql; do
|
||||
docker exec -i "$container" psql -v ON_ERROR_STOP=1 -U easyai_test -d easyai_gateway_test < "$migration"
|
||||
version=$(basename "$migration" .sql)
|
||||
docker exec "$container" psql -v ON_ERROR_STOP=1 -U easyai_test -d easyai_gateway_test \
|
||||
-c "INSERT INTO schema_migrations(version) VALUES ('$version') ON CONFLICT (version) DO NOTHING"
|
||||
done
|
||||
- name: Verify Go code
|
||||
working-directory: apps/api
|
||||
env:
|
||||
@@ -110,3 +141,9 @@ jobs:
|
||||
trivy fs --scanners vuln,secret,misconfig --severity HIGH,CRITICAL \
|
||||
--ignore-unfixed --exit-code 1 --timeout 15m --skip-dirs .git \
|
||||
--skip-dirs node_modules .
|
||||
- name: Stop PostgreSQL integration database
|
||||
if: always()
|
||||
run: |
|
||||
if test -n "${AI_GATEWAY_TEST_POSTGRES_CONTAINER:-}"; then
|
||||
docker rm -f "$AI_GATEWAY_TEST_POSTGRES_CONTAINER" >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
@@ -64,6 +64,37 @@ jobs:
|
||||
printf 'Go files require gofmt:\n%s\n' "$unformatted" >&2
|
||||
exit 1
|
||||
}
|
||||
- name: Start PostgreSQL 16 integration database
|
||||
env:
|
||||
CI_RUN_ID: ${{ github.run_id }}
|
||||
CI_RUN_NUMBER: ${{ github.run_number }}
|
||||
run: |
|
||||
set -eu
|
||||
container="easyai-gateway-test-pg-${CI_RUN_ID}-${CI_RUN_NUMBER}"
|
||||
docker run -d --rm --name "$container" \
|
||||
-e POSTGRES_USER=easyai_test \
|
||||
-e POSTGRES_PASSWORD=easyai_test_only \
|
||||
-e POSTGRES_DB=easyai_gateway_test \
|
||||
postgres:16-alpine
|
||||
for attempt in $(seq 1 60); do
|
||||
if docker exec "$container" pg_isready -U easyai_test -d easyai_gateway_test >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
test "$attempt" -lt 60
|
||||
sleep 1
|
||||
done
|
||||
database_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container")
|
||||
test -n "$database_ip"
|
||||
printf 'AI_GATEWAY_TEST_DATABASE_URL=postgresql://easyai_test:easyai_test_only@%s:5432/easyai_gateway_test?sslmode=disable\n' "$database_ip" >> "$GITHUB_ENV"
|
||||
printf 'AI_GATEWAY_TEST_POSTGRES_CONTAINER=%s\n' "$container" >> "$GITHUB_ENV"
|
||||
docker exec "$container" psql -v ON_ERROR_STOP=1 -U easyai_test -d easyai_gateway_test \
|
||||
-c 'CREATE TABLE IF NOT EXISTS schema_migrations (version text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())'
|
||||
for migration in apps/api/migrations/*.sql; do
|
||||
docker exec -i "$container" psql -v ON_ERROR_STOP=1 -U easyai_test -d easyai_gateway_test < "$migration"
|
||||
version=$(basename "$migration" .sql)
|
||||
docker exec "$container" psql -v ON_ERROR_STOP=1 -U easyai_test -d easyai_gateway_test \
|
||||
-c "INSERT INTO schema_migrations(version) VALUES ('$version') ON CONFLICT (version) DO NOTHING"
|
||||
done
|
||||
- name: Verify Go code
|
||||
working-directory: apps/api
|
||||
env:
|
||||
@@ -95,3 +126,9 @@ jobs:
|
||||
trivy fs --scanners vuln,secret,misconfig --severity HIGH,CRITICAL \
|
||||
--ignore-unfixed --exit-code 1 --timeout 15m --skip-dirs .git \
|
||||
--skip-dirs node_modules .
|
||||
- name: Stop PostgreSQL integration database
|
||||
if: always()
|
||||
run: |
|
||||
if test -n "${AI_GATEWAY_TEST_POSTGRES_CONTAINER:-}"; then
|
||||
docker rm -f "$AI_GATEWAY_TEST_POSTGRES_CONTAINER" >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user