-
Notifications
You must be signed in to change notification settings - Fork 55
Add version check and prompt for self update #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cmcgee1024
merged 20 commits into
swiftlang:main
from
louisunlimited:louis/update-check
Apr 29, 2025
Merged
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8e699e4
feat: add version check and defer print till end of func
louisunlimited d98bf7f
feat: move version check inside `validateSwiftly`
louisunlimited 1d4116d
fix: discard update handler for `self-update`
louisunlimited 1eebdd9
feat: print update msg to stderr
louisunlimited 134eded
chore: rename variable
louisunlimited 2dcf5c4
Merge branch 'main' into louis/update-check
louisunlimited e5dbd79
fix: await async Config.load() op
louisunlimited 6c1422f
chore: add period
louisunlimited 21946a0
fix: non faliure version checking with `try?`
louisunlimited ee55f0b
chore: lint
louisunlimited ca71645
fix: build errors
louisunlimited bae69c5
fix(ListTests): mocked Swiftly Version
louisunlimited fe66b75
test(Platform): mock swiftly verison
louisunlimited 80074ef
test(Run): mock swiftly verison
louisunlimited 83a6bc9
test(Uninstall): mock swiftly verison
louisunlimited 1787f10
test(Use): mock swiftly verison
louisunlimited f01d1f2
feat: add MockSwiftlyVersion Test Trait
louisunlimited e467ab5
chore: lint
louisunlimited 4451417
chore: clean up SwiftlyTests.swift & use SwiftlyCore.version.major
louisunlimited 09be749
chore: use SwiftlyCore.version.major for ListTests
louisunlimited File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,7 +93,7 @@ extension Data { | |
} | ||
|
||
extension SwiftlyCommand { | ||
public mutating func validateSwiftly(_ ctx: SwiftlyCoreContext) async throws { | ||
public mutating func validateSwiftly(_ ctx: SwiftlyCoreContext) async throws -> () -> Void { | ||
for requiredDir in Swiftly.requiredDirectories(ctx) { | ||
guard try await fs.exists(atPath: requiredDir) else { | ||
do { | ||
|
@@ -107,5 +107,23 @@ extension SwiftlyCommand { | |
|
||
// Verify that the configuration exists and can be loaded | ||
_ = try await Config.load(ctx) | ||
|
||
let swiftlyRelease = try await ctx.httpClient.getCurrentSwiftlyRelease() | ||
let shouldUpdateSwiftly = try swiftlyRelease.swiftlyVersion > SwiftlyCore.version | ||
|
||
return { | ||
if shouldUpdateSwiftly { | ||
let updateMessage = """ | ||
----------------------------- | ||
A new release of swiftly is available | ||
|
||
Please run `swiftly self-update` to update. | ||
-----------------------------\n | ||
""" | ||
|
||
if let data = updateMessage.data(using: .utf8) { | ||
FileHandle.standardError.write(data) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue(blocking): This will throw an error if there's some kind of an HTTP connection problem fetching the current swiftly release. That shouldn't abort the principal operation, such as use/install/etc.
suggestion: Change this to
try? await
so that the release is optional. Only if the release can be found and it is larger than the current version would trigger the message.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, done.