From c68bc8d09fde7ad6e2a421aee5874357f0423549 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 3 Oct 2026 11:34:11 +0200 Subject: [PATCH] Lagere die Dev-pytest-Suite in ein Host-Skript aus und wartet auf den Deploy-Checkout. Co-authored-by: Cursor --- .gitattributes | 1 + .gitea/workflows/test.yml | 30 ++++--------------- scripts/ci-pytest.sh | 61 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 25 deletions(-) create mode 100644 .gitattributes create mode 100644 scripts/ci-pytest.sh diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfdb8b7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 4f5a906..76d73ca 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -17,41 +17,21 @@ jobs: run: | set -e APP_DIR="$HOME/docker/buyingagent-dev" - COMPOSE_FILE="docker-compose.dev-env.yml" echo "pytest uses Dev Postgres (${APP_DIR}); event=${{ github.event_name }}" cd "$APP_DIR" for i in $(seq 1 60); do - if [ -f "$APP_DIR/pyproject.toml" ] \ - && grep -q "api-test:" "$COMPOSE_FILE" \ - && docker compose -f "$COMPOSE_FILE" exec -T api true 2>/dev/null; then - echo "api and test profile ready (attempt $i)" + if [ -f scripts/ci-pytest.sh ]; then + echo "ci-pytest.sh ready (attempt $i)" break fi if [ "$i" -eq 60 ]; then - echo "timeout waiting for Dev checkout/api" - docker compose -f "$COMPOSE_FILE" ps || true - ls -la "$APP_DIR" || true + echo "timeout waiting for scripts/ci-pytest.sh after Dev deploy" + ls -la scripts || true exit 1 fi sleep 5 done - PGUSER="$(docker compose -f "$COMPOSE_FILE" exec -T postgres printenv POSTGRES_USER | tr -d '\r')" - echo "test database buyingagent_test on the existing Dev Postgres (owner ${PGUSER})" - docker compose -f "$COMPOSE_FILE" exec -T postgres \ - psql -U "$PGUSER" -d postgres -v ON_ERROR_STOP=1 \ - -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'buyingagent_test' AND pid <> pg_backend_pid();" - docker compose -f "$COMPOSE_FILE" exec -T postgres \ - psql -U "$PGUSER" -d postgres -v ON_ERROR_STOP=1 \ - -c "DROP DATABASE IF EXISTS buyingagent_test;" - docker compose -f "$COMPOSE_FILE" exec -T postgres \ - psql -U "$PGUSER" -d postgres -v ON_ERROR_STOP=1 \ - -c "CREATE DATABASE buyingagent_test OWNER ${PGUSER};" - docker compose -f "$COMPOSE_FILE" --profile test build --pull=false api-test - RUN_OPTS="--rm --no-deps -v ${APP_DIR}:/src:ro -w /src -e PYTHONPATH=/src -e DB_NAME=buyingagent_test -e ENVIRONMENT=test -e ENGINE_BUILD=test" - docker compose -f "$COMPOSE_FILE" --profile test run $RUN_OPTS \ - api-test /app/.venv/bin/alembic upgrade head - docker compose -f "$COMPOSE_FILE" --profile test run $RUN_OPTS \ - api-test /app/.venv/bin/pytest tests -ra --tb=short --cache-dir=/tmp/pytest-cache + sh scripts/ci-pytest.sh smoke-dev: if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} diff --git a/scripts/ci-pytest.sh b/scripts/ci-pytest.sh new file mode 100644 index 0000000..7301db3 --- /dev/null +++ b/scripts/ci-pytest.sh @@ -0,0 +1,61 @@ +#!/bin/sh +set -e + +APP_DIR="${APP_DIR:-$HOME/docker/buyingagent-dev}" +COMPOSE_FILE="${COMPOSE_FILE:-docker-compose.dev-env.yml}" + +echo "pytest uses Dev Postgres (${APP_DIR})" +cd "$APP_DIR" + +i=1 +while [ "$i" -le 60 ]; do + if [ -f "$APP_DIR/pyproject.toml" ] \ + && grep -q "api-test:" "$COMPOSE_FILE" \ + && docker compose -f "$COMPOSE_FILE" exec -T api true >/dev/null 2>&1; then + echo "api and test profile ready (attempt $i)" + break + fi + if [ "$i" -eq 60 ]; then + echo "timeout waiting for Dev checkout/api" + docker compose -f "$COMPOSE_FILE" ps || true + ls -la "$APP_DIR" || true + exit 1 + fi + i=$((i + 1)) + sleep 5 +done + +PGUSER="$(docker compose -f "$COMPOSE_FILE" exec -T postgres printenv POSTGRES_USER | tr -d '\r')" +echo "test database buyingagent_test on the existing Dev Postgres (owner ${PGUSER})" + +docker compose -f "$COMPOSE_FILE" exec -T postgres \ + psql -U "$PGUSER" -d postgres -v ON_ERROR_STOP=1 \ + -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'buyingagent_test' AND pid <> pg_backend_pid();" + +docker compose -f "$COMPOSE_FILE" exec -T postgres \ + psql -U "$PGUSER" -d postgres -v ON_ERROR_STOP=1 \ + -c "DROP DATABASE IF EXISTS buyingagent_test;" + +docker compose -f "$COMPOSE_FILE" exec -T postgres \ + psql -U "$PGUSER" -d postgres -v ON_ERROR_STOP=1 \ + -c "CREATE DATABASE buyingagent_test OWNER ${PGUSER};" + +docker compose -f "$COMPOSE_FILE" --profile test build --pull=false api-test + +docker compose -f "$COMPOSE_FILE" --profile test run --rm --no-deps \ + -v "${APP_DIR}:/src:ro" \ + -w /src \ + -e PYTHONPATH=/src \ + -e DB_NAME=buyingagent_test \ + -e ENVIRONMENT=test \ + -e ENGINE_BUILD=test \ + api-test /app/.venv/bin/alembic upgrade head + +docker compose -f "$COMPOSE_FILE" --profile test run --rm --no-deps \ + -v "${APP_DIR}:/src:ro" \ + -w /src \ + -e PYTHONPATH=/src \ + -e DB_NAME=buyingagent_test \ + -e ENVIRONMENT=test \ + -e ENGINE_BUILD=test \ + api-test /app/.venv/bin/pytest tests -ra --tb=short --cache-dir=/tmp/pytest-cache