Skip to content

Commit 7251823

Browse files
committed
Postgres instance on CI.
1 parent 9930cbe commit 7251823

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

.github/workflows/all-test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ jobs:
4646
matrix:
4747
shard: [0, 1, 2, 3, 4, 5, 6, 7]
4848
runs-on: ubuntu-latest
49+
services:
50+
postgres:
51+
image: postgres
52+
env:
53+
POSTGRES_PASSWORD: postgres
54+
# Set health checks to wait until postgres has started
55+
options: >-
56+
--health-cmd pg_isready
57+
--health-interval 10s
58+
--health-timeout 5s
59+
--health-retries 5
60+
ports:
61+
- 5432:5432
4962
steps:
5063
- name: Cache PUB_CACHE
5164
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
@@ -63,6 +76,8 @@ jobs:
6376
run: sudo apt-get update -yq && sudo apt-get install webp
6477
- run: dart test -P presubmit --shard-index ${{matrix.shard}} --total-shards 8
6578
working-directory: app/
79+
env:
80+
PUB_POSTGRES_URL: postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable
6681

6782
define_pkg_list:
6883
runs-on: ubuntu-latest

app/lib/shared/env_config.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class _EnvConfig {
5050
late final fakeEmailSenderOutputDir =
5151
Platform.environment['FAKE_EMAIL_SENDER_OUTPUT_DIR'];
5252

53+
/// When specified, the server will connect to this URL for postgres database connections.
54+
late final pubPostgresUrl = Platform.environment['PUB_POSTGRES_URL'];
55+
5356
/// True, if running inside AppEngine.
5457
bool get isRunningInAppengine => _gaeService != null && _gaeVersion != null;
5558

app/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ dependencies:
4949
pana: '0.22.23'
5050
# 3rd-party packages with pinned versions
5151
mailer: '6.5.0'
52+
postgres: '3.5.7'
5253
ulid: '2.0.1'
5354
tar: '2.0.0'
5455
api_builder:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:clock/clock.dart';
6+
import 'package:postgres/postgres.dart';
7+
import 'package:pub_dev/shared/env_config.dart';
8+
import 'package:test/test.dart';
9+
10+
void main() {
11+
group('Postgresql connection on CI', () {
12+
test('connects to CI instance', () async {
13+
final pubPostgresUrl = envConfig.pubPostgresUrl;
14+
if (pubPostgresUrl == null) {
15+
markTestSkipped('PUB_POSTGRES_URL was not specified.');
16+
return;
17+
}
18+
try {
19+
await Connection.open(
20+
Endpoint(host: 'localhost', database: 'postgres'),
21+
);
22+
} catch (e, st) {
23+
print(e);
24+
print(st);
25+
}
26+
final conn = await Connection.openFromUrl(pubPostgresUrl);
27+
final rs1 = await conn.execute('SELECT 1;');
28+
expect(rs1[0][0], 1);
29+
30+
final dbName =
31+
'pubtemp_${clock.now().millisecondsSinceEpoch.toRadixString(36)}';
32+
await conn.execute('CREATE DATABASE $dbName');
33+
await conn.execute('DROP DATABASE $dbName');
34+
});
35+
});
36+
}

pubspec.lock

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ packages:
7373
url: "https://pub.dev"
7474
source: hosted
7575
version: "2.1.2"
76+
buffer:
77+
dependency: transitive
78+
description:
79+
name: buffer
80+
sha256: "389da2ec2c16283c8787e0adaede82b1842102f8c8aae2f49003a766c5c6b3d1"
81+
url: "https://pub.dev"
82+
source: hosted
83+
version: "1.2.3"
7684
build:
7785
dependency: transitive
7886
description:
@@ -649,6 +657,14 @@ packages:
649657
url: "https://pub.dev"
650658
source: hosted
651659
version: "1.5.1"
660+
postgres:
661+
dependency: transitive
662+
description:
663+
name: postgres
664+
sha256: "013c6dc668eaab9771c4d3f5fc3e87ed4b3cd4ab3587ac6943cc1f38509ff723"
665+
url: "https://pub.dev"
666+
source: hosted
667+
version: "3.5.7"
652668
protobuf:
653669
dependency: transitive
654670
description:
@@ -705,6 +721,22 @@ packages:
705721
url: "https://pub.dev"
706722
source: hosted
707723
version: "2.1.0"
724+
sasl_scram:
725+
dependency: transitive
726+
description:
727+
name: sasl_scram
728+
sha256: a47207a436eb650f8fdcf54a2e2587b850dc3caef9973ce01f332b07a6fc9cb9
729+
url: "https://pub.dev"
730+
source: hosted
731+
version: "0.1.1"
732+
saslprep:
733+
dependency: transitive
734+
description:
735+
name: saslprep
736+
sha256: "3d421d10be9513bf4459c17c5e70e7b8bc718c9fc5ad4ba5eb4f5fd27396f740"
737+
url: "https://pub.dev"
738+
source: hosted
739+
version: "1.0.3"
708740
sass:
709741
dependency: transitive
710742
description:
@@ -921,6 +953,14 @@ packages:
921953
url: "https://pub.dev"
922954
source: hosted
923955
version: "2.0.1"
956+
unorm_dart:
957+
dependency: transitive
958+
description:
959+
name: unorm_dart
960+
sha256: "0c69186b03ca6addab0774bcc0f4f17b88d4ce78d9d4d8f0619e30a99ead58e7"
961+
url: "https://pub.dev"
962+
source: hosted
963+
version: "0.3.2"
924964
uuid:
925965
dependency: transitive
926966
description:

0 commit comments

Comments
 (0)