Skip to content

Run Tests

Run Tests #63

Workflow file for this run

name: Run Tests
on:
workflow_dispatch:
pull_request:
branches:
- "main"
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- age_image: release_PG16_1.5.0
type: apache
- age_image: release_PG16_1.6.0
type: apache
- age_image: dev_snapshot_PG17
type: apache
- age_image: 16-1.5.0-standard-bookworm
type: cnpg
- age_image: 16-1.5.0-standard-trixie
type: cnpg
- age_image: 16-1.6.0-standard-bookworm
type: cnpg
- age_image: 16-1.6.0-standard-trixie
type: cnpg
- age_image: 17-1.6.0-standard-trixie
type: cnpg
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Start PostgreSQL with AGE extension
run: |
if [ "${{ matrix.type }}" = "cnpg" ]; then
docker run --name postgres-test-${{ matrix.age_image }} \
-e POSTGRES_PASSWORD=app \
-p 5432:5432 \
--shm-size=512mb \
-d ghcr.io/konnektr-io/age:${{ matrix.age_image }} \
bash -c "initdb -D /var/lib/postgresql/data --username=app --pwfile=<(echo app) && \
echo 'host all all 0.0.0.0/0 trust' >> /var/lib/postgresql/data/pg_hba.conf && \
echo 'local all all trust' >> /var/lib/postgresql/data/pg_hba.conf && \
postgres -D /var/lib/postgresql/data \
-c listen_addresses='*'"
else
docker run --name postgres-test-${{ matrix.age_image }} \
-e POSTGRES_USER=app \
-e POSTGRES_PASSWORD=app \
-e POSTGRES_DB=app \
-p 5432:5432 \
-d apache/age:${{ matrix.age_image }}
fi
- name: Run CNPG AGE init SQL
if: matrix.type == 'cnpg'
run: |
for i in {1..30}; do
if docker exec postgres-test-${{ matrix.age_image }} pg_isready -U app -d app; then
echo "PostgreSQL is ready for init";
break;
fi;
echo "Waiting for PostgreSQL (init)...";
sleep 5;
done
echo "Running initialization ..."
docker exec postgres-test-${{ matrix.age_image }} psql -U app -d app -c "CREATE EXTENSION age;"
docker exec postgres-test-${{ matrix.age_image }} psql -U app -d app -c "GRANT SELECT ON ag_catalog.ag_graph TO app;"
docker exec postgres-test-${{ matrix.age_image }} psql -U app -d app -c "GRANT USAGE ON SCHEMA ag_catalog TO app;"
echo "Database initialized successfully"
- name: Wait for PostgreSQL to be ready
if: matrix.type != 'cnpg'
run: |
for i in {1..30}; do
if docker exec postgres-test-${{ matrix.age_image }} pg_isready -U postgres -d app; then
echo "PostgreSQL is ready";
sleep 5;
exit 0;
fi;
echo "Waiting for PostgreSQL...";
sleep 5;
done
echo "PostgreSQL did not become ready in time";
exit 1;
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
6.0.x
8.0.x
9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test with dotnet
run: |
if [ "${{ matrix.type }}" = "cnpg" ]; then
export CNPG_TEST=true
fi
dotnet test --logger 'GitHubActions' --logger 'console;verbosity=normal' --blame-hang --blame-hang-timeout 5m
- name: Stop PostgreSQL container
if: always()
run: |
docker stop postgres-test-${{ matrix.age_image }} || true
docker rm postgres-test-${{ matrix.age_image }} || true