From 5ba40cf19f4b2f8ea97ec4c67b03885e54ae3e1c Mon Sep 17 00:00:00 2001 From: apoorvsadana <95699312+apoorvsadana@users.noreply.github.com> Date: Sun, 28 Jan 2024 19:48:22 +0530 Subject: [PATCH 1/4] automatically pull and update branch --- src/utils/constants.rs | 2 +- src/utils/github.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/utils/constants.rs b/src/utils/constants.rs index f3277ce..6440fbe 100644 --- a/src/utils/constants.rs +++ b/src/utils/constants.rs @@ -3,7 +3,7 @@ pub const MADARA_REPO_NAME: &str = "madara"; pub const KARNOT_REPO_ORG: &str = "karnotxyz"; -pub const BRANCH_NAME: &str = "custom_events_page"; +pub const BRANCH_NAME: &str = "cli_branch"; pub const APP_CONFIG_NAME: &str = "config.toml"; pub const APP_DA_CONFIG_NAME: &str = "da-config.json"; diff --git a/src/utils/github.rs b/src/utils/github.rs index cf32363..878d595 100644 --- a/src/utils/github.rs +++ b/src/utils/github.rs @@ -39,6 +39,22 @@ pub fn git_clone(url: &str, path: &PathBuf, branch: Option<&str>) -> Result<(), let remote = repo.find_remote("origin")?; if let Some(remote_url) = remote.url() { if remote_url == url { + if let Some(branch) = branch { + let x = Command::new("git") + .arg("fetch") + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .current_dir(path) + .output()?; + Command::new("git") + .arg("checkout") + .arg(branch) + .current_dir(path) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .output()?; + Command::new("git").arg("pull").stdout(Stdio::inherit()).stderr(Stdio::inherit()).output()?; + } return Ok(()); } } From a62c0a70e9d816664622ac2174b75c636a9319f1 Mon Sep 17 00:00:00 2001 From: apoorvsadana <95699312+apoorvsadana@users.noreply.github.com> Date: Sun, 28 Jan 2024 20:51:01 +0530 Subject: [PATCH 2/4] automatically update to new git branch --- src/cli/init.rs | 4 ++-- src/cli/run.rs | 2 +- src/utils/constants.rs | 5 ++--- src/utils/github.rs | 17 +++++++---------- src/utils/madara.rs | 14 ++++++++++---- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/cli/init.rs b/src/cli/init.rs index 653741f..0291a0f 100644 --- a/src/cli/init.rs +++ b/src/cli/init.rs @@ -7,7 +7,7 @@ use thiserror::Error; use super::prompt::{get_option, get_text_input}; use crate::app::config::{AppChainConfig, ConfigVersion, RollupMode}; use crate::da::da_layers::{DAFactory, DALayer}; -use crate::utils::constants::{APP_CONFIG_NAME, MADARA_REPO_NAME, MADARA_REPO_ORG}; +use crate::utils::constants::{APP_CONFIG_NAME, MADARA_BRANCH_NAME, MADARA_REPO_NAME, MADARA_REPO_ORG}; use crate::utils::errors::GithubError; use crate::utils::github::get_latest_commit_hash; use crate::utils::paths::{get_app_chains_home, get_app_home}; @@ -53,7 +53,7 @@ async fn generate_config() -> Result { let mode = get_option("Select mode for your app chain:", RollupMode::iter().collect::>())?; let da_layer = get_option("Select DA layer for your app chain:", DALayer::iter().collect::>())?; - let madara_version = get_latest_commit_hash(MADARA_REPO_ORG, MADARA_REPO_NAME).await?; + let madara_version = get_latest_commit_hash(MADARA_REPO_ORG, MADARA_REPO_NAME, MADARA_BRANCH_NAME).await?; let config_version = ConfigVersion::Version1; log::info!("\n"); diff --git a/src/cli/run.rs b/src/cli/run.rs index 1d8a077..4afb895 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -48,7 +48,7 @@ async fn start_app_chain() -> Result<(), RunError> { } }; - madara::clone_madara_and_build_repo()?; + madara::clone_madara_and_build_repo(&config)?; let da_factory = DAFactory::new_da(&config.da_layer); da_factory.confirm_minimum_balance(&config)?; diff --git a/src/utils/constants.rs b/src/utils/constants.rs index 6440fbe..86eafd9 100644 --- a/src/utils/constants.rs +++ b/src/utils/constants.rs @@ -1,9 +1,8 @@ -pub const MADARA_REPO_ORG: &str = "keep-starknet-strange"; pub const MADARA_REPO_NAME: &str = "madara"; -pub const KARNOT_REPO_ORG: &str = "karnotxyz"; +pub const MADARA_REPO_ORG: &str = "karnotxyz"; -pub const BRANCH_NAME: &str = "cli_branch"; +pub const MADARA_BRANCH_NAME: &str = "cli_branch"; pub const APP_CONFIG_NAME: &str = "config.toml"; pub const APP_DA_CONFIG_NAME: &str = "da-config.json"; diff --git a/src/utils/github.rs b/src/utils/github.rs index 878d595..2de2e87 100644 --- a/src/utils/github.rs +++ b/src/utils/github.rs @@ -14,18 +14,15 @@ struct Commit { sha: String, } -pub async fn get_latest_commit_hash(org: &str, repo: &str) -> Result { - let github_api_url = format!("{}/repos/{}/{}/commits", GITHUB_API_BASE_URL, org, repo); +pub async fn get_latest_commit_hash(org: &str, repo: &str, branch: &str) -> Result { + let github_api_url = format!("{}/repos/{}/{}/commits/{}", GITHUB_API_BASE_URL, org, repo, branch); let client = Client::new(); let response = client.get(github_api_url).header("User-Agent", "reqwest").send().await; return match response { - Ok(response) => match response.json::>().await { - Ok(commits) => match commits.first() { - Some(latest_commit) => Ok(latest_commit.sha.clone()), - None => Err(GithubError::NoCommitsFound), - }, + Ok(response) => match response.json::().await { + Ok(latest_commit) => Ok(latest_commit.sha.clone()), Err(err) => Err(GithubError::FailedToGetCommits(err)), }, Err(err) => Err(GithubError::FailedToGetCommits(err)), @@ -40,7 +37,7 @@ pub fn git_clone(url: &str, path: &PathBuf, branch: Option<&str>) -> Result<(), if let Some(remote_url) = remote.url() { if remote_url == url { if let Some(branch) = branch { - let x = Command::new("git") + Command::new("git") .arg("fetch") .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) @@ -50,8 +47,8 @@ pub fn git_clone(url: &str, path: &PathBuf, branch: Option<&str>) -> Result<(), .arg("checkout") .arg(branch) .current_dir(path) - .stdout(Stdio::inherit()) - .stderr(Stdio::inherit()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) .output()?; Command::new("git").arg("pull").stdout(Stdio::inherit()).stderr(Stdio::inherit()).output()?; } diff --git a/src/utils/madara.rs b/src/utils/madara.rs index 8e28bb0..3102609 100644 --- a/src/utils/madara.rs +++ b/src/utils/madara.rs @@ -1,18 +1,24 @@ use crate::app::config::AppChainConfig; use crate::da::da_layers::DALayer; use crate::utils::cmd::execute_cmd; -use crate::utils::constants::{APP_DA_CONFIG_NAME, BRANCH_NAME, KARNOT_REPO_ORG, MADARA_REPO_NAME}; +use crate::utils::constants::{APP_DA_CONFIG_NAME, MADARA_BRANCH_NAME, MADARA_REPO_NAME, MADARA_REPO_ORG}; use crate::utils::errors::MadaraError; use crate::utils::github::git_clone; use crate::utils::paths::{get_app_home, get_madara_home}; pub const GITHUB_BASE_URL: &str = "https://github.com"; -pub fn clone_madara_and_build_repo() -> Result<(), MadaraError> { - let repo_url = format!("{}/{}/{}", GITHUB_BASE_URL, KARNOT_REPO_ORG, MADARA_REPO_NAME); +pub fn clone_madara_and_build_repo(config: &AppChainConfig) -> Result<(), MadaraError> { + let repo_url = format!("{}/{}/{}", GITHUB_BASE_URL, MADARA_REPO_ORG, MADARA_REPO_NAME); let madara_path = get_madara_home()?.join("madara"); - match git_clone(&repo_url, &madara_path, Some(BRANCH_NAME)) { + let madara_version = match config.madara_version.as_str() { + // there was a bug initially where the wrong commit version was being set + // in the config + "523ceedc8afe7a4f58abfdbb915aff3c36e817fe" => "5de416aeb2d9e4297e58f7f2dff99aeae521855e", + _ => config.madara_version.as_str(), + }; + match git_clone(&repo_url, &madara_path, Some(madara_version)) { Ok(_) => { log::info!("Successfully cloned Madara repo"); } From 99ed71e17627897253d6805e7339d0ab3e822391 Mon Sep 17 00:00:00 2001 From: apoorvsadana <95699312+apoorvsadana@users.noreply.github.com> Date: Sun, 28 Jan 2024 20:53:24 +0530 Subject: [PATCH 3/4] clippy fix --- src/utils/github.rs | 4 ++-- src/utils/madara.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/github.rs b/src/utils/github.rs index 2de2e87..92623f8 100644 --- a/src/utils/github.rs +++ b/src/utils/github.rs @@ -20,13 +20,13 @@ pub async fn get_latest_commit_hash(org: &str, repo: &str, branch: &str) -> Resu let client = Client::new(); let response = client.get(github_api_url).header("User-Agent", "reqwest").send().await; - return match response { + match response { Ok(response) => match response.json::().await { Ok(latest_commit) => Ok(latest_commit.sha.clone()), Err(err) => Err(GithubError::FailedToGetCommits(err)), }, Err(err) => Err(GithubError::FailedToGetCommits(err)), - }; + } } pub fn git_clone(url: &str, path: &PathBuf, branch: Option<&str>) -> Result<(), GithubError> { diff --git a/src/utils/madara.rs b/src/utils/madara.rs index 3102609..4c1cb7f 100644 --- a/src/utils/madara.rs +++ b/src/utils/madara.rs @@ -1,7 +1,7 @@ use crate::app::config::AppChainConfig; use crate::da::da_layers::DALayer; use crate::utils::cmd::execute_cmd; -use crate::utils::constants::{APP_DA_CONFIG_NAME, MADARA_BRANCH_NAME, MADARA_REPO_NAME, MADARA_REPO_ORG}; +use crate::utils::constants::{APP_DA_CONFIG_NAME, MADARA_REPO_NAME, MADARA_REPO_ORG}; use crate::utils::errors::MadaraError; use crate::utils::github::git_clone; use crate::utils::paths::{get_app_home, get_madara_home}; From f51749ac6d2ecbc673fea5ff97594bdf513ae77c Mon Sep 17 00:00:00 2001 From: apoorvsadana <95699312+apoorvsadana@users.noreply.github.com> Date: Mon, 29 Jan 2024 02:19:23 +0530 Subject: [PATCH 4/4] add new override commit --- src/utils/madara.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/utils/madara.rs b/src/utils/madara.rs index 4c1cb7f..3b16663 100644 --- a/src/utils/madara.rs +++ b/src/utils/madara.rs @@ -15,7 +15,9 @@ pub fn clone_madara_and_build_repo(config: &AppChainConfig) -> Result<(), Madara let madara_version = match config.madara_version.as_str() { // there was a bug initially where the wrong commit version was being set // in the config - "523ceedc8afe7a4f58abfdbb915aff3c36e817fe" => "5de416aeb2d9e4297e58f7f2dff99aeae521855e", + "523ceedc8afe7a4f58abfdbb915aff3c36e817fe" | "8b49fecfe6f420a1dede1e691d50cd59a326bbc0" => { + "5de416aeb2d9e4297e58f7f2dff99aeae521855e" + } _ => config.madara_version.as_str(), }; match git_clone(&repo_url, &madara_path, Some(madara_version)) {