Skip to content

Commit c621142

Browse files
authored
Adopt GitHub actions (#780)
Migrate CI to use GitHub Actions. ### Motivation: To migrate to GitHub actions and centralised infrastructure. ### Modifications: Changes of note: * Adopt swift-format using rules from SwiftNIO. * Remove scripts and docker files which are no longer needed. * Disabled warnings-as-errors on Swift 6.0 CI pipelines for now. ### Result: Feature parity with old CI.
1 parent acaca2d commit c621142

File tree

123 files changed

+7280
-4445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+7280
-4445
lines changed

.github/workflows/main.yml

+18
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: "--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

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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: "AsyncHTTPClient"
13+
unit-tests:
14+
name: Unit tests
15+
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
16+
with:
17+
linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
18+
linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
19+
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
20+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
21+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
22+
23+
cxx-interop:
24+
name: Cxx interop
25+
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
26+
27+
swift-6-language-mode:
28+
name: Swift 6 Language Mode
29+
uses: apple/swift-nio/.github/workflows/swift_6_language_mode.yml@main
30+
if: false # Disabled for now.
+18
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

.licenseignore

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

.swift-format

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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" : 120,
18+
"maximumBlankLines" : 1,
19+
"respectsExistingLineBreaks" : true,
20+
"prioritizeKeepingFunctionOutputTogether" : true,
21+
"noAssignmentInExpressions" : {
22+
"allowedFunctions" : [
23+
"XCTAssertNoThrow",
24+
"XCTAssertThrowsError"
25+
]
26+
},
27+
"rules" : {
28+
"AllPublicDeclarationsHaveDocumentation" : false,
29+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
30+
"AlwaysUseLowerCamelCase" : false,
31+
"AmbiguousTrailingClosureOverload" : true,
32+
"BeginDocumentationCommentWithOneLineSummary" : false,
33+
"DoNotUseSemicolons" : true,
34+
"DontRepeatTypeInStaticProperties" : true,
35+
"FileScopedDeclarationPrivacy" : true,
36+
"FullyIndirectEnum" : true,
37+
"GroupNumericLiterals" : true,
38+
"IdentifiersMustBeASCII" : true,
39+
"NeverForceUnwrap" : false,
40+
"NeverUseForceTry" : false,
41+
"NeverUseImplicitlyUnwrappedOptionals" : false,
42+
"NoAccessLevelOnExtensionDeclaration" : true,
43+
"NoAssignmentInExpressions" : true,
44+
"NoBlockComments" : true,
45+
"NoCasesWithOnlyFallthrough" : true,
46+
"NoEmptyTrailingClosureParentheses" : true,
47+
"NoLabelsInCasePatterns" : true,
48+
"NoLeadingUnderscores" : false,
49+
"NoParensAroundConditions" : true,
50+
"NoVoidReturnOnFunctionSignature" : true,
51+
"OmitExplicitReturns" : true,
52+
"OneCasePerLine" : true,
53+
"OneVariableDeclarationPerLine" : true,
54+
"OnlyOneTrailingClosureArgument" : true,
55+
"OrderedImports" : true,
56+
"ReplaceForEachWithForLoop" : true,
57+
"ReturnVoidInsteadOfEmptyTuple" : true,
58+
"UseEarlyExits" : false,
59+
"UseExplicitNilCheckInConditions" : false,
60+
"UseLetInEveryBoundCaseVariable" : false,
61+
"UseShorthandTypeNames" : true,
62+
"UseSingleLinePropertyGetter" : false,
63+
"UseSynthesizedInitializer" : false,
64+
"UseTripleSlashForDocumentationComments" : true,
65+
"UseWhereClausesInForLoops" : false,
66+
"ValidateDocumentationComments" : false
67+
}
68+
}

.swiftformat

-24
This file was deleted.

CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ We require that your commit messages match our template. The easiest way to do t
6565

6666
git config commit.template dev/git.commit.template
6767

68-
### Make sure Tests work on Linux
6968

70-
AsyncHTTPClient uses XCTest to run tests on both macOS and Linux. While the macOS version of XCTest is able to use the Objective-C runtime to discover tests at execution time, the Linux version is not.
71-
For this reason, whenever you add new tests **you have to run a script** that generates the hooks needed to run those tests on Linux, or our CI will complain that the tests are not all present on Linux. To do this, merely execute `ruby ./scripts/generate_linux_tests.rb` at the root of the package and check the changes it made.
69+
### Run CI checks locally
70+
71+
You can run the Github Actions workflows locally using [act](https://github.com/nektos/act). For detailed steps on how to do this please see [https://github.com/swiftlang/github-workflows?tab=readme-ov-file#running-workflows-locally](https://github.com/swiftlang/github-workflows?tab=readme-ov-file#running-workflows-locally).
7272

7373
## How to contribute your work
7474

Examples/GetHTML/GetHTML.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct GetHTML {
2323
let request = HTTPClientRequest(url: "https://apple.com")
2424
let response = try await httpClient.execute(request, timeout: .seconds(30))
2525
print("HTTP head", response)
26-
let body = try await response.body.collect(upTo: 1024 * 1024) // 1 MB
26+
let body = try await response.body.collect(upTo: 1024 * 1024) // 1 MB
2727
print(String(buffer: body))
2828
} catch {
2929
print("request failed:", error)

Examples/GetJSON/GetJSON.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct GetJSON {
3838
let request = HTTPClientRequest(url: "https://xkcd.com/info.0.json")
3939
let response = try await httpClient.execute(request, timeout: .seconds(30))
4040
print("HTTP head", response)
41-
let body = try await response.body.collect(upTo: 1024 * 1024) // 1 MB
41+
let body = try await response.body.collect(upTo: 1024 * 1024) // 1 MB
4242
// we use an overload defined in `NIOFoundationCompat` for `decode(_:from:)` to
4343
// efficiently decode from a `ByteBuffer`
4444
let comic = try JSONDecoder().decode(Comic.self, from: body)

Examples/Package.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,25 @@ let package = Package(
4343
dependencies: [
4444
.product(name: "AsyncHTTPClient", package: "async-http-client"),
4545
.product(name: "NIOCore", package: "swift-nio"),
46-
], path: "GetHTML"
46+
],
47+
path: "GetHTML"
4748
),
4849
.executableTarget(
4950
name: "GetJSON",
5051
dependencies: [
5152
.product(name: "AsyncHTTPClient", package: "async-http-client"),
5253
.product(name: "NIOCore", package: "swift-nio"),
5354
.product(name: "NIOFoundationCompat", package: "swift-nio"),
54-
], path: "GetJSON"
55+
],
56+
path: "GetJSON"
5557
),
5658
.executableTarget(
5759
name: "StreamingByteCounter",
5860
dependencies: [
5961
.product(name: "AsyncHTTPClient", package: "async-http-client"),
6062
.product(name: "NIOCore", package: "swift-nio"),
61-
], path: "StreamingByteCounter"
63+
],
64+
path: "StreamingByteCounter"
6265
),
6366
]
6467
)

NOTICE.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ This product contains a derivation of the Tony Stone's 'process_test_files.rb'.
5050
* https://www.apache.org/licenses/LICENSE-2.0
5151
* HOMEPAGE:
5252
* https://github.com/tonystone/build-tools/commit/6c417b7569df24597a48a9aa7b505b636e8f73a1
53-
* https://github.com/tonystone/build-tools/blob/master/source/xctest_tool.rb
53+
* https://github.com/tonystone/build-tools/blob/cf3440f43bde2053430285b4ed0709c865892eb5/source/xctest_tool.rb
5454

5555
---
5656

5757
This product contains a derivation of Fabian Fett's 'Base64.swift'.
5858

5959
* LICENSE (Apache License 2.0):
60-
* https://github.com/fabianfett/swift-base64-kit/blob/master/LICENSE
60+
* https://github.com/swift-extras/swift-extras-base64/blob/b8af49699d59ad065b801715a5009619100245ca/LICENSE
6161
* HOMEPAGE:
6262
* https://github.com/fabianfett/swift-base64-kit

Package.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import PackageDescription
1818
let package = Package(
1919
name: "async-http-client",
2020
products: [
21-
.library(name: "AsyncHTTPClient", targets: ["AsyncHTTPClient"]),
21+
.library(name: "AsyncHTTPClient", targets: ["AsyncHTTPClient"])
2222
],
2323
dependencies: [
2424
.package(url: "https://github.com/apple/swift-nio.git", from: "2.71.0"),
@@ -28,14 +28,13 @@ let package = Package(
2828
.package(url: "https://github.com/apple/swift-nio-transport-services.git", from: "1.19.0"),
2929
.package(url: "https://github.com/apple/swift-log.git", from: "1.4.4"),
3030
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
31-
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"),
3231
.package(url: "https://github.com/apple/swift-algorithms.git", from: "1.0.0"),
3332
],
3433
targets: [
3534
.target(
3635
name: "CAsyncHTTPClient",
3736
cSettings: [
38-
.define("_GNU_SOURCE"),
37+
.define("_GNU_SOURCE")
3938
]
4039
),
4140
.target(

Sources/AsyncHTTPClient/AsyncAwait/HTTPClient+execute.swift

+37-30
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import struct Foundation.URL
1615
import Logging
1716
import NIOCore
1817
import NIOHTTP1
1918

19+
import struct Foundation.URL
20+
2021
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
2122
extension HTTPClient {
2223
/// Execute arbitrary HTTP requests.
@@ -85,11 +86,13 @@ extension HTTPClient {
8586
return response
8687
}
8788

88-
guard let redirectURL = response.headers.extractRedirectTarget(
89-
status: response.status,
90-
originalURL: preparedRequest.url,
91-
originalScheme: preparedRequest.poolKey.scheme
92-
) else {
89+
guard
90+
let redirectURL = response.headers.extractRedirectTarget(
91+
status: response.status,
92+
originalURL: preparedRequest.url,
93+
originalScheme: preparedRequest.poolKey.scheme
94+
)
95+
else {
9396
// response does not want a redirect
9497
return response
9598
}
@@ -120,31 +123,35 @@ extension HTTPClient {
120123
) async throws -> HTTPClientResponse {
121124
let cancelHandler = TransactionCancelHandler()
122125

123-
return try await withTaskCancellationHandler(operation: { () async throws -> HTTPClientResponse in
124-
let eventLoop = self.eventLoopGroup.any()
125-
let deadlineTask = eventLoop.scheduleTask(deadline: deadline) {
126-
cancelHandler.cancel(reason: .deadlineExceeded)
127-
}
128-
defer {
129-
deadlineTask.cancel()
130-
}
131-
return try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<HTTPClientResponse, Swift.Error>) -> Void in
132-
let transaction = Transaction(
133-
request: request,
134-
requestOptions: .fromClientConfiguration(self.configuration),
135-
logger: logger,
136-
connectionDeadline: .now() + (self.configuration.timeout.connectionCreationTimeout),
137-
preferredEventLoop: eventLoop,
138-
responseContinuation: continuation
139-
)
140-
141-
cancelHandler.registerTransaction(transaction)
142-
143-
self.poolManager.executeRequest(transaction)
126+
return try await withTaskCancellationHandler(
127+
operation: { () async throws -> HTTPClientResponse in
128+
let eventLoop = self.eventLoopGroup.any()
129+
let deadlineTask = eventLoop.scheduleTask(deadline: deadline) {
130+
cancelHandler.cancel(reason: .deadlineExceeded)
131+
}
132+
defer {
133+
deadlineTask.cancel()
134+
}
135+
return try await withCheckedThrowingContinuation {
136+
(continuation: CheckedContinuation<HTTPClientResponse, Swift.Error>) -> Void in
137+
let transaction = Transaction(
138+
request: request,
139+
requestOptions: .fromClientConfiguration(self.configuration),
140+
logger: logger,
141+
connectionDeadline: .now() + (self.configuration.timeout.connectionCreationTimeout),
142+
preferredEventLoop: eventLoop,
143+
responseContinuation: continuation
144+
)
145+
146+
cancelHandler.registerTransaction(transaction)
147+
148+
self.poolManager.executeRequest(transaction)
149+
}
150+
},
151+
onCancel: {
152+
cancelHandler.cancel(reason: .taskCanceled)
144153
}
145-
}, onCancel: {
146-
cancelHandler.cancel(reason: .taskCanceled)
147-
})
154+
)
148155
}
149156
}
150157

0 commit comments

Comments
 (0)