From dd708e75c76fce19d8c9a1c1b5b0f9fff4a155ed Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Thu, 2 Oct 2025 13:10:32 +0200 Subject: [PATCH 1/2] Postgres instance on CI. --- .github/workflows/all-test.yml | 15 ++++++++++ app/lib/shared/env_config.dart | 3 ++ app/pubspec.yaml | 1 + app/test/shared/postgresql_ci_test.dart | 36 ++++++++++++++++++++++ pubspec.lock | 40 +++++++++++++++++++++++++ 5 files changed, 95 insertions(+) create mode 100644 app/test/shared/postgresql_ci_test.dart diff --git a/.github/workflows/all-test.yml b/.github/workflows/all-test.yml index 0538372216..66fdc9ea0b 100644 --- a/.github/workflows/all-test.yml +++ b/.github/workflows/all-test.yml @@ -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 @@ -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 diff --git a/app/lib/shared/env_config.dart b/app/lib/shared/env_config.dart index 0330737924..660f529cf9 100644 --- a/app/lib/shared/env_config.dart +++ b/app/lib/shared/env_config.dart @@ -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; diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 6ed50000a9..5a2fb66c1b 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -49,6 +49,7 @@ dependencies: pana: '0.22.23' # 3rd-party packages with pinned versions mailer: '6.5.0' + postgres: '3.5.7' ulid: '2.0.1' tar: '2.0.0' api_builder: diff --git a/app/test/shared/postgresql_ci_test.dart b/app/test/shared/postgresql_ci_test.dart new file mode 100644 index 0000000000..d5df7fa44f --- /dev/null +++ b/app/test/shared/postgresql_ci_test.dart @@ -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'); + }); + }); +} diff --git a/pubspec.lock b/pubspec.lock index d52fad8a22..3472d612a9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -649,6 +657,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.5.1" + postgres: + dependency: transitive + description: + name: postgres + sha256: "013c6dc668eaab9771c4d3f5fc3e87ed4b3cd4ab3587ac6943cc1f38509ff723" + url: "https://pub.dev" + source: hosted + version: "3.5.7" protobuf: dependency: transitive description: @@ -705,6 +721,22 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" + sasl_scram: + dependency: transitive + description: + name: sasl_scram + sha256: a47207a436eb650f8fdcf54a2e2587b850dc3caef9973ce01f332b07a6fc9cb9 + url: "https://pub.dev" + source: hosted + version: "0.1.1" + saslprep: + dependency: transitive + description: + name: saslprep + sha256: "3d421d10be9513bf4459c17c5e70e7b8bc718c9fc5ad4ba5eb4f5fd27396f740" + url: "https://pub.dev" + source: hosted + version: "1.0.3" sass: dependency: transitive description: @@ -921,6 +953,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.1" + unorm_dart: + dependency: transitive + description: + name: unorm_dart + sha256: "0c69186b03ca6addab0774bcc0f4f17b88d4ce78d9d4d8f0619e30a99ead58e7" + url: "https://pub.dev" + source: hosted + version: "0.3.2" uuid: dependency: transitive description: From a05d162e3c3685cef7908973c2f79d956f009d03 Mon Sep 17 00:00:00 2001 From: Istvan Soos Date: Sat, 4 Oct 2025 14:51:40 +0200 Subject: [PATCH 2/2] removing sasl_scram dependency from postgres --- app/pubspec.yaml | 2 +- pubspec.lock | 28 ++-------------------------- 2 files changed, 3 insertions(+), 27 deletions(-) diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 5a2fb66c1b..7830e4ef92 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -49,7 +49,7 @@ dependencies: pana: '0.22.23' # 3rd-party packages with pinned versions mailer: '6.5.0' - postgres: '3.5.7' + postgres: '3.5.8' ulid: '2.0.1' tar: '2.0.0' api_builder: diff --git a/pubspec.lock b/pubspec.lock index 3472d612a9..47ae927b33 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -661,10 +661,10 @@ packages: dependency: transitive description: name: postgres - sha256: "013c6dc668eaab9771c4d3f5fc3e87ed4b3cd4ab3587ac6943cc1f38509ff723" + sha256: "96d7f40e079b96cdbfed13d71c64668cfd79c35bc17223c6b3ac0ca63bff72f0" url: "https://pub.dev" source: hosted - version: "3.5.7" + version: "3.5.8" protobuf: dependency: transitive description: @@ -721,22 +721,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.0" - sasl_scram: - dependency: transitive - description: - name: sasl_scram - sha256: a47207a436eb650f8fdcf54a2e2587b850dc3caef9973ce01f332b07a6fc9cb9 - url: "https://pub.dev" - source: hosted - version: "0.1.1" - saslprep: - dependency: transitive - description: - name: saslprep - sha256: "3d421d10be9513bf4459c17c5e70e7b8bc718c9fc5ad4ba5eb4f5fd27396f740" - url: "https://pub.dev" - source: hosted - version: "1.0.3" sass: dependency: transitive description: @@ -953,14 +937,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.1" - unorm_dart: - dependency: transitive - description: - name: unorm_dart - sha256: "0c69186b03ca6addab0774bcc0f4f17b88d4ce78d9d4d8f0619e30a99ead58e7" - url: "https://pub.dev" - source: hosted - version: "0.3.2" uuid: dependency: transitive description: