Skip to content

Commit f4d4b9e

Browse files
authored
Sendable cleanup (#271)
* Update minimum Swift to 5.9 * Silence retroactive conformance warnings * Fix Sendable warnings in withSession(_:) and make SQLPostgresConfiguration Sendable * Minimal swift-format pass * Make SQLBenchmark test async. Disable questionably-useful performance test * Update DocC theme settings * Update CI
1 parent 99d09c4 commit f4d4b9e

17 files changed

+97
-167
lines changed

Diff for: .github/workflows/test.yml

+36-77
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
api-breakage:
2727
if: ${{ github.event_name == 'pull_request' && !(github.event.pull_request.draft || false) }}
2828
runs-on: ubuntu-latest
29-
container: swift:jammy
29+
container: swift:noble
3030
steps:
3131
- name: Checkout
3232
uses: actions/checkout@v4
@@ -36,86 +36,25 @@ jobs:
3636
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
3737
swift package diagnose-api-breaking-changes origin/main
3838
39-
dependency-graph:
40-
if: ${{ github.event_name == 'push' }}
41-
runs-on: ubuntu-latest
42-
container: swift:jammy
43-
permissions:
44-
contents: write
45-
steps:
46-
- name: Check out code
47-
uses: actions/checkout@v4
48-
- name: Fix Git configuration
49-
run: |
50-
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
51-
apt-get update && apt-get install -y curl
52-
- name: Submit dependency graph
53-
uses: vapor-community/swift-dependency-submission@v0.1
54-
55-
code-coverage:
56-
if: ${{ !(github.event.pull_request.draft || false) }}
57-
runs-on: ubuntu-latest
58-
container: swift:jammy
59-
services:
60-
psql-a:
61-
image: postgres:16
62-
env:
63-
POSTGRES_USER: test_username
64-
POSTGRES_DB: test_database
65-
POSTGRES_PASSWORD: test_password
66-
POSTGRES_HOST_AUTH_METHOD: scram-sha-256
67-
POSTGRES_INITDB_ARGS: --auth-host=scram-sha-256
68-
steps:
69-
- name: Check out code
70-
uses: actions/checkout@v4
71-
- name: Run unit tests for coverage data
72-
run: swift test --enable-code-coverage
73-
- name: Upload coverage data
74-
uses: vapor/swift-codecov-action@v0.3
75-
with:
76-
codecov_token: ${{ secrets.CODECOV_TOKEN }}
77-
78-
# gh-codeql:
79-
# if: ${{ !(github.event.pull_request.draft || false) }}
80-
# runs-on: ubuntu-latest
81-
# container:
82-
# image: swift:5.10-jammy
83-
# permissions: { actions: write, contents: read, security-events: write }
84-
# timeout-minutes: 60
85-
# steps:
86-
# - name: Check out code
87-
# uses: actions/checkout@v4
88-
# - name: Mark repo safe in non-fake global config
89-
# run: |
90-
# git config --global --add safe.directory "${GITHUB_WORKSPACE}"
91-
# - name: Initialize CodeQL
92-
# uses: github/codeql-action/init@v3
93-
# with: { languages: swift }
94-
# - name: Perform build
95-
# run: swift build
96-
# - name: Run CodeQL analyze
97-
# uses: github/codeql-action/analyze@v3
98-
9939
linux-unit:
10040
if: ${{ !(github.event.pull_request.draft || false) }}
10141
strategy:
10242
fail-fast: false
10343
matrix:
10444
postgres-image:
105-
- postgres:16
106-
- postgres:14
107-
- postgres:12
45+
- postgres:17
46+
- postgres:15
47+
- postgres:13
10848
swift-image:
109-
- swift:5.8-jammy
11049
- swift:5.9-jammy
111-
- swift:5.10-jammy
112-
- swiftlang/swift:nightly-main-jammy
50+
- swift:5.10-noble
51+
- swift:6.0-noble
11352
include:
114-
- postgres-image: postgres:16
53+
- postgres-image: postgres:17
11554
postgres-auth: scram-sha-256
116-
- postgres-image: postgres:14
55+
- postgres-image: postgres:15
11756
postgres-auth: md5
118-
- postgres-image: postgres:12
57+
- postgres-image: postgres:13
11958
postgres-auth: trust
12059
runs-on: ubuntu-latest
12160
container: ${{ matrix.swift-image }}
@@ -132,15 +71,19 @@ jobs:
13271
- name: Check out package
13372
uses: actions/checkout@v4
13473
- name: Run local tests
135-
run: swift test --sanitize=thread
74+
run: swift test --sanitize=thread --enable-code-coverage
75+
- name: Upload coverage data
76+
uses: vapor/swift-codecov-action@v0.3
77+
with:
78+
codecov_token: ${{ secrets.CODECOV_TOKEN || '' }}
13679

13780
linux-integration:
13881
if: ${{ !(github.event.pull_request.draft || false) }}
13982
runs-on: ubuntu-latest
140-
container: swift:5.10-jammy
83+
container: swift:6.0-noble
14184
services:
14285
psql-a:
143-
image: postgres:16
86+
image: postgres:17
14487
env:
14588
POSTGRES_USER: test_username
14689
POSTGRES_DB: test_database
@@ -173,10 +116,10 @@ jobs:
173116
fail-fast: false
174117
matrix:
175118
include:
176-
- macos-version: macos-13
177-
xcode-version: '~14.3'
178119
- macos-version: macos-14
179-
xcode-version: latest
120+
xcode-version: latest-stable
121+
- macos-version: macos-15
122+
xcode-version: latest-stable
180123
runs-on: ${{ matrix.macos-version }}
181124
env:
182125
POSTGRES_HOSTNAME: 127.0.0.1
@@ -197,4 +140,20 @@ jobs:
197140
- name: Checkout code
198141
uses: actions/checkout@v4
199142
- name: Run local tests
200-
run: swift test --sanitize=thread
143+
run: swift test --sanitize=thread --enable-code-coverage
144+
- name: Upload coverage data
145+
uses: vapor/swift-codecov-action@v0.3
146+
with:
147+
codecov_token: ${{ secrets.CODECOV_TOKEN || '' }}
148+
149+
musl:
150+
runs-on: ubuntu-latest
151+
container: swift:6.0-noble
152+
timeout-minutes: 30
153+
steps:
154+
- name: Check out code
155+
uses: actions/checkout@v4
156+
- name: Install SDK
157+
run: swift sdk install https://download.swift.org/swift-6.0.3-release/static-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum 67f765e0030e661a7450f7e4877cfe008db4f57f177d5a08a6e26fd661cdd0bd
158+
- name: Build
159+
run: swift build --swift-sdk x86_64-swift-linux-musl

Diff for: Package.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version:5.9
22
import PackageDescription
33

44
let package = Package(
@@ -39,6 +39,9 @@ let package = Package(
3939
)
4040

4141
var swiftSettings: [SwiftSetting] { [
42+
.enableUpcomingFeature("ExistentialAny"),
4243
.enableUpcomingFeature("ConciseMagicFile"),
4344
.enableUpcomingFeature("ForwardTrailingClosures"),
45+
.enableUpcomingFeature("DisableOutwardActorInference"),
46+
.enableExperimentalFeature("StrictConcurrency=complete"),
4447
] }

Diff for: Package@swift-5.9.swift

-47
This file was deleted.

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<a href="LICENSE"><img src="https://design.vapor.codes/images/mitlicense.svg" alt="MIT License"></a>
1212
<a href="https://github.com/vapor/postgres-kit/actions/workflows/test.yml"><img src="https://img.shields.io/github/actions/workflow/status/vapor/postgres-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc" alt="Continuous Integration"></a>
1313
<a href="https://codecov.io/github/vapor/postgres-kit"><img src="https://img.shields.io/codecov/c/github/vapor/postgres-kit?style=plastic&logo=codecov&label=codecov"></a>
14-
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift58up.svg" alt="Swift 5.8+"></a>
14+
<a href="https://swift.org"><img src="https://design.vapor.codes/images/swift59up.svg" alt="Swift 5.9+"></a>
1515
</p>
1616

1717
<br>

Diff for: Sources/PostgresKit/ConnectionPool+Postgres.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import NIOCore
2-
import PostgresNIO
31
@preconcurrency import AsyncKit
42
import Logging
3+
import NIOCore
4+
import PostgresNIO
55

66
extension EventLoopGroupConnectionPool where Source == PostgresConnectionSource {
77
public func database(logger: Logger) -> any PostgresDatabase {
@@ -39,11 +39,11 @@ private struct _EventLoopConnectionPoolPostgresDatabase: PostgresDatabase {
3939
var eventLoop: any EventLoop {
4040
self.pool.eventLoop
4141
}
42-
42+
4343
func send(_ request: any PostgresRequest, logger: Logger) -> EventLoopFuture<Void> {
4444
self.pool.withConnection(logger: logger) { $0.send(request, logger: logger) }
4545
}
46-
46+
4747
func withConnection<T>(_ closure: @escaping (PostgresConnection) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
4848
self.pool.withConnection(logger: self.logger, closure)
4949
}

Diff for: Sources/PostgresKit/Deprecations/PostgresConfiguration.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import NIOSSL
21
import Foundation
32
import NIOCore
3+
import NIOSSL
44

55
@available(*, deprecated, message: "Use `SQLPostgresConfiguration` instead.")
66
public struct PostgresConfiguration {

Diff for: Sources/PostgresKit/Deprecations/PostgresConnectionSource+PostgresConfiguration.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import NIOSSL
21
import Atomics
32
import Logging
4-
import PostgresNIO
53
import NIOCore
4+
import NIOSSL
5+
import PostgresNIO
66

77
extension PostgresConnectionSource {
88
@available(*, deprecated, message: "Use `sqlConfiguration` instead.")

Diff for: Sources/PostgresKit/Deprecations/PostgresDatabase+SQL+Deprecated.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import PostgresNIO
21
import Foundation
2+
import PostgresNIO
33
import SQLKit
44

55
@available(*, deprecated, message: "Use `.sql(jsonEncoder:jsonDecoder:)` instead.")

Diff for: Sources/PostgresKit/Docs.docc/theme-settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"psqlkit": "#336791",
99
"documentation-intro-fill": "radial-gradient(circle at top, var(--color-psqlkit) 30%, #000 100%)",
1010
"documentation-intro-accent": "var(--color-psqlkit)",
11+
"documentation-intro-eyebrow": "white",
12+
"documentation-intro-figure": "white",
13+
"documentation-intro-title": "white",
1114
"logo-base": { "dark": "#fff", "light": "#000" },
1215
"logo-shape": { "dark": "#000", "light": "#fff" },
1316
"fill": { "dark": "#000", "light": "#fff" }

Diff for: Sources/PostgresKit/PostgresConnectionSource.swift

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import NIOSSL
2-
import NIOConcurrencyHelpers
31
import AsyncKit
42
import Logging
3+
import NIOConcurrencyHelpers
4+
import NIOCore
5+
import NIOSSL
56
import PostgresNIO
67
import SQLKit
7-
import NIOCore
88

99
public struct PostgresConnectionSource: ConnectionPoolSource {
1010
public let sqlConfiguration: SQLPostgresConfiguration
11-
11+
1212
private static let idGenerator = NIOLockedValueBox<Int>(0)
13-
13+
1414
public init(sqlConfiguration: SQLPostgresConfiguration) {
1515
self.sqlConfiguration = sqlConfiguration
1616
}
@@ -22,10 +22,13 @@ public struct PostgresConnectionSource: ConnectionPoolSource {
2222
let connectionFuture = PostgresConnection.connect(
2323
on: eventLoop,
2424
configuration: self.sqlConfiguration.coreConfiguration,
25-
id: Self.idGenerator.withLockedValue { $0 += 1; return $0 },
25+
id: Self.idGenerator.withLockedValue {
26+
$0 += 1
27+
return $0
28+
},
2629
logger: logger
2730
)
28-
31+
2932
if let searchPath = self.sqlConfiguration.searchPath {
3033
return connectionFuture.flatMap { conn in
3134
conn.sql(queryLogLevel: nil)
@@ -39,4 +42,4 @@ public struct PostgresConnectionSource: ConnectionPoolSource {
3942
}
4043
}
4144

42-
extension PostgresConnection: ConnectionPoolItem {}
45+
extension PostgresNIO.PostgresConnection: AsyncKit.ConnectionPoolItem {}

Diff for: Sources/PostgresKit/PostgresDataTranslation.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import PostgresNIO
21
import Foundation
2+
import PostgresNIO
33

44
/// Quick and dirty ``CodingKey``, borrowed from FluentKit. If ``CodingKeyRepresentable`` wasn't broken by design
55
/// (specifically, it can't be back-deployed before macOS 12.3 etc., even though it was introduced in Swift 5.6),
@@ -17,7 +17,7 @@ private extension PostgresCell {
1717
}
1818

1919
/// Sidestep problems with URL coding behavior by making it conform directly to Postgres coding.
20-
extension URL: PostgresNonThrowingEncodable, PostgresDecodable {
20+
extension Foundation.URL: PostgresNIO.PostgresNonThrowingEncodable, PostgresNIO.PostgresDecodable {
2121
public static var psqlType: PostgresDataType {
2222
String.psqlType
2323
}

Diff for: Sources/PostgresKit/PostgresDatabase+SQL.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import PostgresNIO
21
import Logging
2+
import PostgresNIO
33
import SQLKit
44

55
extension PostgresDatabase {
@@ -95,7 +95,7 @@ extension PostgresSQLDatabase: SQLDatabase, PostgresDatabase {
9595
self.database.withConnection(closure)
9696
}
9797

98-
func withSession<R>(_ closure: @escaping @Sendable (any SQLDatabase) async throws -> R) async throws -> R {
98+
func withSession<R: Sendable>(_ closure: @escaping @Sendable (any SQLDatabase) async throws -> R) async throws -> R {
9999
try await self.withConnection { c in
100100
c.eventLoop.makeFutureWithTask {
101101
try await closure(c.sql(

Diff for: Sources/PostgresKit/PostgresRow+SQL.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import PostgresNIO
21
import Foundation
2+
import PostgresNIO
33
import SQLKit
44

55
extension PostgresRow {
66
@inlinable
77
public func sql() -> some SQLRow {
88
self.sql(decodingContext: .default)
99
}
10-
10+
1111
public func sql(decodingContext: PostgresDecodingContext<some PostgresJSONDecoder>) -> some SQLRow {
1212
_PostgresSQLRow(randomAccessView: self.makeRandomAccess(), decodingContext: decodingContext)
1313
}
@@ -39,7 +39,7 @@ extension _PostgresSQLRow: SQLRow {
3939
guard self.randomAccessView.contains(column) else {
4040
throw _Error.missingColumn(column)
4141
}
42-
42+
4343
return try PostgresDataTranslation.decode(T.self, from: self.randomAccessView[column], in: self.decodingContext)
4444
}
4545
}

0 commit comments

Comments
 (0)