✨ feat: add PostgreSQL service support for BDD tests in CI/CD
This commit is contained in:
@@ -124,10 +124,28 @@ jobs:
|
|||||||
runs-on: ubuntu-latest-ca
|
runs-on: ubuntu-latest-ca
|
||||||
if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'ci-bot'"
|
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:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
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
|
- name: Login to Gitea Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
@@ -170,17 +188,46 @@ jobs:
|
|||||||
go build ./...
|
go build ./...
|
||||||
fi
|
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
|
- name: Run tests with coverage using Docker cache
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||||
echo "Running in Docker cache..."
|
echo "Running in Docker cache with PostgreSQL support..."
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
|
--network host \
|
||||||
-v "$(pwd):/workspace" \
|
-v "$(pwd):/workspace" \
|
||||||
-w /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 }} \
|
${{ env.CACHE_IMAGE }} \
|
||||||
sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
|
sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
|
||||||
else
|
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 test ./... -coverprofile=coverage.out -v
|
||||||
go tool cover -func=coverage.out > coverage.txt
|
go tool cover -func=coverage.out > coverage.txt
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user