fix: configure db host for act and wait for postgres
This commit is contained in:
45
.github/workflows/python-uv-ci-with-db.yml
vendored
45
.github/workflows/python-uv-ci-with-db.yml
vendored
@@ -114,13 +114,6 @@ jobs:
|
|||||||
--health-interval=${{ inputs.redis_health_interval }}
|
--health-interval=${{ inputs.redis_health_interval }}
|
||||||
--health-timeout=${{ inputs.redis_health_timeout }}
|
--health-timeout=${{ inputs.redis_health_timeout }}
|
||||||
--health-retries=${{ inputs.redis_health_retries }}
|
--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:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
defaults:
|
defaults:
|
||||||
@@ -130,6 +123,22 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
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
|
- name: Load env vars
|
||||||
if: ${{ inputs.env != '' }}
|
if: ${{ inputs.env != '' }}
|
||||||
run: |
|
run: |
|
||||||
@@ -196,6 +205,28 @@ jobs:
|
|||||||
echo "$line" >> "$GITHUB_ENV"
|
echo "$line" >> "$GITHUB_ENV"
|
||||||
done <<< "${{ inputs.test_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
|
- name: Run format check
|
||||||
if: ${{ inputs.format_command != '' }}
|
if: ${{ inputs.format_command != '' }}
|
||||||
run: ${{ inputs.format_command }}
|
run: ${{ inputs.format_command }}
|
||||||
|
|||||||
Reference in New Issue
Block a user