Skip to content

Commit

Permalink
Update minimum Swift version to 5.5 (#51)
Browse files Browse the repository at this point in the history
* Update minimum Swift version to 5.5, improve CI

* Normalize behavior of Mongo driver tests to match other drivers. Fix copy-paste error in logger label for second database connection.
  • Loading branch information
gwynne authored Nov 27, 2022
1 parent e96cf41 commit 5b50882
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 15 deletions.
104 changes: 95 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,77 @@
name: test
on:
- pull_request
pull_request: { branches: ['*'] }
push: { branches: ['main'] }

env:
LOG_LEVEL: debug
SWIFT_DETERMINISTIC_HASHING: 1
MONGO_HOSTNAME: 'mongo-a'
MONGO_HOSTNAME_A: 'mongo-a'
MONGO_HOSTNAME_B: 'mongo-b'
MONGO_DATABASE: 'test_database'
MONGO_DATABASE_A: 'test_database'
MONGO_DATABASE_B: 'test_database'

jobs:
linux:
# Baseline test run for code coverage stats
codecov:
strategy:
matrix:
dbimage:
- mongo:6
runs-on: ubuntu-latest
container: swift:5.7-jammy
services:
mongo-a:
image: ${{ matrix.dbimage }}
mongo-b:
image: ${{ matrix.dbimage }}
steps:
- name: Save Mongo version to env
run: |
echo MONGO_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/[email protected]
with:
cc_flags: 'unittests'
cc_env_vars: 'SWIFT_VERSION,SWIFT_PLATFORM,RUNNER_OS,RUNNER_ARCH,MONGO_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'
runs-on: ubuntu-latest
container: swift:5.7-jammy
steps:
- name: Check out package
uses: actions/checkout@v3
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}
- name: Check for API breaking changes
run: swift package diagnose-api-breaking-changes origin/main

linux-all:
if: github.event_name == 'pull_request'
strategy:
fail-fast: false
matrix:
dbimage:
- mongo
- mongo:6
runner:
- swift:5.4-focal
- swift:5.5-focal
- swift:5.5-bionic
- swift:5.6-focal
- swiftlang/swift:nightly-main-focal
- swift:5.7-jammy
- swiftlang/swift:nightly-main-jammy
container: ${{ matrix.runner }}
runs-on: ubuntu-latest
services:
Expand All @@ -25,6 +84,33 @@ jobs:
uses: actions/checkout@v3
- name: Run tests with Thread Sanitizer
run: swift test --sanitize=thread
env:
MONGO_HOSTNAME_A: mongo-a
MONGO_HOSTNAME_B: mongo-b

macos-all:
if: github.event_name == 'pull_request'
strategy:
fail-fast: false
matrix:
dbimage: ['mongodb-community']
macos: ['macos-11', 'macos-12']
xcode: ['latest-stable']
runs-on: ${{ matrix.macos }}
env:
MONGO_HOSTNAME: 127.0.0.1
MONGO_HOSTNAME_A: 127.0.0.1
MONGO_HOSTNAME_B: 127.0.0.1
MONGO_DATABASE_B: 'test_database_b'
steps:
- name: Select latest available Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.xcode }}
- name: Install Mongo and wait for server start
run: |
brew tap mongodb/brew
brew install ${{ matrix.dbimage }}
brew services start ${{ matrix.dbimage }}
timeout-minutes: 2
- name: Checkout code
uses: actions/checkout@v3
- name: Run all tests
run: swift test --sanitize=thread
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.4
// swift-tools-version:5.5
import PackageDescription

let package = Package(
Expand All @@ -10,7 +10,7 @@ let package = Package(
.library(name: "FluentMongoDriver", targets: ["FluentMongoDriver"]),
],
dependencies: [
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.27.0"),
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.36.0"),
.package(url: "https://github.com/OpenKitten/MongoKitten.git", from: "6.6.4"),
],
targets: [
Expand Down
8 changes: 4 additions & 4 deletions Tests/FluentMongoDriverTests/FluentMongoDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,21 +250,21 @@ final class FluentMongoDriverTests: XCTestCase {
hostname: env("MONGO_HOSTNAME_A") ?? "localhost",
port: env("MONGO_PORT_A").flatMap(Int.init) ?? 27017
)],
targetDatabase: env("MONGO_DATABASE_A") ?? "vapor_database"
targetDatabase: env("MONGO_DATABASE_A") ?? "test_database"
)), as: .a)
try self.dbs.use(.mongo(settings: .init(
authentication: .unauthenticated,
hosts: [.init(
hostname: env("MONGO_HOSTNAME_B") ?? "localhost",
port: env("MONGO_PORT_B").flatMap(Int.init) ?? 27017
)],
targetDatabase: env("MONGO_DATABASE_B") ?? "vapor_database_2"
targetDatabase: env("MONGO_DATABASE_B") ?? "test_database"
)), as: .b)

// Drop existing tables.
let a = self.dbs.database(.a, logger: Logger(label: "test.fluent.a"), on: self.eventLoopGroup.next()) as! MongoDatabaseRepresentable
let a = self.dbs.database(.a, logger: Logger(label: "test.fluent.a"), on: self.eventLoopGroup.any()) as! MongoDatabaseRepresentable
try a.raw.drop().wait()
let b = self.dbs.database(.b, logger: Logger(label: "test.fluent.a"), on: self.eventLoopGroup.next()) as! MongoDatabaseRepresentable
let b = self.dbs.database(.b, logger: Logger(label: "test.fluent.b"), on: self.eventLoopGroup.any()) as! MongoDatabaseRepresentable
try b.raw.drop().wait()
}

Expand Down

0 comments on commit 5b50882

Please sign in to comment.