Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/MacOSPlatform/MacOS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public struct MacOS: Platform {

if ctx.mockedHomeDir == nil {
await ctx.message("Extracting the swiftly package...")
_ = sys.installer(
try await sys.installer(
.pkg(archive),
.target("CurrentUserHomeDirectory")
)
).run(self)
try? await sys.pkgutil(.volume(userHomeDir)).forget(pkg_id: "org.swift.swiftly").run(self)
} else {
let installDir = userHomeDir / ".swiftly"
Expand Down
32 changes: 25 additions & 7 deletions Sources/Swiftly/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@ import Foundation
import SwiftlyCore
import SystemPackage

public enum SwiftlyVersionMigration {
case exact(SwiftlyVersion)
case minor(SwiftlyVersion)

public func matches(_ version: SwiftlyVersion) -> Bool {
switch self {
case let .exact(v):
return version.major == v.major && version.minor == v.minor && version.patch == v.patch && version.suffix == v.suffix
case let .minor(v):
return version.major == v.major && version.minor == v.minor
}
}
}

public var migrations: [SwiftlyVersionMigration] {
[
.exact(.init(major: 0, minor: 4, patch: 0, suffix: "dev")),
.exact(.init(major: 0, minor: 4, patch: 0)),
.minor(.init(major: 1, minor: 0, patch: 0)),
.minor(.init(major: 1, minor: 1, patch: 0)),
.minor(.init(major: 1, minor: 2, patch: 0)),
]
}

struct Init: SwiftlyCommand {
public static let configuration = CommandConfiguration(
abstract: "Perform swiftly initialization into your user account."
Expand Down Expand Up @@ -44,13 +68,7 @@ struct Init: SwiftlyCommand {

var config = try? await Config.load(ctx)

if var config, !overwrite &&
(
config.version == SwiftlyVersion(major: 0, minor: 4, patch: 0, suffix: "dev") ||
config.version == SwiftlyVersion(major: 0, minor: 4, patch: 0) ||
(config.version.major == 1 && config.version.minor == 0)
)
{
if var config, !overwrite && !migrations.filter({ $0.matches(config.version) }).isEmpty {
// This is a simple upgrade from the 0.4.0 pre-releases, or 1.x

// Move our executable over to the correct place
Expand Down
3 changes: 2 additions & 1 deletion Sources/Swiftly/SelfUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ struct SelfUpdate: SwiftlyCommand {
fatalError("Unsupported OS")
#endif

guard version > SwiftlyCore.version else {
// Allow newer or identical versions to help self-update testing of a release
guard version >= SwiftlyCore.version else {
await ctx.print("Self-update does not support downgrading to an older version or re-installing the current version. Current version is \(SwiftlyCore.version) and requested version is \(version).")
return SwiftlyCore.version
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/SwiftlyTests/InitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import SystemPackage
import Testing

@Suite struct InitTests {
@Test func migrationsHasCurrentSwiftlyVersion() async throws {
// If the current swiftly version isn't in the migration list then it should be added there to
// support future self updates.
#expect(!migrations.filter { $0.matches(SwiftlyCore.version) }.isEmpty)
}

@Test(.testHome(), arguments: ["/bin/bash", "/bin/zsh", "/bin/fish"]) func initFresh(_ shell: String) async throws {
// GIVEN: a fresh user account without swiftly installed
try? await fs.remove(atPath: Swiftly.currentPlatform.swiftlyConfigFile(SwiftlyTests.ctx))
Expand Down