swiftly icon indicating copy to clipboard operation
swiftly copied to clipboard

Add version check and prompt for self update

Open louisunlimited opened this issue 8 months ago • 7 comments

  • Fixes #233

Manually added checks at the start of each command (apart from self-update and init) to check for version mismatches, if found, it will try to prompt the user with:

"A new release of swiftly is available"
"Please run `swiftly self-update` to update."

It also tries to prompt the user at the very last stage of the command, ensuring the update prompt will always show at the end to avoid being buried.

louisunlimited avatar Apr 09 '25 07:04 louisunlimited

I'm thinking about possibly refactoring this in some way to make things coherent, maybe all as a method under SwiftlyCommand like the existing: https://github.com/swiftlang/swiftly/blob/2cedc32495c1e80faf84321ff2d1a4c6b3b82d30/Sources/Swiftly/Swiftly.swift#L83

louisunlimited avatar Apr 09 '25 07:04 louisunlimited

It looks like the big URL -> FilePath created conflicts on this PR.

cmcgee1024 avatar Apr 23 '25 14:04 cmcgee1024

Hi @cmcgee1024 I just merged main into this branch, lmk if you need anything else!

louisunlimited avatar Apr 25 '25 04:04 louisunlimited

@swift-ci test macOS

cmcgee1024 avatar Apr 25 '25 12:04 cmcgee1024

@louisunlimited I suspect that the tests are failing because mocked http executor is producing fatal errors due to this attempt to make a network request. The idea is to keep the vast majority of tests from making real network requests so that they can run quickly and are immune to changes on swift.org that make them brittle.

Perhaps this could produce a mocked swiftly version instead, based on the current version in SwiftlyVersion?

cmcgee1024 avatar Apr 25 '25 12:04 cmcgee1024

@louisunlimited you can fix the formatting error by running swift run swiftformat . and then commit the formatting fixes.

cmcgee1024 avatar Apr 25 '25 12:04 cmcgee1024

@louisunlimited I suspect that the tests are failing because mocked http executor is producing fatal errors due to this attempt to make a network request. The idea is to keep the vast majority of tests from making real network requests so that they can run quickly and are immune to changes on swift.org that make them brittle.

Perhaps this could produce a mocked swiftly version instead, based on the current version in SwiftlyVersion?

Yeah I was going through tests locally and I see that by wrapping tests inside something like

try await SwiftlyTests.withMockedSwiftlyVersion(latestSwiftlyVersion: SwiftlyVersion(major: SwiftlyCore.version.major, minor: 0, patch: 0)) {
    ...
}

would fix it. I could just wrap this around all the tests (or the helper func they call), but was thinking if there are better ways. Any suggestions?

louisunlimited avatar Apr 26 '25 05:04 louisunlimited

would fix it. I could just wrap this around all the tests (or the helper func they call), but was thinking if there are better ways. Any suggestions?

I think that's pretty consistent with what's being done in other cases in the test suite, so that seems fine to me.

cmcgee1024 avatar Apr 28 '25 17:04 cmcgee1024

@cmcgee1024 Just updated the tests! Lmk what you think, and also if it's necessary to add a "shouldPromptVersionUpate" test for each of the commands. End up with using Traits instead of wrapping them because there seems to be some ordering issues with how ctx is being passed around. All test are passing locally.

louisunlimited avatar Apr 28 '25 20:04 louisunlimited

@swift-ci test macOS

cmcgee1024 avatar Apr 29 '25 13:04 cmcgee1024

@swift-ci test macOS

cmcgee1024 avatar Apr 29 '25 13:04 cmcgee1024

Thanks for your contribution @louisunlimited

cmcgee1024 avatar Apr 29 '25 14:04 cmcgee1024