feat: add PostgreSQL service support for BDD tests in CI/CD

This commit is contained in:
2026-04-07 19:19:53 +02:00
parent 4604ce7caa
commit 53bdd9579f

View File

@@ -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