From a2894871126bbbd80c620409e241246c80e8676b Mon Sep 17 00:00:00 2001 From: "hummingbird-automation[bot]" <168462326+hummingbird-automation[bot]@users.noreply.github.com> Date: Thu, 28 Nov 2024 07:31:50 +0000 Subject: [PATCH] Update from Hummingbird Project Template (#12) * Update from hummingbird-project-template 572d468b2cabeca286314c5a35196bd42445c8ef * run swift-format * Remove .swiftformat --------- Co-authored-by: adam-fowler Co-authored-by: Adam Fowler --- .github/workflows/validate.yml | 6 +-- .swift-format | 63 +++++++++++++++++++++++ .swiftformat | 26 ---------- CONTRIBUTING.md | 2 +- Package.swift | 24 +++++---- Sources/JobsRedis/RedisJobQueue.swift | 28 +++++----- Tests/JobsRedisTests/RedisJobsTests.swift | 9 ++-- scripts/validate.sh | 25 ++++----- 8 files changed, 111 insertions(+), 72 deletions(-) create mode 100644 .swift-format delete mode 100644 .swiftformat diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 7cddf30..434025a 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -8,16 +8,12 @@ concurrency: jobs: validate: - runs-on: macOS-latest + runs-on: ubuntu-latest timeout-minutes: 15 steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 1 - - name: Install Dependencies - run: | - brew install mint - mint install NickLockwood/SwiftFormat@0.53.10 --no-link - name: run script run: ./scripts/validate.sh diff --git a/.swift-format b/.swift-format new file mode 100644 index 0000000..bb3dcff --- /dev/null +++ b/.swift-format @@ -0,0 +1,63 @@ +{ + "version" : 1, + "indentation" : { + "spaces" : 4 + }, + "tabWidth" : 4, + "fileScopedDeclarationPrivacy" : { + "accessLevel" : "private" + }, + "spacesAroundRangeFormationOperators" : false, + "indentConditionalCompilationBlocks" : false, + "indentSwitchCaseLabels" : false, + "lineBreakAroundMultilineExpressionChainComponents" : false, + "lineBreakBeforeControlFlowKeywords" : false, + "lineBreakBeforeEachArgument" : true, + "lineBreakBeforeEachGenericRequirement" : true, + "lineLength" : 150, + "maximumBlankLines" : 1, + "respectsExistingLineBreaks" : true, + "prioritizeKeepingFunctionOutputTogether" : true, + "multiElementCollectionTrailingCommas" : true, + "rules" : { + "AllPublicDeclarationsHaveDocumentation" : false, + "AlwaysUseLiteralForEmptyCollectionInit" : false, + "AlwaysUseLowerCamelCase" : false, + "AmbiguousTrailingClosureOverload" : true, + "BeginDocumentationCommentWithOneLineSummary" : false, + "DoNotUseSemicolons" : true, + "DontRepeatTypeInStaticProperties" : true, + "FileScopedDeclarationPrivacy" : true, + "FullyIndirectEnum" : true, + "GroupNumericLiterals" : true, + "IdentifiersMustBeASCII" : true, + "NeverForceUnwrap" : false, + "NeverUseForceTry" : false, + "NeverUseImplicitlyUnwrappedOptionals" : false, + "NoAccessLevelOnExtensionDeclaration" : true, + "NoAssignmentInExpressions" : true, + "NoBlockComments" : true, + "NoCasesWithOnlyFallthrough" : true, + "NoEmptyTrailingClosureParentheses" : true, + "NoLabelsInCasePatterns" : true, + "NoLeadingUnderscores" : false, + "NoParensAroundConditions" : true, + "NoVoidReturnOnFunctionSignature" : true, + "OmitExplicitReturns" : true, + "OneCasePerLine" : true, + "OneVariableDeclarationPerLine" : true, + "OnlyOneTrailingClosureArgument" : true, + "OrderedImports" : true, + "ReplaceForEachWithForLoop" : true, + "ReturnVoidInsteadOfEmptyTuple" : true, + "UseEarlyExits" : false, + "UseExplicitNilCheckInConditions" : false, + "UseLetInEveryBoundCaseVariable" : false, + "UseShorthandTypeNames" : true, + "UseSingleLinePropertyGetter" : false, + "UseSynthesizedInitializer" : false, + "UseTripleSlashForDocumentationComments" : true, + "UseWhereClausesInForLoops" : false, + "ValidateDocumentationComments" : false + } +} diff --git a/.swiftformat b/.swiftformat deleted file mode 100644 index 14fb33f..0000000 --- a/.swiftformat +++ /dev/null @@ -1,26 +0,0 @@ -# Minimum swiftformat version ---minversion 0.53.10 - -# Swift version ---swiftversion 5.9 - -# file options ---exclude .build - -# rules ---disable redundantReturn, extensionAccessControl, typeSugar, conditionalAssignment, preferForLoop, redundantInternal, redundantStaticSelf - -# format options ---ifdef no-indent ---nospaceoperators ...,..< ---patternlet inline ---self insert ---stripunusedargs unnamed-only - -#--maxwidth 150 ---wraparguments before-first ---wrapparameters before-first ---wrapcollections before-first - -#file header -# --header "//===----------------------------------------------------------------------===//\n//\n// This source file is part of the Hummingbird server framework project\n//\n// Copyright (c) {created.year}-{year} the Hummingbird authors\n// Licensed under Apache License v2.0\n//\n// See LICENSE.txt for license information\n// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors\n//\n// SPDX-License-Identifier: Apache-2.0\n//\n//===----------------------------------------------------------------------===//" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 14b9831..8f5de31 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,4 +28,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.53.10. +We use Apple's swift-format for formatting code. PRs will not be accepted if they haven't be formatted. \ No newline at end of file diff --git a/Package.swift b/Package.swift index 09f188e..1c448f2 100644 --- a/Package.swift +++ b/Package.swift @@ -7,20 +7,26 @@ let package = Package( name: "swift-jobs-redis", platforms: [.macOS(.v14), .iOS(.v17), .tvOS(.v17)], products: [ - .library(name: "JobsRedis", targets: ["JobsRedis"]), + .library(name: "JobsRedis", targets: ["JobsRedis"]) ], dependencies: [ .package(url: "https://github.com/hummingbird-project/swift-jobs.git", from: "1.0.0-beta.4"), .package(url: "https://github.com/swift-server/RediStack.git", from: "1.4.0"), ], targets: [ - .target(name: "JobsRedis", dependencies: [ - .product(name: "Jobs", package: "swift-jobs"), - .product(name: "RediStack", package: "RediStack"), - ]), - .testTarget(name: "JobsRedisTests", dependencies: [ - .byName(name: "JobsRedis"), - .product(name: "Jobs", package: "swift-jobs"), - ]), + .target( + name: "JobsRedis", + dependencies: [ + .product(name: "Jobs", package: "swift-jobs"), + .product(name: "RediStack", package: "RediStack"), + ] + ), + .testTarget( + name: "JobsRedisTests", + dependencies: [ + .byName(name: "JobsRedis"), + .product(name: "Jobs", package: "swift-jobs"), + ] + ), ] ) diff --git a/Sources/JobsRedis/RedisJobQueue.swift b/Sources/JobsRedis/RedisJobQueue.swift index d35f768..24c5438 100644 --- a/Sources/JobsRedis/RedisJobQueue.swift +++ b/Sources/JobsRedis/RedisJobQueue.swift @@ -13,13 +13,14 @@ //===----------------------------------------------------------------------===// import Atomics +import Jobs +import NIOCore +import RediStack + import struct Foundation.Data import struct Foundation.Date import class Foundation.JSONDecoder import struct Foundation.UUID -import Jobs -import NIOCore -import RediStack /// Redis implementation of job queue driver public final class RedisJobQueue: JobQueueDriver { @@ -37,11 +38,12 @@ public final class RedisJobQueue: JobQueueDriver { public init(_ value: String) { let parts = value.components(separatedBy: ":") self.id = parts[0] - self.delayUntil = if parts.count > 1 { - Self.toMillisecondsFromString(value: parts[1]) - } else { - 0 - } + self.delayUntil = + if parts.count > 1 { + Self.toMillisecondsFromString(value: parts[1]) + } else { + 0 + } } static func toMilliseconds(value: Double?) -> Int64 { @@ -52,7 +54,7 @@ public final class RedisJobQueue: JobQueueDriver { } static func toMillisecondsFromString(value: String) -> Int64 { - return Int64(value) ?? 0 + Int64(value) ?? 0 } func isDelayed() -> Bool { @@ -153,7 +155,7 @@ public final class RedisJobQueue: JobQueueDriver { /// - Parameter key: Metadata key /// - Returns: Associated ByteBuffer public func getMetadata(_ key: String) async throws -> ByteBuffer? { - return try await self.redisConnectionPool.wrappedValue.get(.init(key)).get().byteBuffer + try await self.redisConnectionPool.wrappedValue.get(.init(key)).get().byteBuffer } /// Set job queue metadata @@ -231,7 +233,7 @@ public final class RedisJobQueue: JobQueueDriver { } func get(jobId: JobID) async throws -> ByteBuffer? { - return try await self.redisConnectionPool.wrappedValue.get(jobId.redisKey).get().byteBuffer + try await self.redisConnectionPool.wrappedValue.get(jobId.redisKey).get().byteBuffer } func set(jobId: JobID, buffer: ByteBuffer) async throws { @@ -264,7 +266,7 @@ extension RedisJobQueue { } public func makeAsyncIterator() -> AsyncIterator { - return .init(queue: self) + .init(queue: self) } } @@ -292,6 +294,6 @@ extension ByteBuffer { } public func convertedToRESPValue() -> RESPValue { - return .bulkString(self) + .bulkString(self) } } diff --git a/Tests/JobsRedisTests/RedisJobsTests.swift b/Tests/JobsRedisTests/RedisJobsTests.swift index db28e89..a45565d 100644 --- a/Tests/JobsRedisTests/RedisJobsTests.swift +++ b/Tests/JobsRedisTests/RedisJobsTests.swift @@ -15,7 +15,6 @@ import Atomics import Foundation import Jobs -@testable import JobsRedis import Logging import NIOConcurrencyHelpers import NIOCore @@ -24,6 +23,8 @@ import RediStack import ServiceLifecycle import XCTest +@testable import JobsRedis + extension XCTestExpectation { convenience init(description: String, expectedFulfillmentCount: Int) { self.init(description: description) @@ -209,7 +210,8 @@ final class RedisJobsTests: XCTestCase { let pendingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.queueKey).get() XCTAssertEqual(pendingJobs, 0) - let processingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.processingQueueKey).get() + let processingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.processingQueueKey) + .get() XCTAssertEqual(processingJobs, 0) } XCTAssertEqual(currentJobTryCount.withLockedValue { $0 }, 2) @@ -296,7 +298,8 @@ final class RedisJobsTests: XCTestCase { let pendingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.queueKey).get() XCTAssertEqual(pendingJobs, 0) let failedJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.failedQueueKey).get() - let processingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.processingQueueKey).get() + let processingJobs = try await jobQueue.queue.redisConnectionPool.wrappedValue.llen(of: jobQueue.queue.configuration.processingQueueKey) + .get() XCTAssertEqual(failedJobs + processingJobs, 1) } } diff --git a/scripts/validate.sh b/scripts/validate.sh index bb67406..f949949 100755 --- a/scripts/validate.sh +++ b/scripts/validate.sh @@ -31,8 +31,6 @@ SWIFT_FORMAT_VERSION=0.53.10 set -eu here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -which swiftformat > /dev/null 2>&1 || (echo "swiftformat not installed. You can install it using 'brew install swiftformat'" ; exit -1) - function replace_acceptable_years() { # this needs to replace all acceptable forms with 'YEARS' sed -e 's/20[12][0-9]-20[12][0-9]/YEARS/' -e 's/20[12][0-9]/YEARS/' -e '/^#!/ d' @@ -40,13 +38,9 @@ function replace_acceptable_years() { printf "=> Checking format... " FIRST_OUT="$(git status --porcelain)" -if [[ -n "${CI-""}" ]]; then - printf "(using v$(mint run NickLockwood/SwiftFormat@"$SWIFT_FORMAT_VERSION" --version)) " - mint run NickLockwood/SwiftFormat@"$SWIFT_FORMAT_VERSION" . > /dev/null 2>&1 -else - printf "(using v$(swiftformat --version)) " - swiftformat . > /dev/null 2>&1 -fi +git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place +git diff --exit-code '*.swift' + SECOND_OUT="$(git status --porcelain)" if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then printf "\033[0;31mformatting issues!\033[0m\n" @@ -55,10 +49,11 @@ if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then else printf "\033[0;32mokay.\033[0m\n" fi -exit printf "=> Checking license headers... " tmp=$(mktemp /tmp/.soto-core-sanity_XXXXXX) +exit 0 + for language in swift-or-c; do declare -a matching_files declare -a exceptions @@ -66,18 +61,18 @@ for language in swift-or-c; do matching_files=( -name '*' ) case "$language" in swift-or-c) - exceptions=( -path '*Sources/INIParser/*' -o -path '*Sources/CSotoExpat/*' -o -path '*Benchmark/.build/*' -o -name Package.swift) + exceptions=( -path '*/Benchmarks/.build/*' -o -name Package.swift) matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' ) cat > "$tmp" <<"EOF" //===----------------------------------------------------------------------===// // -// This source file is part of the Hummingbird open source project +// This source file is part of the Hummingbird server framework project // // Copyright (c) YEARS the Hummingbird authors // Licensed under Apache License v2.0 // // See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of Hummingbird authors +// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors // // SPDX-License-Identifier: Apache-2.0 // @@ -89,13 +84,13 @@ EOF cat > "$tmp" <<"EOF" ##===----------------------------------------------------------------------===## ## -## This source file is part of the Hummingbird open source project +## This source file is part of the Hummingbird server framework project ## ## Copyright (c) YEARS the Hummingbird authors ## Licensed under Apache License v2.0 ## ## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of Hummingbird authors +## See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors ## ## SPDX-License-Identifier: Apache-2.0 ##