From e9f1789ee4c58cbdc84aaa31c6aec2c92be1eadf Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Fri, 8 Mar 2024 11:54:24 +0000 Subject: [PATCH] Project template updates (#14) * Project template updates * run swiftformat --- .github/dependabot.yml | 21 ++++++++++++++++ .github/workflows/api-breakage.yml | 3 ++- .github/workflows/ci.yml | 24 ++++++++++++------- .github/workflows/nightly.yml | 9 ++++--- .github/workflows/validate.yml | 7 +++--- .gitignore | 1 + .swiftformat | 6 ++--- CONTRIBUTING.md | 4 ++-- Dockerfile | 2 +- .../HummingbirdFluent/Persist+fluent.swift | 8 +++---- scripts/validate.sh | 2 +- 11 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..998fd4c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,21 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + groups: + dependencies: + patterns: + - "*" + - package-ecosystem: "swift" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 6 + allow: + - dependency-type: all + groups: + all-dependencies: + patterns: + - "*" diff --git a/.github/workflows/api-breakage.yml b/.github/workflows/api-breakage.yml index b6bed85..dd4bcb4 100644 --- a/.github/workflows/api-breakage.yml +++ b/.github/workflows/api-breakage.yml @@ -7,11 +7,12 @@ on: jobs: linux: runs-on: ubuntu-latest + timeout-minutes: 15 container: image: swift:5.9 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 # https://github.com/actions/checkout/issues/766 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 11c8ebf..0d4cd5e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,30 +4,36 @@ on: push: branches: - main - - 2.x.x paths: - '**.swift' - '**.yml' pull_request: - paths: - - '**.swift' - - '**.yml' workflow_dispatch: jobs: linux: runs-on: ubuntu-latest + timeout-minutes: 15 strategy: matrix: - image: - - 'swift:5.9' - - 'swiftlang/swift:nightly-5.10-jammy' + image: ["swift:5.9", "swift:5.10", "swiftlang/swift:nightly-jammy"] container: image: ${{ matrix.image }} steps: - name: Checkout uses: actions/checkout@v4 - - name: Build + - name: Test + run: | + swift test --enable-code-coverage + - name: Convert coverage files run: | - swift test + llvm-cov export -format="lcov" \ + .build/debug/hummingbird-fluentPackageTests.xctest \ + -ignore-filename-regex="\/Tests\/" \ + -ignore-filename-regex="\/Benchmarks\/" \ + -instr-profile .build/debug/codecov/default.profdata > info.lcov + - name: Upload to codecov.io + uses: codecov/codecov-action@v4 + with: + file: info.lcov diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index aff877a..1009911 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,13 +1,12 @@ name: Swift nightly build on: - schedule: - - cron: '0 1 * * 1' workflow_dispatch: jobs: linux: runs-on: ubuntu-latest + timeout-minutes: 15 strategy: matrix: image: ['nightly-focal', 'nightly-jammy', 'nightly-amazonlinux2'] @@ -16,7 +15,7 @@ jobs: image: swiftlang/swift:${{ matrix.image }} steps: - name: Checkout - uses: actions/checkout@v3 - - name: Build + uses: actions/checkout@v4 + - name: Test run: | - swift build + swift test diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index ff97404..172da88 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -2,20 +2,19 @@ name: Validity Check on: pull_request: - branches: - - main jobs: validate: runs-on: macOS-latest + timeout-minutes: 15 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 1 - name: Install Dependencies run: | brew install mint - mint install NickLockwood/SwiftFormat@0.48.17 --no-link + mint install NickLockwood/SwiftFormat@0.51.15 --no-link - name: run script run: ./scripts/validate.sh diff --git a/.gitignore b/.gitignore index 2541032..45ca84c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ xcuserdata/ Package.resolved /public /docs +.benchmarkBaselines \ No newline at end of file diff --git a/.swiftformat b/.swiftformat index 3a7c14d..d800f8a 100644 --- a/.swiftformat +++ b/.swiftformat @@ -1,14 +1,14 @@ # Minimum swiftformat version ---minversion 0.47.4 +--minversion 0.51.0 # Swift version ---swiftversion 5.3 +--swiftversion 5.9 # file options --exclude .build # rules ---disable redundantReturn, extensionAccessControl +--disable redundantReturn, extensionAccessControl, typeSugar # format options --ifdef no-indent diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 12d20a0..bd21b4f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,7 +2,7 @@ ## Legal By submitting a pull request, you represent that you have the right to license your contribution to the community, and agree by submitting the patch -that your contributions are licensed under the Apache 2.0 license (see [LICENSE](LICENSE.txt)). +that your contributions are licensed under the Apache 2.0 license (see [LICENSE](LICENSE)). ## Contributor Conduct All contributors are expected to adhere to the project's [Code of Conduct](CODE_OF_CONDUCT.md). @@ -30,4 +30,4 @@ The main development branch of the repository is `main`. ### Formatting -We use Nick Lockwood's SwiftFormat for formatting code. PRs will not be accepted if they haven't be formatted. The current version of SwiftFormat we are using is v0.48.17. \ No newline at end of file +We use Nick Lockwood's SwiftFormat for formatting code. PRs will not be accepted if they haven't be formatted. The current version of SwiftFormat we are using is v0.51.15. \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 01fa447..102200f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # ================================ # Build image # ================================ -FROM swift:5.7 as build +FROM swift:5.9 as build WORKDIR /build diff --git a/Sources/HummingbirdFluent/Persist+fluent.swift b/Sources/HummingbirdFluent/Persist+fluent.swift index b72b95b..9f688e1 100644 --- a/Sources/HummingbirdFluent/Persist+fluent.swift +++ b/Sources/HummingbirdFluent/Persist+fluent.swift @@ -39,7 +39,7 @@ public final class HBFluentPersistDriver: HBPersistDriver { } /// Create new key. This doesn't check for the existence of this key already so may fail if the key already exists - public func create(key: String, value: Object, expires: Duration?) async throws { + public func create(key: String, value: some Codable, expires: Duration?) async throws { let db = self.fluent.db(self.databaseID) let data = try JSONEncoder().encode(value) let date = expires.map { Date.now + Double($0.components.seconds) } ?? Date.distantFuture @@ -54,7 +54,7 @@ public final class HBFluentPersistDriver: HBPersistDriver { } /// Set value for key. - public func set(key: String, value: Object, expires: Duration?) async throws { + public func set(key: String, value: some Codable, expires: Duration?) async throws { let db = self.fluent.db(self.databaseID) let data = try JSONEncoder().encode(value) let date = expires.map { Date.now + Double($0.components.seconds) } ?? Date.distantFuture @@ -66,7 +66,7 @@ public final class HBFluentPersistDriver: HBPersistDriver { let model = try await PersistModel.query(on: db) .filter(\._$id == key) .first() - if let model = model { + if let model { model.data = data model.expires = date try await model.update(on: db) @@ -96,7 +96,7 @@ public final class HBFluentPersistDriver: HBPersistDriver { public func remove(key: String) async throws { let db = self.fluent.db(self.databaseID) let model = try await PersistModel.find(key, on: db) - guard let model = model else { return } + guard let model else { return } return try await model.delete(force: true, on: db) } diff --git a/scripts/validate.sh b/scripts/validate.sh index e201bd3..f621e66 100755 --- a/scripts/validate.sh +++ b/scripts/validate.sh @@ -13,7 +13,7 @@ ## ##===----------------------------------------------------------------------===## -SWIFT_FORMAT_VERSION=0.48.17 +SWIFT_FORMAT_VERSION=0.51.15 set -eu here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"