diff --git a/.forgejo/scripts/supabase-db-tests.sh b/.forgejo/scripts/supabase-db-tests.sh new file mode 100755 index 0000000..3c43241 --- /dev/null +++ b/.forgejo/scripts/supabase-db-tests.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# pgTAP-Tests gegen den laufenden Supabase-Stack ausführen, wenn der Docker-Daemon remote ist +# (DOCKER_HOST=tcp://..., z. B. dind). `supabase test db` bindet supabase/tests per Host-Pfad ein; +# dieser Pfad existiert im dind nicht (Ergebnis: "no pgTAP tests found"). Daher: Tests per +# `docker cp` in einen pg_prove-Container kopieren. Voraussetzung: `supabase start` lief. +set -euo pipefail + +PROJECT_ID="${SUPABASE_PROJECT_ID:-shuffle}" # = project_id in supabase/config.toml +PG_PROVE_IMAGE="${PG_PROVE_IMAGE:-public.ecr.aws/supabase/pg_prove:3.36}" # wie in Supabase CLI 3.0.0 + +# pgTAP wie `supabase test db` vorab aktivieren (die Tests rufen nur plan() etc. auf) +docker exec "supabase_db_${PROJECT_ID}" psql -U postgres -d postgres -v ON_ERROR_STOP=1 \ + -c "create extension if not exists pgtap with schema extensions" + +cid=$(docker create --network "supabase_network_${PROJECT_ID}" -e PGPASSWORD=postgres \ + "$PG_PROVE_IMAGE" pg_prove --ext .sql -r -h "supabase_db_${PROJECT_ID}" -U postgres -d postgres /tests) +trap 'docker rm -f "$cid" >/dev/null 2>&1 || true' EXIT +docker cp supabase/tests "$cid:/" +docker start -a "$cid" diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 77cb8ee..a480a10 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -147,21 +147,38 @@ jobs: if [ -n "$changed" ]; then echo "Geänderte bestehende Migrationen: $changed"; exit 1; fi fi - # RLS-/pgTAP-Tests: braucht einen Runner mit Docker-Socket (Label "docker-host"). + # RLS-/pgTAP-Tests: braucht einen Runner mit Docker-Zugriff (Label "docker-host"). + # Der Job-Container hat kein Docker-CLI und keinen Socket (Isolation, Repo ist öffentlich). Stattdessen + # wird ein gepinntes Docker-CLI installiert und der dind-Daemon des Runners per TCP angesprochen + # (erreichbar über das Default-Gateway des Job-Netzes). Supabase-Ports liegen dann im dind; + # die Supabase-CLI nimmt den Host aus DOCKER_HOST automatisch. # Nutzt die eingecheckte supabase/config.toml. Ohne passenden Runner Job bei Bedarf deaktivieren. supabase-tests: runs-on: docker-host + env: + DOCKER_CLI_VERSION: 27.3.1 + DIND_PORT: 2375 steps: - uses: https://code.forgejo.org/actions/checkout@v4 - - uses: https://code.forgejo.org/actions/setup-node@v4 - with: - node-version: 22 - - name: Supabase starten und Datenbanktests ausführen + - name: Docker-CLI installieren und dind anbinden + run: | + arch=$(uname -m) + curl -fsSL "https://download.docker.com/linux/static/stable/${arch}/docker-${DOCKER_CLI_VERSION}.tgz" \ + | tar -xz -C /usr/local/bin --strip-components=1 docker/docker + # Default-Gateway des Job-Containers (= dind-Host) aus /proc/net/route; `ip` fehlt im Image + hex=$(awk '$2=="00000000"{print $3; exit}' /proc/net/route) + gw=$(printf '%d.%d.%d.%d' "0x${hex:6:2}" "0x${hex:4:2}" "0x${hex:2:2}" "0x${hex:0:2}") + echo "DOCKER_HOST=tcp://${gw}:${DIND_PORT}" >> "$GITHUB_ENV" + DOCKER_HOST="tcp://${gw}:${DIND_PORT}" docker version --format 'dind {{.Server.Version}}' + - name: Supabase starten run: | test -f supabase/config.toml || { echo "supabase/config.toml fehlt"; exit 1; } test -d supabase/migrations || { echo "Keine Migrationen – übersprungen"; exit 0; } npx --yes supabase@${{ env.SUPABASE_CLI_VERSION }} start -x studio,imgproxy,edge-runtime,logflare,vector - npx --yes supabase@${{ env.SUPABASE_CLI_VERSION }} test db + - name: Datenbanktests (pgTAP) + run: | + test -d supabase/migrations || exit 0 + bash .forgejo/scripts/supabase-db-tests.sh - name: Aufräumen if: always() run: npx --yes supabase@${{ env.SUPABASE_CLI_VERSION }} stop --no-backup || true