From b3dfa1130ca7ebdc81fe3c929e2d79949160259e Mon Sep 17 00:00:00 2001 From: sabesh Date: Sun, 12 Feb 2023 16:25:55 +0530 Subject: [PATCH 1/4] Add `hostname` to `MySQLConnection.connect()` --- Sources/MySQLKit/MySQLConnectionSource.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/MySQLKit/MySQLConnectionSource.swift b/Sources/MySQLKit/MySQLConnectionSource.swift index b05dcd88..7ac9aaa9 100644 --- a/Sources/MySQLKit/MySQLConnectionSource.swift +++ b/Sources/MySQLKit/MySQLConnectionSource.swift @@ -18,6 +18,7 @@ public struct MySQLConnectionSource: ConnectionPoolSource { database: self.configuration.database ?? self.configuration.username, password: self.configuration.password, tlsConfiguration: self.configuration.tlsConfiguration, + serverHostname: self.configuration._hostname, logger: logger, on: eventLoop ) From 5bc52390aa70283d058f581d019280ff28f77ed3 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Tue, 11 Apr 2023 20:19:37 -0500 Subject: [PATCH 2/4] Temporary fix to support both plain IPs and SNI --- Sources/MySQLKit/MySQLConfiguration.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sources/MySQLKit/MySQLConfiguration.swift b/Sources/MySQLKit/MySQLConfiguration.swift index 12185665..7f89168a 100644 --- a/Sources/MySQLKit/MySQLConfiguration.swift +++ b/Sources/MySQLKit/MySQLConfiguration.swift @@ -1,6 +1,7 @@ import Foundation import NIOSSL import NIOCore +@_implementationOnly import NIOPosix // for inet_pton() public struct MySQLConfiguration { public var address: () throws -> SocketAddress @@ -84,7 +85,14 @@ public struct MySQLConfiguration { self.username = username self.database = database self.password = password - self.tlsConfiguration = tlsConfiguration - self._hostname = hostname + if let tlsConfiguration = tlsConfiguration { + self.tlsConfiguration = tlsConfiguration + + // Temporary fix - this logic should be removed once MySQLNIO is updated + var n4 = in_addr(), n6 = in6_addr() + if inet_pton(AF_INET, hostname, &n4) != 1 && inet_pton(AF_INET6, hostname, &n6) != 1 { + self._hostname = hostname + } + } } } From 6aa7149a181cb6d717251fbe0a89bde316cc89c5 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Tue, 11 Apr 2023 20:39:52 -0500 Subject: [PATCH 3/4] Apply CI updates --- .github/workflows/test.yml | 123 +++++++++++++++---------------------- 1 file changed, 48 insertions(+), 75 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6288c7ef..8013d12e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,9 @@ name: test +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true on: - pull_request: { branches: ['*'] } + pull_request: { types: [opened, reopened, synchronize, ready_for_review] } push: { branches: [ main ] } env: @@ -21,48 +24,15 @@ env: jobs: - codecov: - strategy: - # For MySQL we have to run coverage baselines against multiple DB versions thanks to - # the driver's behavior changing notably depending on the server. - matrix: { dbimage: ['mysql:5.7', 'mysql:8.0', 'mariadb:10.7'] } - runs-on: ubuntu-latest - container: swift:5.7-jammy - services: - mysql-a: - image: ${{ matrix.dbimage }} - env: - MYSQL_ALLOW_EMPTY_PASSWORD: "true" - MYSQL_USER: test_username - MYSQL_PASSWORD: test_password - MYSQL_DATABASE: test_database - steps: - - name: Save MySQL version to env - run: | - echo MYSQL_VERSION='${{ matrix.dbimage }}' >> $GITHUB_ENV - - name: Check out package - uses: actions/checkout@v3 - - name: Run local tests with coverage - run: swift test --enable-code-coverage - - name: Submit coverage report to Codecov.io - uses: vapor/swift-codecov-action@v0.2 - with: - cc_flags: 'unittests' - cc_env_vars: 'SWIFT_VERSION,SWIFT_PLATFORM,RUNNER_OS,RUNNER_ARCH,MYSQL_VERSION' - cc_fail_ci_if_error: true - cc_verbose: true - cc_dry_run: false - # Check for API breakage versus main api-breakage: - if: github.event_name == 'pull_request' + if: ${{ github.event_name == 'pull_request' && !github.event.pull_request.draft }} runs-on: ubuntu-latest - container: swift:5.7-jammy + container: swift:5.8-jammy steps: - name: Check out package uses: actions/checkout@v3 - with: - fetch-depth: 0 + with: { fetch-depth: 0 } # https://github.com/actions/checkout/issues/766 - name: Mark the workspace as safe run: git config --global --add safe.directory ${GITHUB_WORKSPACE} @@ -71,7 +41,7 @@ jobs: # Test integration with downstream Fluent driver dependents: - if: github.event_name == 'pull_request' + if: ${{ !(github.event.pull_request.draft || false) }} runs-on: ubuntu-latest services: mysql-a: @@ -88,52 +58,48 @@ jobs: MYSQL_USER: test_username MYSQL_PASSWORD: test_password MYSQL_DATABASE: test_database - container: swift:5.7-jammy + container: swift:5.8-jammy strategy: fail-fast: false matrix: - # Same minimum all-behavior set as the code coverage runs dbimage: - mysql:5.7 - mysql:8.0 - - mariadb:10.7 - dependent: - - fluent-mysql-driver + - mariadb:10.11 + - percona:8.0 steps: - name: Check out package uses: actions/checkout@v3 - with: - path: package + with: { path: 'mysql-kit' } - name: Check out dependent uses: actions/checkout@v3 with: - repository: vapor/${{ matrix.dependent }} - path: dependent - ref: main + repository: vapor/fluent-mysql-driver + path: fluent-mysql-driver - name: Use local package - run: swift package edit mysql-kit --path ../package - working-directory: dependent + run: swift package --package-path fluent-mysql-driver edit mysql-kit --path ./mysql-kit - name: Run tests with Thread Sanitizer - run: swift test --sanitize=thread - working-directory: dependent + run: swift test --package-path fluent-mysql-driver --sanitize=thread - # Run unit tests (Linux) + # Run unit tests (Linux), do code coverage in same job to cut down on extra builds linux-unit: - if: github.event_name == 'pull_request' + if: ${{ !(github.event.pull_request.draft || false) }} strategy: fail-fast: false matrix: dbimage: - mysql:5.7 - mysql:8.0 - - mariadb:10.3 - - mariadb:10.7 + - mariadb:10.4 + - mariadb:10.11 - percona:8.0 runner: - - swift:5.5-bionic + # List is deliberately incomplete; we want to avoid running 50 jobs on every commit - swift:5.6-focal - - swift:5.7-jammy - - swiftlang/swift:nightly-main-jammy + #- swift:5.7-jammy + - swift:5.8-jammy + - swiftlang/swift:nightly-5.9-jammy + #- swiftlang/swift:nightly-main-jammy container: ${{ matrix.runner }} runs-on: ubuntu-latest services: @@ -145,24 +111,31 @@ jobs: MYSQL_PASSWORD: test_password MYSQL_DATABASE: test_database steps: - - name: Check out code + - name: Save MySQL version to env + run: | + echo MYSQL_VERSION='${{ matrix.dbimage }}' >> $GITHUB_ENV + - name: Check out package uses: actions/checkout@v3 - - name: Run tests with Thread Sanitizer - run: swift test --sanitize=thread + - name: Run local tests with coverage and TSan + run: swift test --enable-code-coverage --sanitize=thread + - name: Submit coverage report to Codecov.io + uses: vapor/swift-codecov-action@v0.2 + with: + cc_flags: 'unittests' + cc_env_vars: 'SWIFT_VERSION,SWIFT_PLATFORM,RUNNER_OS,RUNNER_ARCH,MYSQL_VERSION' + cc_fail_ci_if_error: true + cc_verbose: true + cc_dry_run: false # Run unit tests (macOS). Don't bother with lots of variations, Linux will cover that. macos-unit: - if: github.event_name == 'pull_request' + if: ${{ !(github.event.pull_request.draft || false) }} strategy: fail-fast: false matrix: - formula: - - mysql@8.0 - macos: - - macos-11 - - macos-12 - xcode: - - latest-stable + formula: [ 'mysql@8.0' ] + macos: [ 'macos-12' ] + xcode: [ 'latest-stable' ] runs-on: ${{ matrix.macos }} steps: - name: Select latest available Xcode @@ -187,16 +160,16 @@ jobs: uses: actions/checkout@v3 - name: Run tests with Thread Sanitizer run: swift test --sanitize=thread - env: - MYSQL_HOSTNAME: '127.0.0.1' + env: { MYSQL_HOSTNAME: '127.0.0.1' } test-exports: + if: ${{ !(github.event.pull_request.draft || false) }} name: Test exports runs-on: ubuntu-latest + container: swift:5.8-jammy steps: - - name: Check out Vapor + - name: Check out package uses: actions/checkout@v3 - with: - fetch-depth: 0 + with: { fetch-depth: 0 } - name: Build run: swift build -Xswiftc -DBUILDING_DOCC From f0cceac0e596582901d7654fbd47afd2c2038e40 Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Tue, 11 Apr 2023 22:08:32 -0500 Subject: [PATCH 4/4] CI oops --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8013d12e..830c8de6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -119,6 +119,7 @@ jobs: - name: Run local tests with coverage and TSan run: swift test --enable-code-coverage --sanitize=thread - name: Submit coverage report to Codecov.io + if: ${{ !contains(matrix.runner, '5.8') }} uses: vapor/swift-codecov-action@v0.2 with: cc_flags: 'unittests'