Skip to content

Commit f68a2bc

Browse files
authored
Support for reporting SQLite version numbers to clients (#34)
* Drop support for Swift <5.5 * Bring CI up to date * Modernize NIO usage and add log level override support for unit tests * Add static methods on SQLiteConnection to make the runtime version of SQLite available to higher layers without having to use SQLite APIs directly.
1 parent a9a862d commit f68a2bc

File tree

4 files changed

+133
-74
lines changed

4 files changed

+133
-74
lines changed

.github/workflows/test.yml

Lines changed: 101 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,127 @@
11
name: test
22
on:
3-
pull_request:
4-
push:
5-
branches:
6-
- main
7-
defaults:
8-
run:
9-
shell: bash
3+
pull_request: { branches: ['*'] }
4+
push: { branches: [ main ] }
5+
6+
env:
7+
LOG_LEVEL: debug
8+
SWIFT_DETERMINISTIC_HASHING: 1
109

1110
jobs:
12-
dependents:
11+
12+
codecov:
1313
runs-on: ubuntu-latest
14-
container: swift:5.4-focal
15-
strategy:
16-
fail-fast: false
17-
matrix:
18-
dependent:
19-
- sqlite-kit
20-
- fluent-sqlite-driver
14+
container: swift:5.7-jammy
2115
steps:
22-
- name: Install dependencies
16+
# N.B.: When we switch to embedded SQLite, these first two steps should be removed,
17+
# and the version saved to the environment should come from the checked-out package.
18+
- name: Install libsqlite3 dependency
2319
run: apt-get -q update && apt-get -q install -y libsqlite3-dev
24-
- name: Check out SQLiteNIO
25-
uses: actions/checkout@v2
20+
- name: Save SQLite version to env
21+
run: |
22+
echo SQLITE_VERSION="$(pkg-config --modversion sqlite3)" >> $GITHUB_ENV
23+
- name: Check out package
24+
uses: actions/checkout@v3
25+
- name: Run local tests with coverage
26+
run: swift test --enable-code-coverage
27+
- name: Submit coverage report to Codecov.io
28+
uses: vapor/[email protected]
2629
with:
27-
path: sqlite-nio
28-
- name: Check out dependent
29-
uses: actions/checkout@v2
30+
cc_flags: 'unittests'
31+
cc_env_vars: 'SWIFT_VERSION,SWIFT_PLATFORM,RUNNER_OS,RUNNER_ARCH,SQLITE_VERSION'
32+
cc_fail_ci_if_error: true
33+
cc_verbose: true
34+
cc_dry_run: false
35+
36+
# Check for API breakage versus main
37+
api-breakage:
38+
if: github.event_name == 'pull_request'
39+
runs-on: ubuntu-latest
40+
container: swift:5.7-jammy
41+
steps:
42+
- name: Install libsqlite3 dependency
43+
run: apt-get -q update && apt-get -q install -y libsqlite3-dev
44+
- name: Check out package
45+
uses: actions/checkout@v3
3046
with:
31-
repository: vapor/${{ matrix.dependent }}
32-
path: dependent
33-
- name: Use local SQLiteNIO
34-
run: swift package edit sqlite-nio --path ../sqlite-nio
35-
working-directory: dependent
36-
- name: Run tests with Thread Sanitizer
37-
run: swift test --enable-test-discovery --sanitize=thread
38-
working-directory: dependent
39-
linux:
47+
fetch-depth: 0
48+
# https://github.com/actions/checkout/issues/766
49+
- name: Mark the workspace as safe
50+
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
51+
- name: Check for API breaking changes
52+
run: swift package diagnose-api-breaking-changes origin/main
53+
54+
# Make sure downstream dependents still work
55+
dependents-check:
56+
if: github.event_name == 'pull_request'
4057
runs-on: ubuntu-latest
58+
container: swift:5.7-jammy
59+
steps:
60+
- name: Install libsqlite3 dependency
61+
run: apt-get -q update && apt-get -q install -y libsqlite3-dev
62+
- name: Check out package
63+
uses: actions/checkout@v3
64+
with:
65+
path: sqlite-nio
66+
- name: Check out SQLKit driver
67+
uses: actions/checkout@v3
68+
with:
69+
repository: vapor/sqlite-kit
70+
path: sqlite-kit
71+
- name: Check out FluentKit driver
72+
uses: actions/checkout@v3
73+
with:
74+
repository: vapor/fluent-sqlite-driver
75+
path: fluent-sqlite-driver
76+
- name: Tell dependents to use local checkout
77+
run: |
78+
swift package --package-path sqlite-kit edit sqlite-nio --path sqlite-nio
79+
swift package --package-path fluent-sqlite-driver edit sqlite-nio --path sqlite-nio
80+
- name: Run SQLiteKit tests with Thread Sanitizer
81+
run: swift test --package-path sqlite-kit --sanitize=thread
82+
- name: Run FluentSQLiteDriver tests with Thread Sanitizer
83+
run: swift test --package-path fluent-sqlite-driver --sanitize=thread
84+
85+
# Run unit tests (Linux)
86+
linux-unit:
87+
if: github.event_name == 'pull_request'
4188
strategy:
4289
fail-fast: false
4390
matrix:
44-
image:
45-
- swift:5.2-focal
46-
- swift:5.2-amazonlinux2
47-
- swift:5.3-focal
48-
- swift:5.3-amazonlinux2
49-
- swift:5.4-focal
50-
- swift:5.4-amazonlinux2
51-
#- swiftlang/swift:nightly-5.5-focal
52-
#- swiftlang/swift:nightly-5.5-amazonlinux2
53-
container: ${{ matrix.image }}
91+
runner:
92+
- swift:5.5-bionic
93+
- swift:5.6-focal
94+
- swift:5.7-jammy
95+
- swiftlang/swift:nightly-main-jammy
96+
container: ${{ matrix.runner }}
97+
runs-on: ubuntu-latest
5498
steps:
55-
- name: Install Ubuntu dependencies
99+
- name: Install libsqlite3 dependency
56100
run: apt-get -q update && apt-get -q install -y libsqlite3-dev
57-
if: ${{ endsWith(matrix.image, 'bionic') || endsWith(matrix.image, 'focal') }}
58-
- name: Update AmazonLinux2's too-old SQLite and compensate for its Postgres
59-
if: ${{ endsWith(matrix.image, 'amazonlinux2') }}
60-
working-directory: /root
61-
# Cribbed from the Fedora RPM, leaves out a lot. System's Tcl is too old to run SQLite's tests.
62-
run: |
63-
yum install -y sqlite-devel
64-
yum install -y file tcl-devel make
65-
curl -L 'https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release' | tar xz && cd sqlite
66-
export CFLAGS="-DSQLITE_DISABLE_DIRSYNC=1 -DSQLITE_SECURE_DELETE=1"
67-
./configure --prefix=/usr --libdir=/usr/lib64 --enable-fts3 --enable-all --with-tcl=/usr/lib64
68-
make all install
69-
- name: Checkout code
70-
uses: actions/checkout@v2
101+
- name: Check out code
102+
uses: actions/checkout@v3
71103
- name: Run tests with Thread Sanitizer
72-
run: swift test --enable-test-discovery --sanitize=thread
73-
macos:
74-
runs-on: macos-latest
104+
run: swift test --sanitize=thread
105+
106+
107+
# Run unit tests (macOS).
108+
macos-unit:
109+
if: github.event_name == 'pull_request'
75110
strategy:
76111
fail-fast: false
77112
matrix:
113+
macos:
114+
- macos-11
115+
- macos-12
78116
xcode:
79-
- latest
80117
- latest-stable
118+
runs-on: ${{ matrix.macos }}
81119
steps:
82120
- name: Select latest available Xcode
83121
uses: maxim-lobanov/setup-xcode@v1
84-
with:
122+
with:
85123
xcode-version: ${{ matrix.xcode }}
86-
- name: Checkout code
87-
uses: actions/checkout@v2
124+
- name: Check out code
125+
uses: actions/checkout@v3
88126
- name: Run tests with Thread Sanitizer
89-
run: swift test --enable-test-discovery --sanitize=thread
127+
run: swift test --sanitize=thread

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.2
1+
// swift-tools-version:5.5
22
import PackageDescription
33

44
let package = Package(
@@ -11,7 +11,7 @@ let package = Package(
1111
.library(name: "SQLiteNIO", targets: ["SQLiteNIO"]),
1212
],
1313
dependencies: [
14-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
14+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.42.0"),
1515
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
1616
],
1717
targets: [

Sources/SQLiteNIO/SQLiteConnection.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ public final class SQLiteConnection: SQLiteDatabase {
130130
self.logger = logger
131131
self.eventLoop = eventLoop
132132
}
133+
134+
public static func libraryVersion() -> Int32 {
135+
sqlite3_libversion_number()
136+
}
137+
138+
public static func libraryVersionString() -> String {
139+
String(cString: sqlite3_libversion())
140+
}
133141

134142
public func lastAutoincrementID() -> EventLoopFuture<Int> {
135143
let promise = self.eventLoop.makePromise(of: Int.self)

Tests/SQLiteNIOTests/SQLiteNIOTests.swift

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import XCTest
22
import SQLiteNIO
3+
import Logging
34

45
final class SQLiteNIOTests: XCTestCase {
56
func testBasicConnection() throws {
@@ -84,18 +85,30 @@ final class SQLiteNIOTests: XCTestCase {
8485

8586
var threadPool: NIOThreadPool!
8687
var eventLoopGroup: EventLoopGroup!
87-
var eventLoop: EventLoop {
88-
return self.eventLoopGroup.next()
89-
}
88+
var eventLoop: EventLoop { return self.eventLoopGroup.any() }
9089

91-
override func setUp() {
92-
self.threadPool = .init(numberOfThreads: 8)
90+
override func setUpWithError() throws {
91+
self.threadPool = .init(numberOfThreads: 1)
9392
self.threadPool.start()
94-
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 8)
93+
self.eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1)
94+
XCTAssert(isLoggingConfigured)
95+
}
96+
97+
override func tearDownWithError() throws {
98+
try self.threadPool.syncShutdownGracefully()
99+
try self.eventLoopGroup.syncShutdownGracefully()
95100
}
101+
}
96102

97-
override func tearDown() {
98-
try! self.threadPool.syncShutdownGracefully()
99-
try! self.eventLoopGroup.syncShutdownGracefully()
103+
let isLoggingConfigured: Bool = {
104+
LoggingSystem.bootstrap { label in
105+
var handler = StreamLogHandler.standardOutput(label: label)
106+
handler.logLevel = env("LOG_LEVEL").flatMap { Logger.Level(rawValue: $0) } ?? .info
107+
return handler
100108
}
109+
return true
110+
}()
111+
112+
func env(_ name: String) -> String? {
113+
ProcessInfo.processInfo.environment[name]
101114
}

0 commit comments

Comments
 (0)