Skip to content

Commit 6497387

Browse files
authored
Merge pull request #22 from tayloraswift/build-automation
turn PackageBuildStatus into a type and JSON coding model
2 parents 860217d + ca338de commit 6497387

Some content is hidden

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

48 files changed

+1197
-667
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.build
22
.massbuild
3+
.swiftinit
34
.testing
45
.unidoc
56
.vscode

Package.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ let package:Package = .init(
5656

5757
.library(name: "Unidoc", targets: ["Unidoc"]),
5858
.library(name: "UnidocAnalysis", targets: ["UnidocAnalysis"]),
59+
.library(name: "UnidocAutomation", targets: ["UnidocAutomation"]),
5960
.library(name: "UnidocDB", targets: ["UnidocDB"]),
6061
.library(name: "UnidocDiagnostics", targets: ["UnidocDiagnostics"]),
6162
.library(name: "UnidocLinker", targets: ["UnidocLinker"]),
@@ -65,6 +66,7 @@ let package:Package = .init(
6566
.library(name: "UnidocSelectors", targets: ["UnidocSelectors"]),
6667
.library(name: "URI", targets: ["URI"]),
6768

69+
.executable(name: "UnidocBuild", targets: ["UnidocBuild"]),
6870
.executable(name: "UnidocServer", targets: ["UnidocServer"]),
6971
],
7072
dependencies:
@@ -381,6 +383,11 @@ let package:Package = .init(
381383
.target(name: "UnidocSelectors"),
382384
]),
383385

386+
.target(name: "UnidocAutomation", dependencies:
387+
[
388+
.target(name: "JSON"),
389+
]),
390+
384391
.target(name: "UnidocDB", dependencies:
385392
[
386393
.target(name: "GitHubAPI"),
@@ -409,6 +416,7 @@ let package:Package = .init(
409416
.target(name: "GitHubAPI"),
410417
.target(name: "HTTP"),
411418
.target(name: "MarkdownRendering"),
419+
.target(name: "UnidocAutomation"),
412420
.target(name: "UnidocQueries"),
413421
.target(name: "URI"),
414422
]),
@@ -447,8 +455,10 @@ let package:Package = .init(
447455
]),
448456

449457

450-
.executableTarget(name: "Massbuild", dependencies:
458+
.executableTarget(name: "UnidocBuild", dependencies:
451459
[
460+
.target(name: "HTTPClient"),
461+
.target(name: "UnidocAutomation"),
452462
.target(name: "SymbolGraphBuilder"),
453463
]),
454464

Sources/GitHubClient/GitHubClient.Connection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ extension GitHubClient<GitHubOAuth.API>.Connection
9494
}
9595

9696
status = response.status
97-
break
97+
break following
9898
}
9999

100100
throw GitHubClient<GitHubOAuth.API>.StatusError.init(code: status)

Sources/HTTPClient/ClientInterfaceHandler.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ extension ClientInterfaceHandler:ChannelOutboundHandler
4444
batch:[HPACKHeaders]
4545
)
4646

47+
func errorCaught(context:ChannelHandlerContext, error:any Error)
48+
{
49+
self.owner?.finish(throwing: error)
50+
context.channel.close(promise: nil)
51+
}
52+
4753
func write(context:ChannelHandlerContext, data:NIOAny, promise:EventLoopPromise<Void>?)
4854
{
4955
let owner:AsyncThrowingStream<HTTP2Client.Facet, any Error>.Continuation
@@ -65,14 +71,12 @@ extension ClientInterfaceHandler:ChannelOutboundHandler
6571
switch $0
6672
{
6773
case .success(let stream):
68-
stream.write(HTTP2Frame.FramePayload.headers(
74+
stream.writeAndFlush(HTTP2Frame.FramePayload.headers(
6975
HTTP2Frame.FramePayload.Headers.init(
7076
headers: request,
7177
endStream: true)),
7278
promise: nil)
7379

74-
stream.flush()
75-
7680
case .failure(let error):
7781
owner.finish(throwing: error)
7882
context.channel.close(promise: nil)

Sources/HTTPClient/HTTP2Client.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ extension HTTP2Client
8484
{
8585
/// Connect to the remote host over HTTPS and perform the given operation.
8686
@inlinable public
87-
func connect<T>(with body:(Connection) async throws -> T) async throws -> T
87+
func connect<T>(port:Int = 443, with body:(Connection) async throws -> T) async throws -> T
8888
{
8989
let channel:any Channel = try await self.bootstrap.connect(
9090
host: self.remote,
91-
port: 443).get()
91+
port: port).get()
9292

9393
defer
9494
{

Sources/HTTPServer/Channels/HTTPServerOperation.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,33 @@ protocol HTTPServerOperation:Sendable
1818
address:SocketAddress?,
1919
headers:HTTPHeaders,
2020
body:[UInt8])
21+
22+
init?(put uri:String,
23+
address:SocketAddress?,
24+
headers:HTTPHeaders,
25+
body:[UInt8])
2126
}
2227
extension HTTPServerOperation
2328
{
2429
@inlinable public
25-
init?(_ uri:String,
30+
init?(get uri:String,
2631
address:SocketAddress?,
2732
headers:HTTPHeaders)
2833
{
2934
nil
3035
}
3136

3237
@inlinable public
33-
init?(_ uri:String,
38+
init?(post uri:String,
39+
address:SocketAddress?,
40+
headers:HTTPHeaders,
41+
body:[UInt8])
42+
{
43+
nil
44+
}
45+
46+
@inlinable public
47+
init?(put uri:String,
3448
address:SocketAddress?,
3549
headers:HTTPHeaders,
3650
body:[UInt8])

Sources/HTTPServer/Channels/ServerInterfaceHandler.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ extension ServerInterfaceHandler:ChannelInboundHandler, RemovableChannelHandler
7777
self.send(message: .init(status: .badRequest), context: context)
7878
}
7979

80-
case .POST:
80+
case .POST, .PUT:
8181
self.request = (head, .init())
8282

8383
case _:
@@ -119,10 +119,27 @@ extension ServerInterfaceHandler:ChannelInboundHandler, RemovableChannelHandler
119119

120120
self.request = nil
121121

122-
if let operation:Server.Operation = .init(post: head.uri,
122+
let operation:Server.Operation?
123+
124+
switch head.method
125+
{
126+
case .POST:
127+
operation = .init(post: head.uri,
123128
address: self.address,
124129
headers: head.headers,
125130
body: body)
131+
132+
case .PUT:
133+
operation = .init(put: head.uri,
134+
address: self.address,
135+
headers: head.headers,
136+
body: body)
137+
138+
case _:
139+
fatalError("unreachable: collected buffers for method \(head.method)!")
140+
}
141+
142+
if let operation:Server.Operation
126143
{
127144
self.server.submit(operation, promise: self.accept(context: context))
128145
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import JSONAST
2+
3+
public
4+
protocol JSONObjectEncodable<CodingKey>:JSONEncodable
5+
{
6+
associatedtype CodingKey:RawRepresentable<String> = JSON.Key
7+
8+
func encode(to json:inout JSON.ObjectEncoder<CodingKey>)
9+
}
10+
extension JSONObjectEncodable
11+
{
12+
@inlinable public
13+
func encode(to json:inout JSON)
14+
{
15+
self.encode(to: &json[as: JSON.ObjectEncoder<CodingKey>.self])
16+
}
17+
}

Sources/Massbuild/Main.swift

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

Sources/Media/MediaSubtype.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ enum MediaSubtype:String, Equatable, Hashable, Sendable
33
{
44
case apng
55
case avif
6+
case bson
67
case css
78
case gif
89
case html
@@ -75,6 +76,7 @@ extension MediaSubtype
7576
{
7677
case .apng: return "apng"
7778
case .avif: return "avif"
79+
case .bson: return "bson"
7880
case .css: return "css"
7981
case .gif: return "gif"
8082
case .html: return "html"

0 commit comments

Comments
 (0)