fix: configure db host for act and wait for postgres

This commit is contained in:
2026-03-30 12:23:41 +02:00
parent 59625a53b2
commit 01a1e24a7b

View File

@@ -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 }}