From 01a1e24a7bceb4c9e654806feb56effa328a1dbe Mon Sep 17 00:00:00 2001 From: estebanthi Date: Mon, 30 Mar 2026 12:23:41 +0200 Subject: [PATCH] fix: configure db host for act and wait for postgres --- .github/workflows/python-uv-ci-with-db.yml | 45 ++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/.github/workflows/python-uv-ci-with-db.yml b/.github/workflows/python-uv-ci-with-db.yml index 4085042..dfd4c15 100644 --- a/.github/workflows/python-uv-ci-with-db.yml +++ b/.github/workflows/python-uv-ci-with-db.yml @@ -114,13 +114,6 @@ jobs: --health-interval=${{ inputs.redis_health_interval }} --health-timeout=${{ inputs.redis_health_timeout }} --health-retries=${{ inputs.redis_health_retries }} - env: - POSTGRES_HOST: 127.0.0.1 - POSTGRES_PORT: ${{ job.services.postgres.ports['5432'] }} - POSTGRES_USER: ${{ inputs.postgres_user }} - POSTGRES_PASSWORD: ${{ inputs.postgres_password }} - POSTGRES_DB: ${{ inputs.postgres_db }} - DATABASE_URL: postgres://${{ inputs.postgres_user }}:${{ inputs.postgres_password }}@127.0.0.1:${{ job.services.postgres.ports['5432'] }}/${{ inputs.postgres_db }} permissions: contents: read defaults: @@ -130,6 +123,22 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Configure DB env + run: | + if [ "${ACT:-}" = "true" ] || [ "${GITEA_ACTIONS:-}" = "true" ]; then + host="postgres" + port="5432" + else + host="127.0.0.1" + port="${{ job.services.postgres.ports['5432'] }}" + fi + echo "POSTGRES_HOST=$host" >> "$GITHUB_ENV" + echo "POSTGRES_PORT=$port" >> "$GITHUB_ENV" + echo "POSTGRES_USER=${{ inputs.postgres_user }}" >> "$GITHUB_ENV" + echo "POSTGRES_PASSWORD=${{ inputs.postgres_password }}" >> "$GITHUB_ENV" + echo "POSTGRES_DB=${{ inputs.postgres_db }}" >> "$GITHUB_ENV" + echo "DATABASE_URL=postgres://${{ inputs.postgres_user }}:${{ inputs.postgres_password }}@$host:$port/${{ inputs.postgres_db }}" >> "$GITHUB_ENV" + - name: Load env vars if: ${{ inputs.env != '' }} run: | @@ -196,6 +205,28 @@ jobs: echo "$line" >> "$GITHUB_ENV" done <<< "${{ inputs.test_env }}" + - name: Wait for postgres + run: | + python - <<'PY' + import os + import socket + import time + + host = os.getenv("POSTGRES_HOST", "127.0.0.1") + port = int(os.getenv("POSTGRES_PORT", "5432")) + deadline = time.time() + 60 + + while True: + try: + with socket.create_connection((host, port), timeout=2): + print(f"Postgres reachable at {host}:{port}") + break + except OSError: + if time.time() > deadline: + raise + time.sleep(1) + PY + - name: Run format check if: ${{ inputs.format_command != '' }} run: ${{ inputs.format_command }}