Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/all-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ jobs:
matrix:
shard: [0, 1, 2, 3, 4, 5, 6, 7]
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Cache PUB_CACHE
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
Expand All @@ -63,6 +76,8 @@ jobs:
run: sudo apt-get update -yq && sudo apt-get install webp
- run: dart test -P presubmit --shard-index ${{matrix.shard}} --total-shards 8
working-directory: app/
env:
PUB_POSTGRES_URL: postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable

define_pkg_list:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions app/lib/shared/env_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class _EnvConfig {
late final fakeEmailSenderOutputDir =
Platform.environment['FAKE_EMAIL_SENDER_OUTPUT_DIR'];

/// When specified, the server will connect to this URL for postgres database connections.
late final pubPostgresUrl = Platform.environment['PUB_POSTGRES_URL'];

/// True, if running inside AppEngine.
bool get isRunningInAppengine => _gaeService != null && _gaeVersion != null;

Expand Down
1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies:
pana: '0.22.23'
# 3rd-party packages with pinned versions
mailer: '6.5.0'
postgres: '3.5.8'
ulid: '2.0.1'
tar: '2.0.0'
api_builder:
Expand Down
36 changes: 36 additions & 0 deletions app/test/shared/postgresql_ci_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:clock/clock.dart';
import 'package:postgres/postgres.dart';
import 'package:pub_dev/shared/env_config.dart';
import 'package:test/test.dart';

void main() {
group('Postgresql connection on CI', () {
test('connects to CI instance', () async {
final pubPostgresUrl = envConfig.pubPostgresUrl;
if (pubPostgresUrl == null) {
markTestSkipped('PUB_POSTGRES_URL was not specified.');
return;
}
try {
await Connection.open(
Endpoint(host: 'localhost', database: 'postgres'),
);
} catch (e, st) {
print(e);
print(st);
}
final conn = await Connection.openFromUrl(pubPostgresUrl);
final rs1 = await conn.execute('SELECT 1;');
expect(rs1[0][0], 1);

final dbName =
'pubtemp_${clock.now().millisecondsSinceEpoch.toRadixString(36)}';
await conn.execute('CREATE DATABASE $dbName');
await conn.execute('DROP DATABASE $dbName');
});
});
}
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
buffer:
dependency: transitive
description:
name: buffer
sha256: "389da2ec2c16283c8787e0adaede82b1842102f8c8aae2f49003a766c5c6b3d1"
url: "https://pub.dev"
source: hosted
version: "1.2.3"
build:
dependency: transitive
description:
Expand Down Expand Up @@ -649,6 +657,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.5.1"
postgres:
dependency: transitive
description:
name: postgres
sha256: "96d7f40e079b96cdbfed13d71c64668cfd79c35bc17223c6b3ac0ca63bff72f0"
url: "https://pub.dev"
source: hosted
version: "3.5.8"
protobuf:
dependency: transitive
description:
Expand Down