Add version check and prompt for self update
- 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.
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
It looks like the big URL -> FilePath created conflicts on this PR.
Hi @cmcgee1024 I just merged main into this branch, lmk if you need anything else!
@swift-ci test macOS
@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?
@louisunlimited you can fix the formatting error by running swift run swiftformat . and then commit the formatting fixes.
@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?
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 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.
@swift-ci test macOS
@swift-ci test macOS
Thanks for your contribution @louisunlimited