From f349f95e1d44bc7b292179f678569c67aee5892a Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Fri, 14 Jun 2024 11:51:42 -0500 Subject: [PATCH] Make Postgres and MySQL connection params separately configurable, take another whack at the CI --- .github/workflows/test.yml | 91 ++++++++++++++++++- .../QueuesFluentDriverTests.swift | 22 ++--- 2 files changed, 98 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3dbf46d..8cddaa8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,90 @@ on: push: { branches: [ main ] } jobs: - unit-tests: - uses: vapor/ci/.github/workflows/run-unit-tests.yml@main - secrets: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + api-breakage: + if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft }} + runs-on: ubuntu-latest + container: swift:noble + timeout-minutes: 30 + steps: + - name: Check out code + uses: actions/checkout@v4 + with: { 'fetch-depth': 0 } + - name: Run API breakage check + run: | + git config --global --add safe.directory "${GITHUB_WORKSPACE}" + swift package diagnose-api-breaking-changes origin/main + + linux-unit: + if: ${{ !(github.event.pull_request.draft || false) }} + strategy: + fail-fast: false + matrix: + swift-image: + - swift:5.8-jammy + - swift:5.9-jammy + - swift:5.10-noble + - swiftlang/swift:nightly-6.0-jammy + - swiftlang/swift:nightly-main-jammy + runs-on: ubuntu-latest + container: ${{ matrix.swift-image }} + services: + psql: { image: 'postgres:16', env: { POSTGRES_USER: test_username, POSTGRES_PASSWORD: test_password, POSTGRES_DB: test_database, POSTGRES_HOST_AUTH_METHOD: scram-sha-256, POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256 } } + mysql: { image: 'mysql:8', env: { MYSQL_ALLOW_EMPTY_PASSWORD: true, MYSQL_USER: test_username, MYSQL_PASSWORD: test_password, MYSQL_DATABASE: test_database } } + timeout-minutes: 60 + steps: + - name: Check out code + uses: actions/checkout@v4 + - name: Run unit tests + env: + POSTGRES_HOST: psql + MYSQL_HOST: mysql + run: SWIFT_DETERMINISTIC_HASHING=1 swift test --sanitize=thread --enable-code-coverage + - name: Upload coverage data + uses: vapor/swift-codecov-action@v0.3 + with: + codecov_token: ${{ secrets.CODECOV_TOKEN || '' }} + + macos-unit: + if: ${{ !(github.event.pull_request.draft || false) }} + strategy: + fail-fast: false + matrix: + include: + - macos-version: macos-13 + xcode-version: '~15.2' + - macos-version: macos-14 + xcode-version: latest-stable + runs-on: ${{ matrix.macos-version }} + timeout-minutes: 60 + steps: + - name: Select appropriate Xcode version + uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: ${{ matrix.xcode-version }} + - name: Install and setup Postgres and MySQL + run: | + export PATH="$(brew --prefix)/opt/postgresql@16/bin:$PATH" PGDATA=/tmp/vapor-postgres-test + (brew upgrade python@3.11 || true) && (brew link --force --overwrite python@3.11 || true) + (brew upgrade python@3.12 || true) && (brew link --force --overwrite python@3.12 || true) + (brew upgrade || true) + brew install --overwrite postgresql@16 && brew link --overwrite --force postgresql@16 + initdb --locale=C --auth-host scram-sha-256 -U test_username --pwfile=<(echo test_password) + pg_ctl start --wait + PGPASSWORD=test_password createdb -w -O test_username test_database + PGPASSWORD=test_password psql -w test_database <<<"ALTER SCHEMA public OWNER TO test_username;" + brew install mysql && brew link --force mysql && brew services start mysql + until echo | mysql -uroot; do sleep 1; done + mysql -uroot --batch <<-'SQL' + CREATE USER test_username@localhost IDENTIFIED BY 'test_password'; + CREATE DATABASE test_database; + GRANT ALL PRIVILEGES ON test_database.* TO test_username@localhost; + SQL + - name: Check out code + uses: actions/checkout@v4 + - name: Run unit tests + run: SWIFT_DETERMINISTIC_HASHING=1 swift test --sanitize=thread --eanble-code-coverage + - name: Upload coverage data + uses: vapor/swift-codecov-action@v0.3 + with: + codecov_token: ${{ secrets.CODECOV_TOKEN || '' }} diff --git a/Tests/QueuesFluentDriverTests/QueuesFluentDriverTests.swift b/Tests/QueuesFluentDriverTests/QueuesFluentDriverTests.swift index 50a327c..f12e4d5 100644 --- a/Tests/QueuesFluentDriverTests/QueuesFluentDriverTests.swift +++ b/Tests/QueuesFluentDriverTests/QueuesFluentDriverTests.swift @@ -28,11 +28,11 @@ final class QueuesFluentDriverTests: XCTestCase { #if canImport(FluentPostgresDriver) app.databases.use(DatabaseConfigurationFactory.postgres(configuration: .init( - hostname: Environment.get("DATABASE_HOST") ?? "localhost", - port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? SQLPostgresConfiguration.ianaPortNumber, - username: Environment.get("DATABASE_USERNAME") ?? "test_username", - password: Environment.get("DATABASE_PASSWORD") ?? "test_password", - database: Environment.get("DATABASE_NAME") ?? "test_database", + hostname: env("POSTGRES_HOST") ?? env("DATABASE_HOST") ?? "localhost", + port: (env("POSTGRES_PORT") ?? env("DATABASE_PORT")).flatMap(Int.init(_:)) ?? SQLPostgresConfiguration.ianaPortNumber, + username: env("POSTGRES_USERNAME") ?? env("DATABASE_USERNAME") ?? "test_username", + password: env("POSTGRES_PASSWORD") ?? env("DATABASE_PASSWORD") ?? "test_password", + database: env("POSTGRES_NAME") ?? env("DATABASE_NAME") ?? "test_database", tls: .prefer(try .init(configuration: .clientDefault))) ), as: .psql) #endif @@ -41,11 +41,11 @@ final class QueuesFluentDriverTests: XCTestCase { var config = TLSConfiguration.clientDefault config.certificateVerification = .none app.databases.use(DatabaseConfigurationFactory.mysql(configuration: .init( - hostname: Environment.get("DATABASE_HOST") ?? "localhost", - port: Environment.get("DATABASE_PORT").flatMap(Int.init(_:)) ?? MySQLConfiguration.ianaPortNumber, - username: Environment.get("DATABASE_USERNAME") ?? "test_username", - password: Environment.get("DATABASE_PASSWORD") ?? "test_password", - database: Environment.get("DATABASE_NAME") ?? "test_database", + hostname: env("MYSQL_HOST") ?? env("DATABASE_HOST") ?? "localhost", + port: (env("MYSQL_PORT") ?? env("DATABASE_PORT")).flatMap(Int.init(_:)) ?? MySQLConfiguration.ianaPortNumber, + username: env("MYSQL_USERNAME") ?? env("DATABASE_USERNAME") ?? "test_username", + password: env("MYSQL_PASSWORD") ?? env("DATABASE_PASSWORD") ?? "test_password", + database: env("MYSQL_NAME") ?? env("DATABASE_NAME") ?? "test_database", tlsConfiguration: config )), as: .mysql) #endif @@ -277,7 +277,7 @@ func XCTAssertNotNilAsync( } func env(_ name: String) -> String? { - return ProcessInfo.processInfo.environment[name] + ProcessInfo.processInfo.environment[name] } let isLoggingConfigured: Bool = {