From 53bdd9579facbea9ea4e4849316d2805807f1d1e Mon Sep 17 00:00:00 2001 From: Gabriel Radureau Date: Tue, 7 Apr 2026 19:19:53 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20PostgreSQL=20service?= =?UTF-8?q?=20support=20for=20BDD=20tests=20in=20CI/CD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci-cd.yaml | 51 +++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/ci-cd.yaml b/.gitea/workflows/ci-cd.yaml index ff6e81e..ebe2cc0 100644 --- a/.gitea/workflows/ci-cd.yaml +++ b/.gitea/workflows/ci-cd.yaml @@ -124,10 +124,28 @@ jobs: runs-on: ubuntu-latest-ca if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'ci-bot'" + services: + postgres: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: dance_lessons_coach_bdd_test + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + steps: - name: Checkout code uses: actions/checkout@v4 + - name: Install PostgreSQL client + run: sudo apt-get update && sudo apt-get install -y postgresql-client + - name: Login to Gitea Container Registry uses: docker/login-action@v3 with: @@ -170,17 +188,46 @@ jobs: go build ./... fi + - name: Wait for PostgreSQL to be ready + run: | + echo "Waiting for PostgreSQL to be ready..." + for i in {1..30}; do + if pg_isready -h localhost -p 5432 -U postgres -d dance_lessons_coach_bdd_test; then + echo "✅ PostgreSQL is ready!" + break + fi + echo "Waiting for PostgreSQL... ($i/30)" + sleep 2 + done + + # Verify PostgreSQL is accessible + if ! pg_isready -h localhost -p 5432 -U postgres -d dance_lessons_coach_bdd_test; then + echo "❌ PostgreSQL failed to start" + exit 1 + fi + - name: Run tests with coverage using Docker cache run: | if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then - echo "Running in Docker cache..." + echo "Running in Docker cache with PostgreSQL support..." docker run --rm \ + --network host \ -v "$(pwd):/workspace" \ -w /workspace \ + -e PGHOST=localhost \ + -e PGPORT=5432 \ + -e PGUSER=postgres \ + -e PGPASSWORD=postgres \ + -e PGDATABASE=dance_lessons_coach_bdd_test \ ${{ env.CACHE_IMAGE }} \ sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt" else - echo "Running natively..." + echo "Running natively with PostgreSQL..." + export PGHOST=localhost + export PGPORT=5432 + export PGUSER=postgres + export PGPASSWORD=postgres + export PGDATABASE=dance_lessons_coach_bdd_test go test ./... -coverprofile=coverage.out -v go tool cover -func=coverage.out > coverage.txt fi