Skip to content

Commit 6069224

Browse files
authored
Postgres instance on CI. (#8985)
1 parent 412b3f2 commit 6069224

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-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@0057852bfaa89a56745cba8c7296529d2fc39830
@@ -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.8'
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: 16 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: "96d7f40e079b96cdbfed13d71c64668cfd79c35bc17223c6b3ac0ca63bff72f0"
665+
url: "https://pub.dev"
666+
source: hosted
667+
version: "3.5.8"
652668
protobuf:
653669
dependency: transitive
654670
description:

0 commit comments

Comments
 (0)