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

install: Check all releases #21417

Merged
merged 1 commit into from
Nov 24, 2021
Merged
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
71 changes: 43 additions & 28 deletions install/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,39 +859,54 @@ fn check_for_newer_github_release(
version_filter: Option<semver::VersionReq>,
prerelease_allowed: bool,
) -> reqwest::Result<Option<String>> {
let url =
reqwest::Url::parse("https://api.github.com/repos/solana-labs/solana/releases").unwrap();
let mut page = 1;
const PER_PAGE: usize = 100;
let client = reqwest::blocking::Client::builder()
.user_agent("solana-install")
.build()?;
let request = client.get(url).build()?;
let response = client.execute(request)?;

let mut releases = response
.json::<GithubReleases>()?
.0
.into_iter()
.filter_map(
|GithubRelease {
tag_name,
prerelease,
}| {
if let Ok(version) = semver_of(&tag_name) {
if (prerelease_allowed || !prerelease)
&& version_filter
.as_ref()
.map_or(true, |version_filter| version_filter.matches(&version))
{
return Some(version);
}
}
None
},
let mut all_releases = vec![];
let mut releases = vec![];

while page == 1 || releases.len() == PER_PAGE {
let url = reqwest::Url::parse_with_params(
"https://api.github.com/repos/solana-labs/solana/releases",
&[
("per_page", &format!("{}", PER_PAGE)),
("page", &format!("{}", page)),
],
)
.collect::<Vec<_>>();
.unwrap();
let request = client.get(url).build()?;
let response = client.execute(request)?;

releases = response
.json::<GithubReleases>()?
.0
.into_iter()
.filter_map(
|GithubRelease {
tag_name,
prerelease,
}| {
if let Ok(version) = semver_of(&tag_name) {
if (prerelease_allowed || !prerelease)
&& version_filter
.as_ref()
.map_or(true, |version_filter| version_filter.matches(&version))
{
return Some(version);
}
}
None
},
)
.collect::<Vec<_>>();
all_releases.extend_from_slice(&releases);
page += 1;
}

releases.sort();
Ok(releases.pop().map(|r| r.to_string()))
all_releases.sort();
Ok(all_releases.pop().map(|r| r.to_string()))
}

pub enum SemverUpdateType {
Expand Down