Skip to content

Commit 4ebfdd6

Browse files
committed
workflows: Disable tests; concentrate on fixing errors in soundness
1 parent 0366e59 commit 4ebfdd6

File tree

2 files changed

+105
-94
lines changed

2 files changed

+105
-94
lines changed

.github/workflows/pull_request.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ on:
55
types: [opened, reopened, synchronize]
66

77
jobs:
8-
tests:
9-
name: Test
10-
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
11-
with:
12-
linux_pre_build_command: apt-get update && apt-get install -y locales locales-all libsqlite3-dev
8+
# tests:
9+
# name: Test
10+
# uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
11+
# with:
12+
# linux_pre_build_command: apt-get update && apt-get install -y locales locales-all libsqlite3-dev
1313
soundness:
1414
name: Soundness
1515
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main

Sources/SwiftSDKGenerator/SystemUtils/HTTPClient+Download.swift

Lines changed: 100 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public protocol HTTPClientProtocol: Sendable {
5353
}
5454

5555
extension HTTPClientProtocol {
56-
static func with<Result: Sendable>(_ body: @Sendable (any HTTPClientProtocol) async throws -> Result) async throws
56+
static func with<Result: Sendable>(
57+
_ body: @Sendable (any HTTPClientProtocol) async throws -> Result
58+
) async throws
5759
-> Result
5860
{
5961
try await self.with(http1Only: false, body)
@@ -63,107 +65,112 @@ extension HTTPClientProtocol {
6365
extension FilePath: @unchecked Sendable {}
6466

6567
#if canImport(AsyncHTTPClient)
66-
import AsyncHTTPClient
67-
68-
extension FileDownloadDelegate.Progress: @unchecked Sendable {}
69-
70-
extension HTTPClient: HTTPClientProtocol {
71-
public static func with<Result: Sendable>(
72-
http1Only: Bool, _ body: @Sendable (any HTTPClientProtocol) async throws -> Result
73-
) async throws -> Result {
74-
var configuration = HTTPClient.Configuration(redirectConfiguration: .follow(max: 5, allowCycles: false))
75-
if http1Only {
76-
configuration.httpVersion = .http1Only
77-
}
78-
let client = HTTPClient(eventLoopGroupProvider: .singleton, configuration: configuration)
79-
return try await withAsyncThrowing {
80-
try await body(client)
81-
} defer: {
82-
try await client.shutdown()
68+
import AsyncHTTPClient
69+
70+
extension FileDownloadDelegate.Progress: @unchecked Sendable {}
71+
72+
extension HTTPClient: HTTPClientProtocol {
73+
public static func with<Result: Sendable>(
74+
http1Only: Bool, _ body: @Sendable (any HTTPClientProtocol) async throws -> Result
75+
) async throws -> Result {
76+
var configuration = HTTPClient.Configuration(
77+
redirectConfiguration: .follow(max: 5, allowCycles: false))
78+
if http1Only {
79+
configuration.httpVersion = .http1Only
80+
}
81+
let client = HTTPClient(eventLoopGroupProvider: .singleton, configuration: configuration)
82+
return try await withAsyncThrowing {
83+
try await body(client)
84+
} defer: {
85+
try await client.shutdown()
86+
}
8387
}
84-
}
8588

86-
public func get(url: String) async throws -> (status: NIOHTTP1.HTTPResponseStatus, body: NIOCore.ByteBuffer?) {
87-
let response = try await self.get(url: url).get()
88-
return (status: response.status, body: response.body)
89-
}
89+
public func get(url: String) async throws -> (
90+
status: NIOHTTP1.HTTPResponseStatus, body: NIOCore.ByteBuffer?
91+
) {
92+
let response = try await self.get(url: url).get()
93+
return (status: response.status, body: response.body)
94+
}
9095

91-
public func head(url: String, headers: NIOHTTP1.HTTPHeaders) async throws -> Bool {
92-
var headRequest = HTTPClientRequest(url: url)
93-
headRequest.method = .HEAD
94-
headRequest.headers = ["Accept": "*/*", "User-Agent": "Swift SDK Generator"]
95-
return try await self.execute(headRequest, deadline: .distantFuture).status == .ok
96-
}
96+
public func head(url: String, headers: NIOHTTP1.HTTPHeaders) async throws -> Bool {
97+
var headRequest = HTTPClientRequest(url: url)
98+
headRequest.method = .HEAD
99+
headRequest.headers = ["Accept": "*/*", "User-Agent": "Swift SDK Generator"]
100+
return try await self.execute(headRequest, deadline: .distantFuture).status == .ok
101+
}
97102

98-
public func downloadFile(
99-
from url: URL,
100-
to path: FilePath
101-
) async throws {
102-
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<(), Error>) in
103-
do {
104-
let delegate = try FileDownloadDelegate(
105-
path: path.string,
106-
reportHead: { task, responseHead in
107-
if responseHead.status != .ok {
108-
task.fail(reason: GeneratorError.fileDownloadFailed(url, responseHead.status.description))
103+
public func downloadFile(
104+
from url: URL,
105+
to path: FilePath
106+
) async throws {
107+
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<(), Error>) in
108+
do {
109+
let delegate = try FileDownloadDelegate(
110+
path: path.string,
111+
reportHead: { task, responseHead in
112+
if responseHead.status != .ok {
113+
task.fail(
114+
reason: GeneratorError.fileDownloadFailed(url, responseHead.status.description))
115+
}
116+
}
117+
)
118+
let request = try HTTPClient.Request(url: url)
119+
120+
execute(request: request, delegate: delegate).futureResult.whenComplete {
121+
switch $0 {
122+
case let .failure(error):
123+
continuation.resume(throwing: error)
124+
case .success:
125+
continuation.resume(returning: ())
109126
}
110127
}
111-
)
112-
let request = try HTTPClient.Request(url: url)
113-
114-
execute(request: request, delegate: delegate).futureResult.whenComplete {
115-
switch $0 {
116-
case let .failure(error):
117-
continuation.resume(throwing: error)
118-
case .success:
119-
continuation.resume(returning: ())
120-
}
128+
} catch {
129+
continuation.resume(throwing: error)
121130
}
122-
} catch {
123-
continuation.resume(throwing: error)
124131
}
125132
}
126-
}
127133

128-
public func streamDownloadProgress(
129-
from url: URL,
130-
to path: FilePath
131-
) -> AsyncThrowingStream<DownloadProgress, any Error> {
132-
.init { continuation in
133-
do {
134-
let delegate = try FileDownloadDelegate(
135-
path: path.string,
136-
reportHead: {
137-
if $0.status != .ok {
138-
continuation
139-
.finish(throwing: FileOperationError.downloadFailed(url, $0.status.description))
134+
public func streamDownloadProgress(
135+
from url: URL,
136+
to path: FilePath
137+
) -> AsyncThrowingStream<DownloadProgress, any Error> {
138+
.init { continuation in
139+
do {
140+
let delegate = try FileDownloadDelegate(
141+
path: path.string,
142+
reportHead: {
143+
if $0.status != .ok {
144+
continuation
145+
.finish(throwing: FileOperationError.downloadFailed(url, $0.status.description))
146+
}
147+
},
148+
reportProgress: {
149+
continuation.yield(
150+
DownloadProgress(totalBytes: $0.totalBytes, receivedBytes: $0.receivedBytes)
151+
)
152+
}
153+
)
154+
let request = try HTTPClient.Request(url: url)
155+
156+
execute(request: request, delegate: delegate).futureResult.whenComplete {
157+
switch $0 {
158+
case let .failure(error):
159+
continuation.finish(throwing: error)
160+
case let .success(finalProgress):
161+
continuation.yield(
162+
DownloadProgress(
163+
totalBytes: finalProgress.totalBytes, receivedBytes: finalProgress.receivedBytes)
164+
)
165+
continuation.finish()
140166
}
141-
},
142-
reportProgress: {
143-
continuation.yield(
144-
DownloadProgress(totalBytes: $0.totalBytes, receivedBytes: $0.receivedBytes)
145-
)
146-
}
147-
)
148-
let request = try HTTPClient.Request(url: url)
149-
150-
execute(request: request, delegate: delegate).futureResult.whenComplete {
151-
switch $0 {
152-
case let .failure(error):
153-
continuation.finish(throwing: error)
154-
case let .success(finalProgress):
155-
continuation.yield(
156-
DownloadProgress(totalBytes: finalProgress.totalBytes, receivedBytes: finalProgress.receivedBytes)
157-
)
158-
continuation.finish()
159167
}
168+
} catch {
169+
continuation.finish(throwing: error)
160170
}
161-
} catch {
162-
continuation.finish(throwing: error)
163171
}
164172
}
165173
}
166-
}
167174
#endif
168175

169176
struct OfflineHTTPClient: HTTPClientProtocol {
@@ -189,11 +196,15 @@ struct OfflineHTTPClient: HTTPClientProtocol {
189196
}
190197
}
191198

192-
public func get(url: String) async throws -> (status: NIOHTTP1.HTTPResponseStatus, body: NIOCore.ByteBuffer?) {
193-
throw FileOperationError.downloadFailed(URL(string: url)!, "Cannot fetch file with offline client")
199+
public func get(url: String) async throws -> (
200+
status: NIOHTTP1.HTTPResponseStatus, body: NIOCore.ByteBuffer?
201+
) {
202+
throw FileOperationError.downloadFailed(
203+
URL(string: url)!, "Cannot fetch file with offline client")
194204
}
195205

196206
public func head(url: String, headers: NIOHTTP1.HTTPHeaders) async throws -> Bool {
197-
throw FileOperationError.downloadFailed(URL(string: url)!, "Cannot fetch file with offline client")
207+
throw FileOperationError.downloadFailed(
208+
URL(string: url)!, "Cannot fetch file with offline client")
198209
}
199210
}

0 commit comments

Comments
 (0)