From 631dd4080ea54ad9871f27f89df287b514deb03a Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 28 Oct 2026 10:19:58 +0100 Subject: [PATCH 1/2] CI: Wegwerf-Postgres je Lauf fuer DB-Tests, CODEOWNERS fuer common/ Co-Authored-By: Claude Sonnet 5.5 --- .gitea/CODEOWNERS | 2 ++ .gitea/workflows/db-tests.yml | 27 ++++++++++++++++-------- scripts/ci-pg-cluster.sh | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 .gitea/CODEOWNERS create mode 100755 scripts/ci-pg-cluster.sh diff --git a/.gitea/CODEOWNERS b/.gitea/CODEOWNERS new file mode 100644 index 00000000..7653275f --- /dev/null +++ b/.gitea/CODEOWNERS @@ -0,0 +1,2 @@ +# common/ ist modulübergreifend: Änderungen brauchen Review (Auswirkungsliste im PR) +/common/ @patrick diff --git a/.gitea/workflows/db-tests.yml b/.gitea/workflows/db-tests.yml index 55651a53..fd8f021c 100644 --- a/.gitea/workflows/db-tests.yml +++ b/.gitea/workflows/db-tests.yml @@ -4,25 +4,34 @@ on: pull_request: paths: - "common/**" - - "dms/**" - - "mail/**" - "archive/**" - "ai/**" - "connect/**" - - "workflow/**" - - "internal/**" + - "scripts/ci-pg-cluster.sh" + - ".gitea/workflows/db-tests.yml" jobs: db-tests: runs-on: nexarch-test - env: - TEST_ADMIN_DSN: ${{ secrets.TEST_ADMIN_DSN }} - REQUIRE_DB: "1" steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version: "1.25" - - name: Tests (common) + - name: Wegwerf-Postgres starten + run: scripts/ci-pg-cluster.sh start + - name: common working-directory: common - run: go test ./testdb/... ./migrate/... -count=1 -p 1 + run: go test ./... -count=1 -p 1 + - name: archive + working-directory: archive + run: go test ./... -count=1 -p 1 + - name: ai + working-directory: ai + run: go test ./... -count=1 -p 1 + - name: connect + working-directory: connect + run: go test ./... -count=1 -p 1 + - name: Wegwerf-Postgres stoppen + if: always() + run: scripts/ci-pg-cluster.sh stop diff --git a/scripts/ci-pg-cluster.sh b/scripts/ci-pg-cluster.sh new file mode 100755 index 00000000..b41db8e7 --- /dev/null +++ b/scripts/ci-pg-cluster.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# Startet/stoppt einen Wegwerf-Postgres fuer CI-DB-Tests (kein Secret, keine feste DB). +set -euo pipefail + +PGBIN=${PGBIN:-/usr/lib/postgresql/17/bin} +PREFIX=/tmp/nexarch-ci-pg. + +case "${1:-}" in +start) + dir=$(mktemp -d "${PREFIX}XXXXXX") + chown postgres:postgres "$dir" + port=$((55000 + RANDOM % 1000)) + while ss -ltn | grep -q ":$port "; do port=$((55000 + RANDOM % 1000)); done + runuser -u postgres -- "$PGBIN/initdb" -D "$dir/data" -A trust -U postgres >/dev/null + runuser -u postgres -- "$PGBIN/pg_ctl" -D "$dir/data" -l "$dir/log" -w \ + -o "-p $port -c listen_addresses=127.0.0.1 -c unix_socket_directories=$dir" start >/dev/null + for db in admin_t tenant_a tenant_b; do + "$PGBIN/psql" -h 127.0.0.1 -p "$port" -U postgres -qc "create database $db" + done + base="postgres://postgres@127.0.0.1:$port" + { + echo "NEXARCH_CI_PGDIR=$dir" + echo "TEST_ADMIN_DSN=$base/admin_t?sslmode=disable" + echo "TEST_TENANT_DSN=$base/tenant_a?sslmode=disable" + echo "TEST_TENANT_DSN_B=$base/tenant_b?sslmode=disable" + echo "REQUIRE_DB=1" + } >> "${GITHUB_ENV:-/dev/stdout}" + ;; +stop) + dir=${NEXARCH_CI_PGDIR:-} + case "$dir" in "$PREFIX"*) ;; *) echo "kein CI-Cluster zu stoppen" ; exit 0 ;; esac + runuser -u postgres -- "$PGBIN/pg_ctl" -D "$dir/data" -m fast stop >/dev/null || true + rm -rf "$dir" + ;; +*) + echo "Aufruf: $0 start|stop" >&2 + exit 2 + ;; +esac -- 2.47.3 From 5f1d43caf1ff8c94588863d685f48b923c8b6636 Mon Sep 17 00:00:00 2001 From: patrick Date: Wed, 28 Oct 2026 10:28:26 +0100 Subject: [PATCH 2/2] CI-Cluster: Admin-DSN auf Datenbank postgres (Root-Tests ersetzen /postgres? im DSN) Co-Authored-By: Claude Sonnet 5.5 --- scripts/ci-pg-cluster.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci-pg-cluster.sh b/scripts/ci-pg-cluster.sh index b41db8e7..8de0776a 100755 --- a/scripts/ci-pg-cluster.sh +++ b/scripts/ci-pg-cluster.sh @@ -14,13 +14,13 @@ start) runuser -u postgres -- "$PGBIN/initdb" -D "$dir/data" -A trust -U postgres >/dev/null runuser -u postgres -- "$PGBIN/pg_ctl" -D "$dir/data" -l "$dir/log" -w \ -o "-p $port -c listen_addresses=127.0.0.1 -c unix_socket_directories=$dir" start >/dev/null - for db in admin_t tenant_a tenant_b; do + for db in tenant_a tenant_b; do "$PGBIN/psql" -h 127.0.0.1 -p "$port" -U postgres -qc "create database $db" done base="postgres://postgres@127.0.0.1:$port" { echo "NEXARCH_CI_PGDIR=$dir" - echo "TEST_ADMIN_DSN=$base/admin_t?sslmode=disable" + echo "TEST_ADMIN_DSN=$base/postgres?sslmode=disable" echo "TEST_TENANT_DSN=$base/tenant_a?sslmode=disable" echo "TEST_TENANT_DSN_B=$base/tenant_b?sslmode=disable" echo "REQUIRE_DB=1" -- 2.47.3