Skip to content

Commit e706c33

Browse files
committed
Decouple from the known list of platforms and branches so that swiftly can operate independently of its current schema version
1 parent ed6dc64 commit e706c33

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

Sources/SwiftlyCore/HTTPClient.swift

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public protocol HTTPRequestExecutor {
5454
func execute(_ request: HTTPClientRequest, timeout: TimeAmount) async throws -> HTTPClientResponse
5555
func getCurrentSwiftlyRelease() async throws -> Components.Schemas.SwiftlyRelease
5656
func getReleaseToolchains() async throws -> [Components.Schemas.Release]
57-
func getSnapshotToolchains(branch: Components.Schemas.KnownSourceBranch, platform: Components.Schemas.KnownPlatformIdentifier) async throws -> Components.Schemas.DevToolchains
57+
func getSnapshotToolchains(branch: Components.Schemas.SourceBranch, platform: Components.Schemas.PlatformIdentifier) async throws -> Components.Schemas.DevToolchains
5858
}
5959

6060
internal struct SwiftlyUserAgentMiddleware: ClientMiddleware {
@@ -146,7 +146,7 @@ internal class HTTPRequestExecutorImpl: HTTPRequestExecutor {
146146
return try response.ok.body.json
147147
}
148148

149-
public func getSnapshotToolchains(branch: Components.Schemas.KnownSourceBranch, platform: Components.Schemas.KnownPlatformIdentifier) async throws -> Components.Schemas.DevToolchains {
149+
public func getSnapshotToolchains(branch: Components.Schemas.SourceBranch, platform: Components.Schemas.PlatformIdentifier) async throws -> Components.Schemas.DevToolchains {
150150
let config = AsyncHTTPClientTransport.Configuration(client: self.httpClient, timeout: .seconds(30))
151151
let swiftlyUserAgent = SwiftlyUserAgentMiddleware()
152152

@@ -371,34 +371,30 @@ public struct SwiftlyHTTPClient {
371371
limit: Int? = nil,
372372
filter: ((ToolchainVersion.Snapshot) -> Bool)? = nil
373373
) async throws -> [ToolchainVersion.Snapshot] {
374-
let platformId: Components.Schemas.KnownPlatformIdentifier = switch platform.name {
375-
// case PlatformDefinition.ubuntu2404.name:
376-
// .ubuntu2404
377-
// case PlatformDefinition.debian12.name:
378-
// .debian12
379-
// case PlatformDefinition.fedora39.name:
380-
// .fedora39
374+
let platformId: Components.Schemas.PlatformIdentifier = switch platform.name {
375+
// These are new platforms that aren't yet in the list of known platforms in the OpenAPI schema
376+
case PlatformDefinition.ubuntu2404.name, PlatformDefinition.debian12.name, PlatformDefinition.fedora39.name:
377+
.init(value2: platform.name)
378+
381379
case PlatformDefinition.ubuntu2204.name:
382-
.ubuntu2204
380+
.init(value1: .ubuntu2204)
383381
case PlatformDefinition.ubuntu2004.name:
384-
.ubuntu2004
382+
.init(value1: .ubuntu2004)
385383
case PlatformDefinition.rhel9.name:
386-
.ubi9
384+
.init(value1: .ubi9)
387385
case PlatformDefinition.amazonlinux2.name:
388-
.amazonlinux2
386+
.init(value1: .amazonlinux2)
389387
case PlatformDefinition.macOS.name:
390-
.macos
388+
.init(value1: .macos)
391389
default:
392390
throw SwiftlyError(message: "No snapshot toolchains available for platform \(platform.name)")
393391
}
394392

395-
let sourceBranch: Components.Schemas.KnownSourceBranch = switch branch {
393+
let sourceBranch: Components.Schemas.SourceBranch = switch branch {
396394
case .main:
397-
.main
398-
case .release(major: 6, minor: 0):
399-
._6_0
400-
default:
401-
throw SwiftlyError(message: "Unknown snapshot branch: \(branch)")
395+
.init(value1: .main)
396+
case let .release(major, minor):
397+
.init(value2: "\(major).\(minor)")
402398
}
403399

404400
let devToolchains = try await SwiftlyCore.httpRequestExecutor.getSnapshotToolchains(branch: sourceBranch, platform: platformId)

Sources/SwiftlyCore/openapi.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ paths:
3737
in: path
3838
required: true
3939
schema:
40-
$ref: '#/components/schemas/KnownSourceBranch'
40+
$ref: '#/components/schemas/SourceBranch'
4141
- name: platform
4242
in: path
4343
required: true
4444
schema:
45-
$ref: '#/components/schemas/KnownPlatformIdentifier'
45+
$ref: '#/components/schemas/PlatformIdentifier'
4646
get:
4747
operationId: listDevToolchains
4848
summary: Fetch all development toolchains
@@ -61,7 +61,7 @@ paths:
6161
in: path
6262
required: true
6363
schema:
64-
$ref: '#/components/schemas/KnownSourceBranch'
64+
$ref: '#/components/schemas/SourceBranch'
6565
get:
6666
operationId: listStaticSDKDevToolchains
6767
summary: Fetch all static SDK development toolchains

Tests/SwiftlyTests/SwiftlyTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ private struct MockHTTPRequestExecutor: HTTPRequestExecutor {
472472
throw SwiftlyTestError(message: "Mocking of fetching the release toolchains is not implemented in MockHTTPRequestExecutor.")
473473
}
474474

475-
public func getSnapshotToolchains(branch _: Components.Schemas.KnownSourceBranch, platform _: Components.Schemas.KnownPlatformIdentifier) async throws -> Components.Schemas.DevToolchains {
475+
public func getSnapshotToolchains(branch _: Components.Schemas.SourceBranch, platform _: Components.Schemas.PlatformIdentifier) async throws -> Components.Schemas.DevToolchains {
476476
throw SwiftlyTestError(message: "Mocking of fetching the snapshot toolchains is not implemented in MockHTTPRequestExecutor.")
477477
}
478478
}
@@ -585,23 +585,23 @@ public class MockToolchainDownloader: HTTPRequestExecutor {
585585
}
586586
}
587587

588-
public func getSnapshotToolchains(branch: Components.Schemas.KnownSourceBranch, platform _: Components.Schemas.KnownPlatformIdentifier) async throws -> Components.Schemas.DevToolchains {
588+
public func getSnapshotToolchains(branch: Components.Schemas.SourceBranch, platform _: Components.Schemas.PlatformIdentifier) async throws -> Components.Schemas.DevToolchains {
589589
let currentPlatform = try await Swiftly.currentPlatform.detectPlatform(disableConfirmation: true, platform: nil)
590590

591591
let releasesForBranch = self.snapshotToolchains.filter { snapshotVersion in
592592
switch snapshotVersion.branch {
593593
case .main:
594-
branch == .main
594+
branch.value1 == .main || branch.value1?.rawValue == "main"
595595
case let .release(major, minor):
596-
major == 6 && minor == 0 && branch == ._6_0
596+
branch.value2 == "\(major).\(minor)" || branch.value1?.rawValue == "\(major).\(minor)"
597597
}
598598
}
599599

600600
let devToolchainsForArch = releasesForBranch.map { branchSnapshot in
601601
Components.Schemas.DevToolchainForArch(
602602
name: Components.Schemas.DevToolchainKind?.none,
603603
date: "",
604-
dir: branch == .main ?
604+
dir: branch.value1 == .main || branch.value2 == "main" ?
605605
"swift-DEVELOPMENT-SNAPSHOT-\(branchSnapshot.date)" :
606606
"swift-6.0-DEVELOPMENT-SNAPSHOT-\(branchSnapshot.date)",
607607
download: "",

0 commit comments

Comments
 (0)