feat: extend python uv ci with db inputs and optional steps

This commit is contained in:
2026-03-24 14:45:08 +01:00
parent 7066e237db
commit e94e04cff3

View File

@@ -21,6 +21,12 @@ on:
required: false
type: string
default: ""
test_env:
description: >
Multiline env vars for tests, one per line: KEY=VALUE
required: false
type: string
default: ""
uv_sync_args:
type: string
default: "--frozen --dev"
@@ -36,6 +42,48 @@ on:
test_command:
type: string
default: "uv run pytest"
alembic_command:
type: string
default: ""
postgres_image:
type: string
default: "postgres:16"
postgres_user:
type: string
default: "postgres"
postgres_password:
type: string
default: "postgres"
postgres_db:
type: string
default: "test_db"
postgres_health_cmd:
type: string
default: "pg_isready -U postgres"
postgres_health_interval:
type: string
default: "10s"
postgres_health_timeout:
type: string
default: "5s"
postgres_health_retries:
type: string
default: "5"
redis_image:
type: string
default: "redis:7-alpine"
redis_health_cmd:
type: string
default: "redis-cli ping"
redis_health_interval:
type: string
default: "5s"
redis_health_timeout:
type: string
default: "5s"
redis_health_retries:
type: string
default: "20"
secrets:
ssh_private_key:
required: false
@@ -47,18 +95,25 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
image: ${{ inputs.postgres_image }}
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_db
POSTGRES_USER: ${{ inputs.postgres_user }}
POSTGRES_PASSWORD: ${{ inputs.postgres_password }}
POSTGRES_DB: ${{ inputs.postgres_db }}
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=5
--health-cmd="${{ inputs.postgres_health_cmd }}"
--health-interval=${{ inputs.postgres_health_interval }}
--health-timeout=${{ inputs.postgres_health_timeout }}
--health-retries=${{ inputs.postgres_health_retries }}
redis:
image: ${{ inputs.redis_image }}
options: >-
--health-cmd="${{ inputs.redis_health_cmd }}"
--health-interval=${{ inputs.redis_health_interval }}
--health-timeout=${{ inputs.redis_health_timeout }}
--health-retries=${{ inputs.redis_health_retries }}
permissions:
contents: read
defaults:
@@ -121,6 +176,19 @@ jobs:
- name: Sync dependencies
run: uv sync ${{ inputs.uv_sync_args }}
- name: Load test env vars
if: ${{ inputs.test_env != '' }}
run: |
while IFS= read -r line; do
[ -z "$line" ] && continue
case "$line" in \#*) continue;; esac
if [[ "$line" != *=* ]]; then
echo "Invalid env line: $line" >&2
exit 1
fi
echo "$line" >> "$GITHUB_ENV"
done <<< "${{ inputs.test_env }}"
- name: Run format check
if: ${{ inputs.format_command != '' }}
run: ${{ inputs.format_command }}
@@ -133,6 +201,10 @@ jobs:
if: ${{ inputs.typecheck_command != '' }}
run: ${{ inputs.typecheck_command }}
- name: Alembic upgrade head (smoke test)
if: ${{ inputs.alembic_command != '' }}
run: ${{ inputs.alembic_command }}
- name: Run tests
if: ${{ inputs.test_command != '' }}
run: ${{ inputs.test_command }}