Skip to content

Commit 5d0f55d

Browse files
committed
Update CI workflow to support multiple age images and add CNPG_TEST environment variable handling
1 parent bc8f52c commit 5d0f55d

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed

.github/workflows/tests.yml

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,63 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
age_image:
16-
- release_PG16_1.5.0
17-
- release_PG16_1.6.0
18-
- dev_snapshot_PG17
15+
include:
16+
- age_image: release_PG16_1.5.0
17+
type: apache
18+
- age_image: release_PG16_1.6.0
19+
type: apache
20+
- age_image: dev_snapshot_PG17
21+
type: apache
22+
- age_image: ghcr.io/konnektr-io/age:16-1.5.0-standard-bookworm
23+
type: cnpg
24+
- age_image: ghcr.io/konnektr-io/age:16-1.5.0-standard-trixie
25+
type: cnpg
26+
- age_image: ghcr.io/konnektr-io/age:16-1.6.0-standard-bookworm
27+
type: cnpg
28+
- age_image: ghcr.io/konnektr-io/age:16-1.6.0-standard-trixie
29+
type: cnpg
30+
- age_image: ghcr.io/konnektr-io/age:17-1.6.0-standard-trixie
31+
type: cnpg
1932
steps:
33+
- name: Run CNPG AGE init SQL
34+
if: matrix.type == 'cnpg'
35+
run: |
36+
for i in {1..30}; do
37+
if docker exec postgres-test-cnpg pg_isready -U app -d app; then
38+
echo "PostgreSQL is ready for init";
39+
break;
40+
fi;
41+
echo "Waiting for PostgreSQL (init)...";
42+
sleep 5;
43+
done
44+
docker exec -u app postgres-test-cnpg psql -U app -d app -c "CREATE EXTENSION age;"
45+
docker exec -u app postgres-test-cnpg psql -U app -d app -c "GRANT SELECT ON ag_catalog.ag_graph TO app;"
46+
docker exec -u app postgres-test-cnpg psql -U app -d app -c "GRANT USAGE ON SCHEMA ag_catalog TO app;"
2047
- name: Checkout
2148
uses: actions/checkout@v4
2249

2350
- name: Start PostgreSQL with AGE extension
2451
run: |
25-
docker run --name postgres-test-${{ matrix.age_image }} \
26-
-e POSTGRES_USER=postgres \
27-
-e POSTGRES_PASSWORD=postgres \
28-
-e POSTGRES_DB=agedotnet_tests \
29-
-p 5432:5432 \
30-
-d apache/age:${{ matrix.age_image }}
52+
if [ "${{ matrix.type }}" = "cnpg" ]; then
53+
docker run --name postgres-test-cnpg \
54+
-e POSTGRES_USER=app \
55+
-e POSTGRES_PASSWORD=app \
56+
-e POSTGRES_DB=app \
57+
-p 5432:5432 \
58+
-d ${{ matrix.age_image }}
59+
else
60+
docker run --name postgres-test-${{ matrix.age_image }} \
61+
-e POSTGRES_USER=app \
62+
-e POSTGRES_PASSWORD=app \
63+
-e POSTGRES_DB=app \
64+
-p 5432:5432 \
65+
-d apache/age:${{ matrix.age_image }}
66+
fi
3167
3268
- name: Wait for PostgreSQL to be ready
3369
run: |
3470
for i in {1..30}; do
35-
if docker exec postgres-test-${{ matrix.age_image }} pg_isready -U postgres -d agedotnet_tests; then
71+
if docker exec postgres-test-${{ matrix.age_image }} pg_isready -U postgres -d app; then
3672
echo "PostgreSQL is ready";
3773
sleep 5;
3874
exit 0;
@@ -58,7 +94,11 @@ jobs:
5894
run: dotnet build --no-restore
5995

6096
- name: Test with dotnet
61-
run: dotnet test --logger 'GitHubActions' --logger 'console;verbosity=normal' --blame-hang --blame-hang-timeout 5m
97+
run: |
98+
if [ "${{ matrix.type }}" = "cnpg" ]; then
99+
export CNPG_TEST=true
100+
fi
101+
dotnet test --logger 'GitHubActions' --logger 'console;verbosity=normal' --blame-hang --blame-hang-timeout 5m
62102
63103
- name: Stop PostgreSQL container
64104
if: always()

test/Npgsql.AgeTests/TestBase.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ public TestBase()
2323
var dataSourceBuilder = new NpgsqlDataSourceBuilder(
2424
connectionStringBuilder.ConnectionString
2525
);
26-
_dataSource = dataSourceBuilder.UseAge().Build();
26+
// UseAge(true) for CNPG images, controlled by CNPG_TEST env var
27+
var cnpgTest = Environment.GetEnvironmentVariable("CNPG_TEST");
28+
if (!string.IsNullOrEmpty(cnpgTest) && cnpgTest.ToLowerInvariant() == "true")
29+
{
30+
_dataSource = dataSourceBuilder.UseAge(true).Build();
31+
}
32+
else
33+
{
34+
_dataSource = dataSourceBuilder.UseAge().Build();
35+
}
2736
}
2837

2938
public void Dispose()

test/Npgsql.AgeTests/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
},
88
"AllowedHosts": "*",
99
"ConnectionStrings": {
10-
"AgeConnectionString": "Server=localhost;Port=5432;Database=agedotnet_tests;Username=postgres;Password=postgres"
10+
"AgeConnectionString": "Server=localhost;Port=5432;Database=app;Username=app;Password=app"
1111
}
1212
}

0 commit comments

Comments
 (0)