diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..998fd4c57 --- /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 f1b8f3f64..7486abcbe 100644 --- a/.github/workflows/api-breakage.yml +++ b/.github/workflows/api-breakage.yml @@ -8,10 +8,10 @@ jobs: linux: runs-on: ubuntu-latest container: - image: swift:5.8 + 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 2b2415347..aaefdde90 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: runs-on: macOS-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: SPM tests run: swift test --enable-code-coverage - name: Convert coverage files @@ -42,13 +42,12 @@ jobs: - 'swift:5.7' - 'swift:5.8' - 'swift:5.9' - #- 'swiftlang/swift:nightly-5.10-jammy' container: image: ${{ matrix.image }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Test run: | swift test --enable-code-coverage diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index e2a00c428..000000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: "CodeQL" - -on: - push: - branches: [ "main", "7.x.x" ] - pull_request: - branches: [ "main", "7.x.x" ] - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - container: swift:5.8 - permissions: - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'swift' ] - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - - - name: Build - run: swift build - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 4e3da45d5..af248a218 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -10,7 +10,7 @@ jobs: runs-on: macOS-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: SPM tests run: swift test linux: @@ -23,7 +23,7 @@ jobs: image: swiftlang/swift:${{ matrix.image }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Test run: | swift test --enable-test-discovery diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index ff9740420..e8dfe32fb 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -10,12 +10,12 @@ jobs: runs-on: macOS-latest 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/.swiftformat b/.swiftformat index 3a7c14dad..164dd1eed 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.7 # file options --exclude .build # rules ---disable redundantReturn, extensionAccessControl +--disable redundantReturn, extensionAccessControl, opaqueGenericParameters, typeSugar # format options --ifdef no-indent diff --git a/Benchmarks/Sources/HBPerformance/EmbeddedApplication.swift b/Benchmarks/Sources/HBPerformance/EmbeddedApplication.swift index 177f9bff9..c3f039fa1 100644 --- a/Benchmarks/Sources/HBPerformance/EmbeddedApplication.swift +++ b/Benchmarks/Sources/HBPerformance/EmbeddedApplication.swift @@ -87,7 +87,7 @@ public struct HBEmbeddedApplication { // write request let requestHead = HTTPRequestHead(version: .init(major: 1, minor: 1), method: method, uri: uri, headers: headers) try writeInbound(.head(requestHead)) - if let body = body { + if let body { try self.writeInbound(.body(body)) } try self.writeInbound(.end(nil)) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 12d20a071..bd21b4f37 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/Sources/Hummingbird/Configuration.swift b/Sources/Hummingbird/Configuration.swift index 4cab57349..dc03cfa68 100644 --- a/Sources/Hummingbird/Configuration.swift +++ b/Sources/Hummingbird/Configuration.swift @@ -110,7 +110,7 @@ extension HBApplication { self.threadPoolSize = threadPoolSize self.noHTTPServer = noHTTPServer - if let logLevel = logLevel { + if let logLevel { self.logLevel = logLevel } else if let logLevel = env.get("LOG_LEVEL") { self.logLevel = Logger.Level(rawValue: logLevel) ?? .info @@ -169,7 +169,7 @@ extension HBApplication { self.threadPoolSize = threadPoolSize self.noHTTPServer = noHTTPServer - if let logLevel = logLevel { + if let logLevel { self.logLevel = logLevel } else if let logLevel = env.get("LOG_LEVEL") { self.logLevel = Logger.Level(rawValue: logLevel) ?? .info @@ -223,7 +223,7 @@ extension HBApplication { self.threadPoolSize = threadPoolSize self.noHTTPServer = noHTTPServer - if let logLevel = logLevel { + if let logLevel { self.logLevel = logLevel } else if let logLevel = env.get("LOG_LEVEL") { self.logLevel = Logger.Level(rawValue: logLevel) ?? .info @@ -277,7 +277,7 @@ extension HBApplication { self.threadPoolSize = threadPoolSize self.noHTTPServer = noHTTPServer - if let logLevel = logLevel { + if let logLevel { self.logLevel = logLevel } else if let logLevel = env.get("LOG_LEVEL") { self.logLevel = Logger.Level(rawValue: logLevel) ?? .info diff --git a/Sources/Hummingbird/HTTP/MediaType.swift b/Sources/Hummingbird/HTTP/MediaType.swift index 18eabb0e9..a169eaeed 100644 --- a/Sources/Hummingbird/HTTP/MediaType.swift +++ b/Sources/Hummingbird/HTTP/MediaType.swift @@ -97,8 +97,8 @@ public struct HBMediaType: Sendable, CustomStringConvertible { break } } - if let category = category, - let subCategory = subCategory + if let category, + let subCategory { self.type = category self.subType = subCategory.lowercased() diff --git a/Sources/Hummingbird/HTTP/URL.swift b/Sources/Hummingbird/HTTP/URL.swift index bdcd9ea18..2fa10eb1d 100644 --- a/Sources/Hummingbird/HTTP/URL.swift +++ b/Sources/Hummingbird/HTTP/URL.swift @@ -139,7 +139,7 @@ extension HBParameters { /// Initialize parameters from parser struct /// - Parameter query: parser holding query strings init(fromQuery query: HBParser?) { - guard var query = query else { + guard var query else { self.parameters = .init() return } diff --git a/Sources/Hummingbird/Router/TrieRouter.swift b/Sources/Hummingbird/Router/TrieRouter.swift index f175edad6..14c6bbe66 100644 --- a/Sources/Hummingbird/Router/TrieRouter.swift +++ b/Sources/Hummingbird/Router/TrieRouter.swift @@ -97,7 +97,7 @@ struct RouterPathTrie { } } -extension Optional where Wrapped == HBParameters { +extension Optional { mutating func set(_ s: Substring, value: Substring) { switch self { case .some(var parameters): diff --git a/Sources/Hummingbird/Server/Request.swift b/Sources/Hummingbird/Server/Request.swift index fcae3b2c6..f13cda793 100644 --- a/Sources/Hummingbird/Server/Request.swift +++ b/Sources/Hummingbird/Server/Request.swift @@ -28,7 +28,7 @@ private extension CodingKey { } } -private extension Array where Element == CodingKey { +private extension Array { /// returns a path key using a dot character as a separator var pathKeyValue: String { map(\.pathKeyValue).joined(separator: ".") diff --git a/Sources/Hummingbird/Server/ResponsePatch.swift b/Sources/Hummingbird/Server/ResponsePatch.swift index 41243583d..ab67a1b20 100644 --- a/Sources/Hummingbird/Server/ResponsePatch.swift +++ b/Sources/Hummingbird/Server/ResponsePatch.swift @@ -62,7 +62,7 @@ extension HBRequest { extension HBResponse { /// apply `HBRequest.ResponsePatch` to `HBResponse` mutating func apply(patch: HBRequest.ResponsePatch?) -> Self { - guard let patch = patch else { return self } + guard let patch else { return self } if let status = patch.status { self.status = status } diff --git a/Sources/Hummingbird/Utils/FlatDictionary.swift b/Sources/Hummingbird/Utils/FlatDictionary.swift index d6da0dced..78296b5aa 100644 --- a/Sources/Hummingbird/Utils/FlatDictionary.swift +++ b/Sources/Hummingbird/Utils/FlatDictionary.swift @@ -75,13 +75,13 @@ public struct FlatDictionary: Collection, ExpressibleByDic set { let hashKey = Self.hashKey(key) if let index = hashKeys.firstIndex(of: hashKey) { - if let newValue = newValue { + if let newValue { self.elements[index].value = newValue } else { self.elements.remove(at: index) self.hashKeys.remove(at: index) } - } else if let newValue = newValue { + } else if let newValue { self.elements.append((key: key, value: newValue)) self.hashKeys.append(hashKey) } diff --git a/Sources/Hummingbird/Utils/HBParser.swift b/Sources/Hummingbird/Utils/HBParser.swift index cbe196198..ca7e98338 100644 --- a/Sources/Hummingbird/Utils/HBParser.swift +++ b/Sources/Hummingbird/Utils/HBParser.swift @@ -663,7 +663,7 @@ extension Unicode.Scalar { } } -extension Set where Element == Unicode.Scalar { +extension Set { public init(_ string: String) { self = Set(string.unicodeScalars) } diff --git a/Sources/HummingbirdFoundation/Files/FileIO.swift b/Sources/HummingbirdFoundation/Files/FileIO.swift index e70d65948..a6a43acdf 100644 --- a/Sources/HummingbirdFoundation/Files/FileIO.swift +++ b/Sources/HummingbirdFoundation/Files/FileIO.swift @@ -111,7 +111,7 @@ public struct HBFileIO { let futureResult: EventLoopFuture switch contents { case .byteBuffer(let buffer): - guard let buffer = buffer else { return context.eventLoop.makeSucceededVoidFuture() } + guard let buffer else { return context.eventLoop.makeSucceededVoidFuture() } futureResult = self.writeFile(buffer: buffer, handle: handle, on: context.eventLoop) case .stream(let streamer): futureResult = self.writeFile(stream: streamer, handle: handle, on: context.eventLoop) diff --git a/Sources/HummingbirdFoundation/Files/FileMiddleware.swift b/Sources/HummingbirdFoundation/Files/FileMiddleware.swift index b70c4c36b..4d4bea1d3 100644 --- a/Sources/HummingbirdFoundation/Files/FileMiddleware.swift +++ b/Sources/HummingbirdFoundation/Files/FileMiddleware.swift @@ -114,12 +114,12 @@ public struct HBFileMiddleware: HBMiddleware { var headers = HTTPHeaders() // content-length - if let contentSize = contentSize { + if let contentSize { headers.add(name: "content-length", value: String(describing: contentSize)) } // modified-date var modificationDateString: String? - if let modificationDate = modificationDate { + if let modificationDate { modificationDateString = HBDateCache.rfc1123Formatter.string(from: modificationDate) headers.add(name: "modified-date", value: modificationDateString!) } @@ -150,7 +150,7 @@ public struct HBFileMiddleware: HBMiddleware { } // verify if-modified-since else if let ifModifiedSince = request.headers["if-modified-since"].first, - let modificationDate = modificationDate + let modificationDate { if let ifModifiedSinceDate = HBDateCache.rfc1123Formatter.date(from: ifModifiedSince) { // round modification date of file down to seconds for comparison @@ -170,7 +170,7 @@ public struct HBFileMiddleware: HBMiddleware { if let ifRange = request.headers["if-range"].first, ifRange != headers["eTag"].first, ifRange != headers["modified-date"].first { // do nothing and drop down to returning full file } else { - if let contentSize = contentSize { + if let contentSize { let lowerBound = max(range.lowerBound, 0) let upperBound = min(range.upperBound, contentSize - 1) headers.replaceOrAdd(name: "content-range", value: "bytes \(lowerBound)-\(upperBound)/\(contentSize)") @@ -188,7 +188,7 @@ public struct HBFileMiddleware: HBMiddleware { case .loadFile(let headers, let range): switch request.method { case .GET: - if let range = range { + if let range { return self.fileIO.loadFile(path: fullPath.relativePath, range: range, context: request.context, logger: request.logger) .map { body, _ in return HBResponse(status: .partialContent, headers: headers, body: body) @@ -276,7 +276,7 @@ extension HBFileMiddleware { } } -extension Sequence where Element == UInt8 { +extension Sequence { /// return a hexEncoded string buffer from an array of bytes func hexDigest() -> String { return self.map { String(format: "%02x", $0) }.joined(separator: "") diff --git a/Sources/HummingbirdJobs/JobQueueWorker.swift b/Sources/HummingbirdJobs/JobQueueWorker.swift index e242d0be0..a688115d6 100644 --- a/Sources/HummingbirdJobs/JobQueueWorker.swift +++ b/Sources/HummingbirdJobs/JobQueueWorker.swift @@ -94,7 +94,7 @@ class HBJobQueueWorker { } return self.queue.pop(on: eventLoop) .map { value in - if let value = value { + if let value { promise.succeed(value) task.cancel() } diff --git a/Sources/HummingbirdXCT/HBXCTAsyncTesting.swift b/Sources/HummingbirdXCT/HBXCTAsyncTesting.swift index 42fa65769..3d4e8d173 100644 --- a/Sources/HummingbirdXCT/HBXCTAsyncTesting.swift +++ b/Sources/HummingbirdXCT/HBXCTAsyncTesting.swift @@ -59,7 +59,7 @@ struct HBXCTAsyncTesting: HBXCT { // shutdown eventloop try await withCheckedThrowingContinuation { (cont: CheckedContinuation) in self.asyncTestingEventLoop.shutdownGracefully { error in - if let error = error { + if let error { cont.resume(throwing: error) } else { cont.resume() @@ -95,7 +95,7 @@ struct HBXCTAsyncTesting: HBXCT { // write request let requestHead = HTTPRequestHead(version: .init(major: 1, minor: 1), method: method, uri: uri, headers: headers) try await writeInbound(.head(requestHead)) - if let body = body { + if let body { try await self.writeInbound(.body(body)) } try await self.writeInbound(.end(nil)) diff --git a/Sources/HummingbirdXCT/HBXCTEmbedded.swift b/Sources/HummingbirdXCT/HBXCTEmbedded.swift index 0d5795d42..2d3249ebe 100644 --- a/Sources/HummingbirdXCT/HBXCTEmbedded.swift +++ b/Sources/HummingbirdXCT/HBXCTEmbedded.swift @@ -53,7 +53,7 @@ struct HBXCTEmbedded: HBXCT { // write request let requestHead = HTTPRequestHead(version: .init(major: 1, minor: 1), method: method, uri: uri, headers: headers) try writeInbound(.head(requestHead)) - if let body = body { + if let body { try self.writeInbound(.body(body)) } try self.writeInbound(.end(nil)) diff --git a/scripts/validate.sh b/scripts/validate.sh index e201bd38b..f621e665f 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 )"