From 86fdec4ffa068736e4e1ac6cd04eee31479cac32 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 6 Sep 2024 15:45:07 +0200 Subject: [PATCH 1/2] Tweak CI Signed-off-by: Oliver Tale-Yazdi --- .github/workflows/rust.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4cc3bdc..7045850 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,5 +1,9 @@ name: Rust +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + on: push: branches: [ "main" ] @@ -34,3 +38,6 @@ jobs: psvm -v stable2407-2 psvm -v 1.13.0 psvm -l + + - name: Fmt + run: cargo fmt --all -- --check From c0b8c78785ee37d5cf925a806c4e94acc34c60c9 Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Fri, 6 Sep 2024 15:45:56 +0200 Subject: [PATCH 2/2] Format code Signed-off-by: Oliver Tale-Yazdi --- src/main.rs | 4 +-- src/tests.rs | 4 +-- src/versions.rs | 74 +++++++++++++++++++++++++------------------------ 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/src/main.rs b/src/main.rs index cc8a2bf..0878e2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -99,9 +99,7 @@ async fn main() -> Result<(), Box> { Ok(()) } -fn validate_workspace_path( - mut path: PathBuf, -) -> Result> { +fn validate_workspace_path(mut path: PathBuf) -> Result> { if path.is_dir() { path = path.join("Cargo.toml"); } diff --git a/src/tests.rs b/src/tests.rs index 94f9605..82cf23f 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -291,9 +291,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" // To run this test, ensure you have installed the GitHub CLI and are authenticated // cause it will fetch the latest release branches from the GitHub API async fn works_for_all_versions() { - let release_versions = crate::versions::get_polkadot_sdk_versions() - .await - .unwrap(); + let release_versions = crate::versions::get_polkadot_sdk_versions().await.unwrap(); for version in release_versions { let crates_versions = diff --git a/src/versions.rs b/src/versions.rs index 0511757..c9c2280 100644 --- a/src/versions.rs +++ b/src/versions.rs @@ -13,9 +13,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +use regex::Regex; use serde::Deserialize; use std::collections::{BTreeMap, HashSet}; -use regex::Regex; /// Represents the structure of a Cargo.lock file, including all packages. #[derive(Debug, Deserialize)] @@ -94,14 +94,15 @@ pub struct TagInfo { pub name: String, } -const POLKADOT_SDK_TAGS_URL: &str = "https://api.github.com/repos/paritytech/polkadot-sdk/tags?per_page=100&page="; +const POLKADOT_SDK_TAGS_URL: &str = + "https://api.github.com/repos/paritytech/polkadot-sdk/tags?per_page=100&page="; const POLKADOT_SDK_TAGS_GH_CMD_URL: &str = "/repos/paritytech/polkadot-sdk/tags?per_page=100&page="; const POLKADOT_SDK_STABLE_TAGS_REGEX: &str = r"^polkadot-stable\d+(-\d+)?$"; /// Fetches a combined list of Polkadot SDK release versions and stable tag releases. /// -/// This function first retrieves release branch versions from the Polkadot SDK and -/// then fetches stable tag releases versions. It combines these two lists into a +/// This function first retrieves release branch versions from the Polkadot SDK and +/// then fetches stable tag releases versions. It combines these two lists into a /// single list of version strings. /// /// # Returns @@ -134,46 +135,46 @@ pub async fn get_polkadot_sdk_versions() -> Result, Box` fails. pub async fn get_stable_tag_versions() -> Result, Box> { let mut release_tags = vec![]; - + for page in 1..100 { let response = reqwest::Client::new() - .get(format!("{}{}", POLKADOT_SDK_TAGS_URL, page)) - .header("User-Agent", "reqwest") - .header("Accept", "application/vnd.github.v3+json") - .send() - .await?; - + .get(format!("{}{}", POLKADOT_SDK_TAGS_URL, page)) + .header("User-Agent", "reqwest") + .header("Accept", "application/vnd.github.v3+json") + .send() + .await?; + let output = if response.status().is_success() { response.text().await? } else { // query the github api using gh command String::from_utf8( std::process::Command::new("gh") - .args([ - "api", - "-H", - "Accept: application/vnd.github+json", - "-H", - "X-GitHub-Api-Version: 2022-11-28", - &format!("{}{}", POLKADOT_SDK_TAGS_GH_CMD_URL, page), + .args([ + "api", + "-H", + "Accept: application/vnd.github+json", + "-H", + "X-GitHub-Api-Version: 2022-11-28", + &format!("{}{}", POLKADOT_SDK_TAGS_GH_CMD_URL, page), ]) .output()? .stdout, - )? - }; - + )? + }; + let tag_branches: Vec = serde_json::from_str(&output)?; let tag_regex = Regex::new(POLKADOT_SDK_STABLE_TAGS_REGEX).unwrap(); - + let stable_tag_branches = tag_branches .iter() .filter(|b| tag_regex.is_match(&b.name)) .map(|branch| branch.name.to_string()); - release_tags = release_tags - .into_iter() - .chain(stable_tag_branches) - .collect(); + release_tags = release_tags + .into_iter() + .chain(stable_tag_branches) + .collect(); if tag_branches.len() < 100 { break; @@ -187,7 +188,7 @@ pub async fn get_stable_tag_versions() -> Result, Box` that may contain the ORML crates and their /// versions. @@ -280,7 +281,7 @@ pub fn include_orml_crates_in_version_mapping( if let Some(orml_toml) = orml_crates_version { for crate_name in orml_toml.workspace.members { crates_versions.insert( - format!("orml-{}",crate_name), + format!("orml-{}", crate_name), orml_toml.workspace.metadata.orml.crates_version.clone(), ); } @@ -295,7 +296,7 @@ pub async fn get_version_mapping_with_fallback( match result { Err(_) => get_version_mapping(base_url, version, "Cargo.lock").await, - Ok(_) => result + Ok(_) => result, } } @@ -466,11 +467,11 @@ fn get_repository_info(repository: &Repository) -> RepositoryInfo { /// let orml_repository = Repository::Orml; /// let orml_versions = get_release_branches_versions(orml_repository).await?; /// println!("Orml Release versions: {:?}", orml_versions); -/// +/// /// let psdk_repository = Repository::Psdk; /// let psdk_versions = get_release_branches_versions(psdk_repository).await?; /// println!("Polkadot-sdk Release versions: {:?}", psdk_versions); -/// +/// /// Ok(()) /// } /// ``` @@ -515,7 +516,8 @@ pub async fn get_release_branches_versions( .filter(|b| b.name.starts_with(&repository_info.version_filter_string)) .filter(|b| (b.name != "polkadot-v1.0.0")) // This is in place to filter that particular orml version as it is not a valid polkadot-sdk release version .map(|branch| { - branch.name + branch + .name .replace(&repository_info.version_replace_string, "") });