Skip to content

Commit 4e86cce

Browse files
authored
MIgrate to GH actions (#22)
* Add GH action files from swift-server/swift-openapi-async-http-client * Remove scripts * Revert unintended TaskLocal changes * Disable license header check (It adds Apple to the license) * swift-format * yml format * format Package.swift * Try license header template
1 parent 47ebf5b commit 4e86cce

23 files changed

+160
-598
lines changed

.editorconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true

.github/workflows/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches: [main]
6+
schedule:
7+
- cron: "0 8,20 * * *"
8+
9+
jobs:
10+
unit-tests:
11+
name: Unit tests
12+
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
13+
with:
14+
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
15+
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
16+
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
17+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
18+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"

.github/workflows/pull_request.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: PR
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
soundness:
9+
name: Soundness
10+
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
11+
with:
12+
license_header_check_project_name: "Hummingbird server framework"
13+
14+
15+
unit-tests:
16+
name: Unit tests
17+
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
18+
with:
19+
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -strict-concurrency=complete"
20+
# TODO: `enable -Xswiftc -strict-concurrency=complete`
21+
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
22+
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable -Xswiftc -strict-concurrency=complete"
23+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
24+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
25+
26+
cxx-interop:
27+
name: Cxx interop
28+
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: PR label
2+
3+
on:
4+
pull_request:
5+
types: [labeled, unlabeled, opened, reopened, synchronize]
6+
7+
jobs:
8+
semver-label-check:
9+
name: Semantic version label check
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 1
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
with:
16+
persist-credentials: false
17+
- name: Check for Semantic Version label
18+
uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main

.license_header_template

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@@===----------------------------------------------------------------------===@@
2+
@@
3+
@@ This source file is part of the Hummingbird server framework project
4+
@@
5+
@@ Copyright (c) YEARS the Hummingbird authors
6+
@@ Licensed under Apache License v2.0
7+
@@
8+
@@ See LICENSE.txt for license information
9+
@@ See CONTRIBUTORS.txt for the list of Hummingbird authors
10+
@@
11+
@@ SPDX-License-Identifier: Apache-2.0
12+
@@
13+
@@===----------------------------------------------------------------------===@@

.licenseignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.gitignore
2+
**/.gitignore
3+
.licenseignore
4+
.gitattributes
5+
.git-blame-ignore-revs
6+
.mailfilter
7+
.mailmap
8+
.spi.yml
9+
.swift-format
10+
.swiftformatignore
11+
.editorconfig
12+
.github/*
13+
*.md
14+
*.txt
15+
*.yml
16+
*.yaml
17+
*.json
18+
Package.swift
19+
**/Package.swift
20+
Package@-*.swift
21+
**/Package@-*.swift
22+
Package.resolved
23+
**/Package.resolved
24+
Makefile
25+
*.modulemap
26+
**/*.modulemap
27+
**/*.docc/*
28+
*.xcprivacy
29+
**/*.xcprivacy
30+
*.symlink
31+
**/*.symlink
32+
Dockerfile
33+
**/Dockerfile
34+
Snippets/*
35+
dev/git.commit.template
36+
.unacceptablelanguageignore

.spi.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: 1
2+
builder:
3+
configs:
4+
- documentation_targets:
5+
- OpenAPIHummingbird

.swift-format

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
"lineLength" : 120,
1515
"maximumBlankLines" : 1,
1616
"prioritizeKeepingFunctionOutputTogether" : false,
17-
"respectsExistingLineBreaks" : true,
17+
"respectsExistingLineBreaks" : false,
1818
"rules" : {
19-
"AllPublicDeclarationsHaveDocumentation" : false,
19+
"AllPublicDeclarationsHaveDocumentation" : true,
2020
"AlwaysUseLowerCamelCase" : false,
2121
"AmbiguousTrailingClosureOverload" : true,
2222
"BeginDocumentationCommentWithOneLineSummary" : false,
@@ -50,9 +50,9 @@
5050
"UseSynthesizedInitializer" : true,
5151
"UseTripleSlashForDocumentationComments" : true,
5252
"UseWhereClausesInForLoops" : false,
53-
"ValidateDocumentationComments" : false
53+
"ValidateDocumentationComments" : true
5454
},
5555
"spacesAroundRangeFormationOperators" : false,
5656
"tabWidth" : 8,
5757
"version" : 1
58-
}
58+
}

Package.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ import PackageDescription
55

66
let package = Package(
77
name: "swift-openapi-hummingbird",
8-
platforms: [
9-
.macOS(.v14), .iOS(.v17), .tvOS(.v17), .watchOS(.v10),
10-
],
11-
products: [
12-
.library(name: "OpenAPIHummingbird", targets: ["OpenAPIHummingbird"]),
13-
],
8+
platforms: [.macOS(.v14), .iOS(.v17), .tvOS(.v17), .watchOS(.v10)],
9+
products: [.library(name: "OpenAPIHummingbird", targets: ["OpenAPIHummingbird"])],
1410
dependencies: [
1511
.package(url: "https://github.com/apple/swift-openapi-runtime.git", from: "1.0.0"),
1612
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0"),
@@ -25,10 +21,7 @@ let package = Package(
2521
),
2622
.testTarget(
2723
name: "OpenAPIHummingbirdTests",
28-
dependencies: [
29-
"OpenAPIHummingbird",
30-
.product(name: "HummingbirdTesting", package: "hummingbird"),
31-
]
24+
dependencies: ["OpenAPIHummingbird", .product(name: "HummingbirdTesting", package: "hummingbird")]
3225
),
3326
]
3427
)

Sources/OpenAPIHummingbird/OpenAPITransport.swift

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,21 @@ extension RouterMethods {
2424
/// - handler: A handler to be invoked when an HTTP request is received.
2525
/// - method: An HTTP request method.
2626
/// - path: The URL path components, for example `["pets", ":petId"]`.
27-
/// - queryItemNames: The names of query items to be extracted
28-
/// from the request URL that matches the provided HTTP operation.
2927
public func register(
3028
_ handler: @escaping @Sendable (HTTPRequest, HTTPBody?, ServerRequestMetadata) async throws -> (
3129
HTTPResponse, HTTPBody?
3230
),
3331
method: HTTPRequest.Method,
3432
path: String
35-
) throws {
36-
self.on(
37-
.init(path),
38-
method: method
39-
) { request, context in
33+
) {
34+
self.on(.init(path), method: method) { request, context in
4035
let (openAPIRequest, openAPIRequestBody) = try request.makeOpenAPIRequest(context: context)
4136
let openAPIRequestMetadata = context.makeOpenAPIRequestMetadata()
42-
let (openAPIResponse, openAPIResponseBody) = try await handler(openAPIRequest, openAPIRequestBody, openAPIRequestMetadata)
37+
let (openAPIResponse, openAPIResponseBody) = try await handler(
38+
openAPIRequest,
39+
openAPIRequestBody,
40+
openAPIRequestMetadata
41+
)
4342
return Response(openAPIResponse, body: openAPIResponseBody)
4443
}
4544
}
@@ -50,16 +49,11 @@ extension Request {
5049
func makeOpenAPIRequest<Context: RequestContext>(context: Context) throws -> (HTTPRequest, HTTPBody?) {
5150
let request = self.head
5251
// extract length from content-length header
53-
let length = if let contentLengthHeader = self.headers[.contentLength], let contentLength = Int(contentLengthHeader) {
54-
HTTPBody.Length.known(numericCast(contentLength))
55-
} else {
56-
HTTPBody.Length.unknown
57-
}
58-
let body = HTTPBody(
59-
self.body.map { [UInt8](buffer: $0) },
60-
length: length,
61-
iterationBehavior: .single
62-
)
52+
let length =
53+
if let contentLengthHeader = self.headers[.contentLength], let contentLength = Int(contentLengthHeader) {
54+
HTTPBody.Length.known(numericCast(contentLength))
55+
} else { HTTPBody.Length.unknown }
56+
let body = HTTPBody(self.body.map { [UInt8](buffer: $0) }, length: length, iterationBehavior: .single)
6357
return (request, body)
6458
}
6559
}
@@ -69,22 +63,18 @@ extension RequestContext {
6963
func makeOpenAPIRequestMetadata() -> ServerRequestMetadata {
7064
let keyAndValues = self.parameters.map { (key: String($0.0), value: $0.1) }
7165
let openAPIParameters = [String: Substring](keyAndValues) { first, _ in first }
72-
return .init(
73-
pathParameters: openAPIParameters
74-
)
66+
return .init(pathParameters: openAPIParameters)
7567
}
7668
}
7769

7870
extension Response {
7971
init(_ response: HTTPResponse, body: HTTPBody?) {
8072
let responseBody: ResponseBody
8173
if let body = body {
82-
let bufferSequence = body.map { ByteBuffer(bytes: $0)}
74+
let bufferSequence = body.map { ByteBuffer(bytes: $0) }
8375
if case .known(let length) = body.length {
8476
responseBody = .init(contentLength: numericCast(length)) { writer in
85-
for try await buffer in bufferSequence {
86-
try await writer.write(buffer)
87-
}
77+
for try await buffer in bufferSequence { try await writer.write(buffer) }
8878
try await writer.finish(nil)
8979
}
9080
} else {
@@ -94,11 +84,7 @@ extension Response {
9484
responseBody = .init(byteBuffer: ByteBuffer())
9585
}
9686

97-
self.init(
98-
status: response.status,
99-
headers: response.headerFields,
100-
body: responseBody
101-
)
87+
self.init(status: response.status, headers: response.headerFields, body: responseBody)
10288
}
10389
}
10490

@@ -110,4 +96,4 @@ extension RouteCollection: @retroactive ServerTransport {}
11096
extension Router: ServerTransport {}
11197
extension RouterGroup: ServerTransport {}
11298
extension RouteCollection: ServerTransport {}
113-
#endif
99+
#endif

0 commit comments

Comments
 (0)