Skip to content
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

Implement self-update command #81

Merged
merged 7 commits into from Dec 1, 2023

Conversation

patrickfreed
Copy link
Collaborator

@patrickfreed patrickfreed commented Nov 15, 2023

Implements a self-update command, which can be used to update swiftly in-place.

This also expands the toolchain downloading mocking framework introduced in #67 to be able to be used for any arbitrary HTTP request. This allows us to use mocking to simulate there being a swiftly update to make, even though there are none currently.

For the 0.2.0 release, users will need to install via swiftly-install.sh, but every release afterwards they can do it via a simple swiftly self-update.

need to unify download, add tests
todo:
  - update existing usages of mock HTTP downloader
  - finish self update tests
@patrickfreed patrickfreed marked this pull request as ready for review November 15, 2023 04:32
Copy link
Member

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general looks good. Adding a few comments

}
}

private func makeRequest(url: String) -> HTTPClientRequest {
var request = HTTPClientRequest(url: url)
request.headers.add(name: "User-Agent", value: "swiftly")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should include the swiftly version here as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private struct Response {
let status: HTTPResponseStatus
let buffer: ByteBuffer
}

private let downloader: ToolchainDownloader
private let inner: HTTPRequestExecutor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to executor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// As a heuristic for if we've hit the 404 page, we check to see if the content is HTML.
if url.host == "download.swift.org" {
guard !response.headers["Content-Type"].contains(where: { $0.contains("text/html") }) else {
throw SwiftlyHTTPClient.DownloadNotFoundError(url: url.path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to ask can't you check the response status, but apparently not. The 404 page returns a status of 302. You could check the location header is https://swift.org/404.html instead though

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So after following the redirect, swift.org/404.html does in fact return a status code of 404 nowadays, so I've just gone ahead and removed this special check altogether.

@patrickfreed patrickfreed merged commit 2e35b41 into swift-server:main Dec 1, 2023
6 checks passed
@patrickfreed patrickfreed added this to the 0.2.0 milestone Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants