Skip to content

Commit

Permalink
Update package for Sendable and 100% test coverage (#223)
Browse files Browse the repository at this point in the history
* Package structure, CI, and docs updates. Min Swift updated to 5.8.

* Add Sendable and ExistentialAny correctness. Fix forwarding of data encoder/decoders to the SQLKit layer. Add support for new SQLKit functionality. Throw DecodingErrors instead of fatalErrors(). Remove unused properties and files.

* Add 100% documentation coverage

* Achieve 100% test coverage. Make tests async and Sendable-correct. Add missing FluentBenchmark test set. Use singleton ELG and thread pool for tests.

* Add updated repo logo
  • Loading branch information
gwynne authored May 1, 2024
1 parent 986f129 commit 26f142d
Show file tree
Hide file tree
Showing 20 changed files with 707 additions and 467 deletions.
66 changes: 0 additions & 66 deletions .github/CONTRIBUTING.md

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/api-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
with:
package_name: fluent-mysql-driver
modules: FluentMySQLDriver
pathsToInvalidate: /fluentmysqldriver
pathsToInvalidate: /fluentmysqldriver/*
64 changes: 29 additions & 35 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ env:

jobs:
api-breakage:
if: ${{ !(github.event.pull_request.draft || false) }}
if: ${{ github.event_name == 'pull_request' && !(github.event.pull_request.draft || false) }}
runs-on: ubuntu-latest
container: swift:5.8-jammy
container: swift:jammy
steps:
- name: Check out package
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4
with: { 'fetch-depth': 0 }
- name: Run API breakage check action
uses: vapor/ci/.github/actions/ci-swift-check-api-breakage@reusable-workflows
- name: API breaking changes
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) }}
Expand All @@ -42,17 +44,17 @@ jobs:
dbimage:
- mysql:5.7
- mysql:8.0
- mysql:8.3
- mariadb:10.4
- mariadb:11
- percona:8.0
runner:
- swift:5.6-focal
- swift:5.7-jammy
- swift:5.8-jammy
- swiftlang/swift:nightly-5.9-jammy
- swiftlang/swift:nightly-main-jammy
runs-on: ubuntu-latest
# List is deliberately incomplete; we want to avoid running 50 jobs on every commit
- swift:5.8-focal
- swift:5.10-jammy
- swiftlang/swift:nightly-6.0-jammy
container: ${{ matrix.runner }}
runs-on: ubuntu-latest
services:
mysql-a:
image: ${{ matrix.dbimage }}
Expand All @@ -69,43 +71,35 @@ jobs:
MYSQL_PASSWORD: test_password
MYSQL_DATABASE: test_database
steps:
- name: Display versions
shell: bash
run: |
echo MYSQL_VERSION='${{ matrix.dbimage }}' >> $GITHUB_ENV
if [[ '${{ contains(matrix.container, 'nightly') }}' == 'true' ]]; then
SWIFT_PLATFORM="$(source /etc/os-release && echo "${ID}${VERSION_ID}")" SWIFT_VERSION="$(cat /.swift_tag)"
printf 'SWIFT_PLATFORM=%s\nSWIFT_VERSION=%s\n' "${SWIFT_PLATFORM}" "${SWIFT_VERSION}" >>"${GITHUB_ENV}"
fi
printf 'OS: %s\nTag: %s\nVersion:\n' "${SWIFT_PLATFORM}-${RUNNER_ARCH}" "${SWIFT_VERSION}" && swift --version
- name: Check out package
uses: actions/checkout@v3
- name: Run tests with Thread Sanitizer and coverage
run: swift test --sanitize=thread --enable-code-coverage
uses: actions/checkout@v4
- 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
uses: vapor/swift-codecov-action@v0.3
with:
cc_env_vars: 'SWIFT_VERSION,SWIFT_PLATFORM,RUNNER_OS,RUNNER_ARCH,MYSQL_VERSION'
codecov_token: ${{ secrets.CODECOV_TOKEN }}

macos-unit:
if: ${{ !(github.event.pull_request.draft || false) }}
strategy:
fail-fast: false
matrix:
include:
- dbimage: [email protected]
macos: macos-13
xcode: latest-stable
runs-on: ${{ matrix.macos }}
- macos-version: macos-13
xcode-version: '~14.3'
- macos-version: macos-14
xcode-version: latest
runs-on: ${{ matrix.macos-version }}
steps:
- name: Select latest available Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ matrix.xcode }}
with:
xcode-version: ${{ matrix.xcode-version }}
- name: Install MySQL server from Homebrew
run: brew install ${{ matrix.dbimage }} && brew link --force ${{ matrix.dbimage }}
run: brew install mysql && brew link --force mysql
- name: Start MySQL server
run: brew services start ${{ matrix.dbimage }}
run: brew services start mysql
- name: Wait for MySQL server to be ready
run: until echo | mysql -uroot; do sleep 1; done
timeout-minutes: 5
Expand All @@ -117,7 +111,7 @@ jobs:
CREATE DATABASE test_database_b; GRANT ALL PRIVILEGES ON test_database_b.* TO test_username@localhost;
SQL
- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Run tests with Thread Sanitizer
run: swift test --sanitize=thread
env:
Expand Down
41 changes: 28 additions & 13 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.6
// swift-tools-version:5.8
import PackageDescription

let package = Package(
Expand All @@ -13,20 +13,35 @@ let package = Package(
.library(name: "FluentMySQLDriver", targets: ["FluentMySQLDriver"]),
],
dependencies: [
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.43.0"),
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.48.1"),
.package(url: "https://github.com/vapor/mysql-kit.git", from: "4.7.1"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.2"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
],
targets: [
.target(name: "FluentMySQLDriver", dependencies: [
.product(name: "FluentKit", package: "fluent-kit"),
.product(name: "FluentSQL", package: "fluent-kit"),
.product(name: "Logging", package: "swift-log"),
.product(name: "MySQLKit", package: "mysql-kit"),
]),
.testTarget(name: "FluentMySQLDriverTests", dependencies: [
.product(name: "FluentBenchmark", package: "fluent-kit"),
.target(name: "FluentMySQLDriver"),
]),
.target(
name: "FluentMySQLDriver",
dependencies: [
.product(name: "FluentKit", package: "fluent-kit"),
.product(name: "FluentSQL", package: "fluent-kit"),
.product(name: "Logging", package: "swift-log"),
.product(name: "MySQLKit", package: "mysql-kit"),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "FluentMySQLDriverTests",
dependencies: [
.product(name: "FluentBenchmark", package: "fluent-kit"),
.target(name: "FluentMySQLDriver"),
],
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
48 changes: 48 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// swift-tools-version:5.9
import PackageDescription

let package = Package(
name: "fluent-mysql-driver",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.watchOS(.v6),
.tvOS(.v13),
],
products: [
.library(name: "FluentMySQLDriver", targets: ["FluentMySQLDriver"]),
],
dependencies: [
.package(url: "https://github.com/vapor/fluent-kit.git", from: "1.48.1"),
.package(url: "https://github.com/vapor/mysql-kit.git", from: "4.7.1"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
],
targets: [
.target(
name: "FluentMySQLDriver",
dependencies: [
.product(name: "FluentKit", package: "fluent-kit"),
.product(name: "FluentSQL", package: "fluent-kit"),
.product(name: "Logging", package: "swift-log"),
.product(name: "MySQLKit", package: "mysql-kit"),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "FluentMySQLDriverTests",
dependencies: [
.product(name: "FluentBenchmark", package: "fluent-kit"),
.target(name: "FluentMySQLDriver"),
],
swiftSettings: swiftSettings
),
]
)

var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
58 changes: 33 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
<p align="center">
<img
src="https://user-images.githubusercontent.com/1342803/75593351-1176b880-5a53-11ea-96ac-b9212e7471e9.png"
height="64"
alt="FluentMySQLDriver"
>
<br>
<br>
<a href="https://docs.vapor.codes/4.0/">
<img src="http://img.shields.io/badge/read_the-docs-2196f3.svg" alt="Documentation">
</a>
<a href="https://discord.gg/vapor">
<img src="https://img.shields.io/discord/431917998102675485.svg" alt="Team Chat">
</a>
<a href="LICENSE">
<img src="http://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License">
</a>
<a href="https://github.com/vapor/fluent-mysql-driver/actions/workflows/test.yml">
<img src="https://github.com/vapor/fluent-mysql-driver/actions/workflows/test.yml/badge.svg?event=push" alt="Continuous Integration">
</a>
<a href="https://codecov.io/gh/vapor/fluent-mysql-driver">
<img src="https://codecov.io/gh/vapor/fluent-mysql-driver/branch/main/graph/badge.svg?token=AobVT2XIMt" alt="Test Coverage">
</a>
<a href="https://swift.org">
<img src="http://img.shields.io/badge/swift-5.6-brightgreen.svg" alt="Swift 5.6">
</a>
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vapor/fluent-mysql-driver/assets/1130717/2810939b-2d77-4d39-9485-8e11b8f5dab4">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/vapor/fluent-mysql-driver/assets/1130717/ab442fbf-baf1-4cfe-8639-23141fb26e5a">
<img src="https://github.com/vapor/fluent-mysql-driver/assets/1130717/ab442fbf-baf1-4cfe-8639-23141fb26e5a" height="96" alt="FluentMySQLDriver">
</picture>
<br>
<br>
<a href="https://docs.vapor.codes/4.0/"><img src="https://design.vapor.codes/images/readthedocs.svg" alt="Documentation"></a>
<a href="https://discord.gg/vapor"><img src="https://design.vapor.codes/images/discordchat.svg" alt="Team Chat"></a>
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
<a href="https://github.com/vapor/fluent-mysql-driver/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/fluent-mysql-driver/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
<a href="https://codecov.io/github/vapor/fluent-mysql-driver"><img src="https://img.shields.io/codecov/c/github/vapor/fluent-mysql-driver?style=plastic&logo=codecov&label=codecov"></a>
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift58up.svg" alt="Swift 5.8+"></a>
</p>

<br>

FluentMySQLDriver is a [FluentKit] driver for MySQL clients. It provides support for using the Fluent ORM with MySQL databases, and uses [MySQLKit] to provide [SQLKit] driver services, [MySQLNIO] to connect and communicate with the database server asynchronously, and [AsyncKit] to provide connection pooling.

[FluentKit]: https://github.com/vapor/fluent-kit
[SQLKit]: https://github.com/vapor/sql-kit
[MySQLKit]: https://github.com/vapor/mysql-kit
[MySQLNIO]: https://github.com/vapor/mysql-nio
[AsyncKit]: https://github.com/vapor/async-kit

### Usage

Use the SPM string to easily include the dependendency in your `Package.swift` file:

```swift
.package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.0.0")
```

For additional information, see [the Fluent documentation](https://docs.vapor.codes/fluent/overview/).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion Sources/FluentMySQLDriver/Docs.docc/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# ``FluentMySQLDriver``

FluentMySQLDriver is a package to integrate MySQLNIO and and MySQLKit with FluentKit to make it easy to use and write MySQL database operations in Swift.
FluentMySQLDriver is a [FluentKit] driver for MySQL clients.

## Overview

FluentMySQLDriver provides support for using the Fluent ORM with MySQL databases. It uses [MySQLKit] to provide [SQLKit] driver services, [MySQLNIO] to connect and communicate with the database server asynchronously, and [AsyncKit] to provide connection pooling.

[FluentKit]: https://github.com/vapor/fluent-kit
[SQLKit]: https://github.com/vapor/sql-kit
[MySQLKit]: https://github.com/vapor/mysql-kit
[MySQLNIO]: https://github.com/vapor/mysql-nio
[AsyncKit]: https://github.com/vapor/async-kit

Loading

0 comments on commit 26f142d

Please sign in to comment.