Skip to content

Commit beabb40

Browse files
Update from Hummingbird Project Template (#5)
* Update from hummingbird-project-template 572d468b2cabeca286314c5a35196bd42445c8ef * swift-format * Remove .swiftformat --------- Co-authored-by: adam-fowler <adam-fowler@users.noreply.github.com> Co-authored-by: Adam Fowler <adamfowler71@gmail.com>
1 parent 53aa062 commit beabb40

File tree

8 files changed

+115
-63
lines changed

8 files changed

+115
-63
lines changed

.github/workflows/validate.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ concurrency:
88

99
jobs:
1010
validate:
11-
runs-on: macOS-latest
11+
runs-on: ubuntu-latest
1212
timeout-minutes: 15
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 1
18-
- name: Install Dependencies
19-
run: |
20-
brew install mint
21-
mint install NickLockwood/SwiftFormat@0.53.10 --no-link
2218
- name: run script
2319
run: ./scripts/validate.sh

.swift-format

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"version" : 1,
3+
"indentation" : {
4+
"spaces" : 4
5+
},
6+
"tabWidth" : 4,
7+
"fileScopedDeclarationPrivacy" : {
8+
"accessLevel" : "private"
9+
},
10+
"spacesAroundRangeFormationOperators" : false,
11+
"indentConditionalCompilationBlocks" : false,
12+
"indentSwitchCaseLabels" : false,
13+
"lineBreakAroundMultilineExpressionChainComponents" : false,
14+
"lineBreakBeforeControlFlowKeywords" : false,
15+
"lineBreakBeforeEachArgument" : true,
16+
"lineBreakBeforeEachGenericRequirement" : true,
17+
"lineLength" : 150,
18+
"maximumBlankLines" : 1,
19+
"respectsExistingLineBreaks" : true,
20+
"prioritizeKeepingFunctionOutputTogether" : true,
21+
"multiElementCollectionTrailingCommas" : true,
22+
"rules" : {
23+
"AllPublicDeclarationsHaveDocumentation" : false,
24+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
25+
"AlwaysUseLowerCamelCase" : false,
26+
"AmbiguousTrailingClosureOverload" : true,
27+
"BeginDocumentationCommentWithOneLineSummary" : false,
28+
"DoNotUseSemicolons" : true,
29+
"DontRepeatTypeInStaticProperties" : true,
30+
"FileScopedDeclarationPrivacy" : true,
31+
"FullyIndirectEnum" : true,
32+
"GroupNumericLiterals" : true,
33+
"IdentifiersMustBeASCII" : true,
34+
"NeverForceUnwrap" : false,
35+
"NeverUseForceTry" : false,
36+
"NeverUseImplicitlyUnwrappedOptionals" : false,
37+
"NoAccessLevelOnExtensionDeclaration" : true,
38+
"NoAssignmentInExpressions" : true,
39+
"NoBlockComments" : true,
40+
"NoCasesWithOnlyFallthrough" : true,
41+
"NoEmptyTrailingClosureParentheses" : true,
42+
"NoLabelsInCasePatterns" : true,
43+
"NoLeadingUnderscores" : false,
44+
"NoParensAroundConditions" : true,
45+
"NoVoidReturnOnFunctionSignature" : true,
46+
"OmitExplicitReturns" : true,
47+
"OneCasePerLine" : true,
48+
"OneVariableDeclarationPerLine" : true,
49+
"OnlyOneTrailingClosureArgument" : true,
50+
"OrderedImports" : true,
51+
"ReplaceForEachWithForLoop" : true,
52+
"ReturnVoidInsteadOfEmptyTuple" : true,
53+
"UseEarlyExits" : false,
54+
"UseExplicitNilCheckInConditions" : false,
55+
"UseLetInEveryBoundCaseVariable" : false,
56+
"UseShorthandTypeNames" : true,
57+
"UseSingleLinePropertyGetter" : false,
58+
"UseSynthesizedInitializer" : false,
59+
"UseTripleSlashForDocumentationComments" : true,
60+
"UseWhereClausesInForLoops" : false,
61+
"ValidateDocumentationComments" : false
62+
}
63+
}

.swiftformat

Lines changed: 0 additions & 26 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ The main development branch of the repository is `main`.
2828

2929
### Formatting
3030

31-
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.
31+
We use Apple's swift-format for formatting code. PRs will not be accepted if they haven't be formatted.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let package = Package(
66
name: "swift-jobs-postgres",
77
platforms: [.macOS(.v14), .iOS(.v17), .tvOS(.v17)],
88
products: [
9-
.library(name: "JobsPostgres", targets: ["JobsPostgres"]),
9+
.library(name: "JobsPostgres", targets: ["JobsPostgres"])
1010
],
1111
dependencies: [
1212
.package(url: "https://github.com/hummingbird-project/swift-jobs.git", from: "1.0.0-beta.4"),
@@ -25,7 +25,7 @@ let package = Package(
2525
.testTarget(
2626
name: "JobsPostgresTests",
2727
dependencies: [
28-
"JobsPostgres",
28+
"JobsPostgres"
2929
]
3030
),
3131
]

Sources/JobsPostgres/PostgresJobsQueue.swift

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ public final class PostgresJobQueue: JobQueueDriver {
122122
_ = try await self.client.withConnection { connection in
123123
self.logger.info("Update Jobs at initialization")
124124
try await self.updateJobsOnInit(withStatus: .pending, onInit: self.configuration.pendingJobsInitialization, connection: connection)
125-
try await self.updateJobsOnInit(withStatus: .processing, onInit: self.configuration.processingJobsInitialization, connection: connection)
125+
try await self.updateJobsOnInit(
126+
withStatus: .processing,
127+
onInit: self.configuration.processingJobsInitialization,
128+
connection: connection
129+
)
126130
try await self.updateJobsOnInit(withStatus: .failed, onInit: self.configuration.failedJobsInitialization, connection: connection)
127131
}
128132
} catch let error as PSQLError {
@@ -229,14 +233,20 @@ public final class PostgresJobQueue: JobQueueDriver {
229233
}
230234
return try result.get()
231235
} catch let error as PSQLError {
232-
logger.error("Failed to get job from queue", metadata: [
233-
"error": "\(String(reflecting: error))",
234-
])
236+
logger.error(
237+
"Failed to get job from queue",
238+
metadata: [
239+
"error": "\(String(reflecting: error))"
240+
]
241+
)
235242
throw error
236243
} catch let error as JobQueueError {
237-
logger.error("Job failed", metadata: [
238-
"error": "\(String(reflecting: error))",
239-
])
244+
logger.error(
245+
"Job failed",
246+
metadata: [
247+
"error": "\(String(reflecting: error))"
248+
]
249+
)
240250
throw error
241251
}
242252
}
@@ -342,7 +352,7 @@ extension PostgresJobQueue {
342352
}
343353

344354
public func makeAsyncIterator() -> AsyncIterator {
345-
return .init(queue: self)
355+
.init(queue: self)
346356
}
347357
}
348358

@@ -353,7 +363,12 @@ extension JobQueueDriver where Self == PostgresJobQueue {
353363
/// - migrations: Database migration collection to add postgres job queue migrations to
354364
/// - configuration: Queue configuration
355365
/// - logger: Logger used by queue
356-
public static func postgres(client: PostgresClient, migrations: DatabaseMigrations, configuration: PostgresJobQueue.Configuration = .init(), logger: Logger) async -> Self {
366+
public static func postgres(
367+
client: PostgresClient,
368+
migrations: DatabaseMigrations,
369+
configuration: PostgresJobQueue.Configuration = .init(),
370+
logger: Logger
371+
) async -> Self {
357372
await Self(client: client, migrations: migrations, configuration: configuration, logger: logger)
358373
}
359374
}

Tests/JobsPostgresTests/JobsTests.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414

1515
import Atomics
1616
import Jobs
17-
@testable import JobsPostgres
1817
import NIOConcurrencyHelpers
1918
import PostgresMigrations
2019
import PostgresNIO
2120
import ServiceLifecycle
2221
import XCTest
2322

23+
@testable import JobsPostgres
24+
2425
func getPostgresConfiguration() async throws -> PostgresClient.Configuration {
25-
return .init(
26+
.init(
2627
host: ProcessInfo.processInfo.environment["POSTGRES_HOSTNAME"] ?? "localhost",
2728
port: 5432,
2829
username: ProcessInfo.processInfo.environment["POSTGRES_USER"] ?? "test_user",
@@ -48,7 +49,11 @@ final class JobsTests: XCTestCase {
4849
#endif
4950
}
5051

51-
func createJobQueue(numWorkers: Int, configuration: PostgresJobQueue.Configuration, function: String = #function) async throws -> JobQueue<PostgresJobQueue> {
52+
func createJobQueue(
53+
numWorkers: Int,
54+
configuration: PostgresJobQueue.Configuration,
55+
function: String = #function
56+
) async throws -> JobQueue<PostgresJobQueue> {
5257
let logger = {
5358
var logger = Logger(label: function)
5459
logger.logLevel = .debug
@@ -181,7 +186,8 @@ final class JobsTests: XCTestCase {
181186
id: jobIdentifer,
182187
parameters: 1,
183188
options: .init(
184-
delayUntil: Date.now.addingTimeInterval(1))
189+
delayUntil: Date.now.addingTimeInterval(1)
190+
)
185191
)
186192
try await jobQueue.push(id: jobIdentifer2, parameters: 5)
187193

@@ -361,7 +367,10 @@ final class JobsTests: XCTestCase {
361367
succeededExpectation.fulfill()
362368
finished.store(true, ordering: .relaxed)
363369
}
364-
let jobQueue = try await createJobQueue(numWorkers: 1, configuration: .init(pendingJobsInitialization: .remove, failedJobsInitialization: .rerun))
370+
let jobQueue = try await createJobQueue(
371+
numWorkers: 1,
372+
configuration: .init(pendingJobsInitialization: .remove, failedJobsInitialization: .rerun)
373+
)
365374
jobQueue.registerJob(job)
366375
try await self.testJobQueue(jobQueue: jobQueue, revertMigrations: true) { jobQueue in
367376
// stall to give onInit a chance to run, so it can remove any pendng jobs

scripts/validate.sh

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,16 @@ SWIFT_FORMAT_VERSION=0.53.10
3131
set -eu
3232
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3333

34-
which swiftformat > /dev/null 2>&1 || (echo "swiftformat not installed. You can install it using 'brew install swiftformat'" ; exit -1)
35-
3634
function replace_acceptable_years() {
3735
# this needs to replace all acceptable forms with 'YEARS'
3836
sed -e 's/20[12][0-9]-20[12][0-9]/YEARS/' -e 's/20[12][0-9]/YEARS/' -e '/^#!/ d'
3937
}
4038

4139
printf "=> Checking format... "
4240
FIRST_OUT="$(git status --porcelain)"
43-
if [[ -n "${CI-""}" ]]; then
44-
printf "(using v$(mint run NickLockwood/SwiftFormat@"$SWIFT_FORMAT_VERSION" --version)) "
45-
mint run NickLockwood/SwiftFormat@"$SWIFT_FORMAT_VERSION" . > /dev/null 2>&1
46-
else
47-
printf "(using v$(swiftformat --version)) "
48-
swiftformat . > /dev/null 2>&1
49-
fi
41+
git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
42+
git diff --exit-code '*.swift'
43+
5044
SECOND_OUT="$(git status --porcelain)"
5145
if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then
5246
printf "\033[0;31mformatting issues!\033[0m\n"
@@ -55,29 +49,30 @@ if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then
5549
else
5650
printf "\033[0;32mokay.\033[0m\n"
5751
fi
58-
exit
5952
printf "=> Checking license headers... "
6053
tmp=$(mktemp /tmp/.soto-core-sanity_XXXXXX)
6154

55+
exit 0
56+
6257
for language in swift-or-c; do
6358
declare -a matching_files
6459
declare -a exceptions
6560
expections=( )
6661
matching_files=( -name '*' )
6762
case "$language" in
6863
swift-or-c)
69-
exceptions=( -path '*Sources/INIParser/*' -o -path '*Sources/CSotoExpat/*' -o -path '*Benchmark/.build/*' -o -name Package.swift)
64+
exceptions=( -path '*/Benchmarks/.build/*' -o -name Package.swift)
7065
matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' )
7166
cat > "$tmp" <<"EOF"
7267
//===----------------------------------------------------------------------===//
7368
//
74-
// This source file is part of the Hummingbird open source project
69+
// This source file is part of the Hummingbird server framework project
7570
//
7671
// Copyright (c) YEARS the Hummingbird authors
7772
// Licensed under Apache License v2.0
7873
//
7974
// See LICENSE.txt for license information
80-
// See CONTRIBUTORS.txt for the list of Hummingbird authors
75+
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
8176
//
8277
// SPDX-License-Identifier: Apache-2.0
8378
//
@@ -89,13 +84,13 @@ EOF
8984
cat > "$tmp" <<"EOF"
9085
##===----------------------------------------------------------------------===##
9186
##
92-
## This source file is part of the Hummingbird open source project
87+
## This source file is part of the Hummingbird server framework project
9388
##
9489
## Copyright (c) YEARS the Hummingbird authors
9590
## Licensed under Apache License v2.0
9691
##
9792
## See LICENSE.txt for license information
98-
## See CONTRIBUTORS.txt for the list of Hummingbird authors
93+
## See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
9994
##
10095
## SPDX-License-Identifier: Apache-2.0
10196
##

0 commit comments

Comments
 (0)