From a33b46b4afb8f5ddee985e7c8592a60a51990553 Mon Sep 17 00:00:00 2001 From: 1445043649 <> Date: Sun, 10 May 2026 22:55:53 +0800 Subject: [PATCH] ci(postgres): add Postgres workflow running @pytest.mark.postgres tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 .github/workflows/backend-postgres-tests.yml,独立于现有 backend-unit-tests workflow: - GitHub runner (ubuntu-latest) 自带 docker daemon - testcontainers 在 runner 上起 postgres:16-alpine 容器 - uv sync --extra postgres-test 拉 testcontainers + asyncpg + psycopg - pytest -m postgres 仅跑 PG 标签的 4 个 smoke test (+ 后续 PR 增量) 为什么独立 workflow 而不是合到 backend-unit-tests: - 现有 fast 测试不受 PG container 启动延迟影响 - 可独立 fail-soft(早期 Stage 0 rollout 期间需要时加 continue-on-error) - fork 用户不强制承担 docker infra 成本 Stage 0 PR1 T1.9. Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/backend-postgres-tests.yml | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/backend-postgres-tests.yml diff --git a/.github/workflows/backend-postgres-tests.yml b/.github/workflows/backend-postgres-tests.yml new file mode 100644 index 00000000..85efdb34 --- /dev/null +++ b/.github/workflows/backend-postgres-tests.yml @@ -0,0 +1,56 @@ +name: Postgres Tests + +# Stage 0 PR1 · runs the @pytest.mark.postgres subset against a real +# Postgres backend (testcontainers spawns postgres:16-alpine on the +# GitHub runner's docker daemon). +# +# Kept as a separate workflow from `Unit Tests` so: +# - the existing fast unit test loop is unchanged +# - PG tests can fail-soft during early Stage 0 rollout if needed +# (set continue-on-error: true on the run step) +# - infra cost is opt-in for forks + +on: + push: + branches: [ 'main' ] + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +concurrency: + group: postgres-tests-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + backend-postgres-tests: + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + timeout-minutes: 20 + + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: '3.12' + + - name: Install uv + uses: astral-sh/setup-uv@v7 + + - name: Verify Docker daemon (testcontainers needs it) + run: docker version + + - name: Install backend dependencies (with postgres-test extra) + working-directory: backend + run: uv sync --group dev --extra postgres-test + + - name: Run @pytest.mark.postgres tests + working-directory: backend + # -m postgres selects only postgres-tagged tests; testcontainers + # spins up postgres:16-alpine as the fixture's session-scoped + # container. ~5-10s container startup + per-test DB CREATE/DROP. + run: PYTHONPATH=. uv run pytest -m postgres -v