Skip to content

Commit 09e12af

Browse files
Make "swift-" prefix optional in MainSnapshotParser (#240)
* Make "swift-" prefix optional in MainSnapshotParser Existing tools like `swiftenv` use `DEVELOPMENT-SNAPSHOT-YYYY-mm-dd-a` for main snapshots, without the `swift-` prefix. The `MainSnapshotParser` should be able to handle this and this change mirrors the `ReleaseSnapshotParser` in this regard, which already supports both `swift-` prefixed and unprefixed versions. * Expand the selector examples to include the "swift-" prefixed versions
1 parent 7b773c7 commit 09e12af

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

Sources/SwiftlyCore/ToolchainVersion.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,21 @@ struct StableReleaseParser: ToolchainSelectorParser {
383383
}
384384
}
385385

386-
/// Parser for selectors like the following (with optional "swift-" prefix):
386+
/// Parser for selectors like the following:
387387
/// - a.b-snapshot-YYYY-mm-dd
388388
/// - a.b-snapshot
389+
/// - a.b-SNAPSHOT-YYYY-mm-dd
390+
/// - a.b-SNAPSHOT
389391
/// - a.b-DEVELOPMENT-SNAPSHOT-YYYY-mm-dd-a
390392
/// - a.b-DEVELOPMENT-SNAPSHOT-YYYY-mm-dd
391393
/// - a.b-DEVELOPMENT-SNAPSHOT
392-
/// - a.b-SNAPSHOT-YYYY-mm-dd
393-
/// - a.b-SNAPSHOT
394+
/// - swift-a.b-snapshot-YYYY-mm-dd
395+
/// - swift-a.b-snapshot
396+
/// - swift-a.b-SNAPSHOT-YYYY-mm-dd
397+
/// - swift-a.b-SNAPSHOT
398+
/// - swift-a.b-DEVELOPMENT-SNAPSHOT-YYYY-mm-dd-a
399+
/// - swift-a.b-DEVELOPMENT-SNAPSHOT-YYYY-mm-dd
400+
/// - swift-a.b-DEVELOPMENT-SNAPSHOT
394401
struct ReleaseSnapshotParser: ToolchainSelectorParser {
395402
static let regex: Regex<(Substring, Substring, Substring, Substring?)> =
396403
try! Regex("^(?:swift-)?([0-9]+)\\.([0-9]+)-(?:snapshot|DEVELOPMENT-SNAPSHOT|SNAPSHOT)(?:-([0-9]{4}-[0-9]{2}-[0-9]{2}))?(?:-a)?$")
@@ -416,12 +423,19 @@ struct ReleaseSnapshotParser: ToolchainSelectorParser {
416423
/// - main-snapshot
417424
/// - main-SNAPSHOT-YYYY-mm-dd
418425
/// - main-SNAPSHOT
426+
/// - DEVELOPMENT-SNAPSHOT-YYYY-mm-dd-a
427+
/// - DEVELOPMENT-SNAPSHOT-YYYY-mm-dd
428+
/// - DEVELOPMENT-SNAPSHOT
429+
/// - swift-main-snapshot-YYYY-mm-dd
430+
/// - swift-main-snapshot
431+
/// - swift-main-SNAPSHOT-YYYY-mm-dd
432+
/// - swift-main-SNAPSHOT
419433
/// - swift-DEVELOPMENT-SNAPSHOT-YYYY-mm-dd-a
420434
/// - swift-DEVELOPMENT-SNAPSHOT-YYYY-mm-dd
421435
/// - swift-DEVELOPMENT-SNAPSHOT
422436
struct MainSnapshotParser: ToolchainSelectorParser {
423437
static let regex: Regex<(Substring, Substring?)> =
424-
try! Regex("^(?:main-snapshot|swift-DEVELOPMENT-SNAPSHOT|main-SNAPSHOT)(?:-([0-9]{4}-[0-9]{2}-[0-9]{2}))?(?:-a)?$")
438+
try! Regex("^(?:swift-)?(?:main-snapshot|DEVELOPMENT-SNAPSHOT|main-SNAPSHOT)(?:-([0-9]{4}-[0-9]{2}-[0-9]{2}))?(?:-a)?$")
425439

426440
func parse(_ input: String) throws -> ToolchainSelector? {
427441
guard let match = try Self.regex.wholeMatch(in: input) else {

Tests/SwiftlyTests/ToolchainSelectorTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ final class ToolchainSelectorTests: SwiftlyTests {
3434
"main-SNAPSHOT-2023-06-05",
3535
"swift-DEVELOPMENT-SNAPSHOT-2023-06-05",
3636
"swift-DEVELOPMENT-SNAPSHOT-2023-06-05-a",
37+
"DEVELOPMENT-SNAPSHOT-2023-06-05-a",
3738
]
3839
try runTest(.snapshot(branch: .main, date: "2023-06-05"), parses)
3940
}

0 commit comments

Comments
 (0)