Skip to content

Commit

Permalink
refactor: improve latest release filtering (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilrobot-01 authored Apr 12, 2024
1 parent baf4587 commit eb8687e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ tempfile = "3.8"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
url = { version = "2.5", optional = true }
walkdir = "2.4"
regex="1.5.4"
regex = "1.5.4"

# contracts
contract-build = { version = "4.0.2", optional = true }
Expand Down Expand Up @@ -70,6 +70,7 @@ parachain = [
"dep:dirs",
"dep:indexmap",
"dep:reqwest",
"dep:serde",
"dep:serde_json",
"dep:symlink",
"dep:toml_edit",
Expand Down
27 changes: 10 additions & 17 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ impl Git {

pub struct GitHub;
impl GitHub {
pub async fn get_latest_releases(number: usize, repo: &Url) -> Result<Vec<String>> {
#[cfg(feature = "parachain")]
pub async fn get_latest_releases(repo: &Url) -> Result<Vec<Release>> {
static APP_USER_AGENT: &str =
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"));

Expand All @@ -38,22 +39,7 @@ impl GitHub {
))
.send()
.await?;
let value = response.json::<serde_json::Value>().await?;

let mut latest_releases: Vec<String> = Vec::new();
for i in 0..number {
if value[i].get("tag_name").is_some() {
let tag_name = value[i]
.get("tag_name")
.and_then(|v| v.as_str())
.map(|v| v.to_owned())
.ok_or(anyhow!("the github release tag name was not found"))?;

latest_releases.push(tag_name);
}
}

Ok(latest_releases)
Ok(response.json::<Vec<Release>>().await?)
}

fn org(repo: &Url) -> Result<&str> {
Expand All @@ -80,3 +66,10 @@ impl GitHub {
format!("{}/releases/download/{tag}/{artifact}", repo.as_str())
}
}

#[cfg(feature = "parachain")]
#[derive(serde::Deserialize)]
pub struct Release {
pub(crate) tag_name: String,
pub(crate) prerelease: bool,
}
16 changes: 8 additions & 8 deletions src/parachains/zombienet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use zombienet_sdk::{Network, NetworkConfig, NetworkConfigExt};
use zombienet_support::fs::local::LocalFileSystem;

const POLKADOT_SDK: &str = "https://github.com/paritytech/polkadot-sdk";
const POLKADOT_DEFAULT_VERSION: &str = "v1.10.0";

pub struct Zombienet {
/// The cache location, used for caching binaries.
Expand Down Expand Up @@ -359,16 +360,15 @@ impl Zombienet {
}

async fn latest_polkadot_release() -> Result<String> {
const POLKADOT_DEFAULT_VERSION: &str = "v1.10.0";
debug!("relay chain version not specified - determining latest polkadot release...");
let repo = Url::parse(POLKADOT_SDK).expect("valid polkadot-sdk repository url");
// Fetching latest 5 releases, to find the polkadot one (ignoring parachain releases)
let release_tags = GitHub::get_latest_releases(5, &repo).await?;
for release_tag in release_tags {
if release_tag.starts_with("polkadot-v") {
return Ok(release_tag
let repo = Url::parse(POLKADOT_SDK).expect("repository url valid");
// Fetching latest releases
for release in GitHub::get_latest_releases(&repo).await? {
if !release.prerelease && release.tag_name.starts_with("polkadot-v") {
return Ok(release
.tag_name
.strip_prefix("polkadot-")
.map_or_else(|| release_tag.clone(), |v| v.to_string()));
.map_or_else(|| release.tag_name.clone(), |v| v.to_string()));
}
}
// It should never reach this point, but in case we download a default version of polkadot
Expand Down

0 comments on commit eb8687e

Please sign in to comment.