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

feat(up parachain): improve build ux #123

Merged
merged 6 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ duct = "0.13"
git2 = "0.18"
tempfile = "3.8"
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
url = { version = "2.5"}
url = { version = "2.5" }

# contracts
subxt-signer = { version = "0.34.0", features = ["subxt", "sr25519"]}
subxt-signer = { version = "0.34.0", features = ["subxt", "sr25519"] }
subxt = { version = "0.34.0" }
ink_env = { version = "5.0.0-rc.2" }
sp-core = { version = "30.0.0"}
sp-core = { version = "30.0.0" }
sp-weights = { version = "29.0.0" }
contract-build = { version = "4.0.2" }
contract-extrinsics = { version = "4.0.0-rc.3"}
contract-extrinsics = { version = "4.0.0-rc.3" }

# parachains
askama = "0.12"
regex="1.5.4"
regex = "1.5.4"
walkdir = "2.4"
indexmap = { version = "2.2"}
indexmap = { version = "2.2" }
toml_edit = { version = "0.22", features = ["serde"] }
symlink = { version = "0.1" }
reqwest = { version = "0.11" }
serde_json = { version = "1.0"}
serde_json = { version = "1.0" }
serde = { version = "1.0", features = ["derive"] }
zombienet-sdk = { git = "https://github.com/r0gue-io/zombienet-sdk", branch = "pop", version = "0.1.0-alpha.1"}
zombienet-sdk = { git = "https://github.com/r0gue-io/zombienet-sdk", branch = "pop", version = "0.1.0-alpha.1" }
zombienet-support = { git = "https://github.com/r0gue-io/zombienet-sdk", branch = "pop", version = "0.1.0-alpha.1" }
git2_credentials = "0.13.0"

# pop-cli
clap = { version = "4.4", features = ["derive"] }
cliclack = "0.1"
cliclack = "0.2"
console = "0.15"
strum = "0.26"
strum_macros = "0.26"
6 changes: 3 additions & 3 deletions crates/pop-cli/src/commands/call/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl CallContractCommand {
.await?;

if !self.execute {
let mut spinner = cliclack::spinner();
let spinner = cliclack::spinner();
spinner.start("Calling the contract...");
let call_dry_run_result = dry_run_call(&call_exec).await?;
log::info(format!("Result: {}", call_dry_run_result))?;
Expand All @@ -89,7 +89,7 @@ impl CallContractCommand {
weight_limit =
Weight::from_parts(self.gas_limit.unwrap(), self.proof_size.unwrap());
} else {
let mut spinner = cliclack::spinner();
let spinner = cliclack::spinner();
spinner.start("Doing a dry run to estimate the gas...");
weight_limit = match dry_run_gas_estimate_call(&call_exec).await {
Ok(w) => {
Expand All @@ -103,7 +103,7 @@ impl CallContractCommand {
},
};
}
let mut spinner = cliclack::spinner();
let spinner = cliclack::spinner();
spinner.start("Calling the contract...");

let call_result = call_smart_contract(call_exec, weight_limit, &self.url)
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-cli/src/commands/new/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl NewContractCommand {
fs::remove_dir_all(contract_path.as_path())?;
}
fs::create_dir_all(contract_path.as_path())?;
let mut spinner = cliclack::spinner();
let spinner = cliclack::spinner();
spinner.start("Generating contract...");
create_smart_contract(&self.name, contract_path.as_path())?;
spinner.stop("Smart contract created!");
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-cli/src/commands/new/pallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl NewPalletCommand {
}
fs::remove_dir_all(pallet_path)?;
}
let mut spinner = cliclack::spinner();
let spinner = cliclack::spinner();
spinner.start("Generating pallet...");
create_pallet_template(
self.path.clone(),
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-cli/src/commands/new/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn generate_parachain_from_template(
))?;
let destination_path = check_destination_path(name_template)?;

let mut spinner = cliclack::spinner();
let spinner = cliclack::spinner();
spinner.start("Generating parachain...");
let tag = instantiate_template_dir(template, destination_path, tag_version, config)?;
if let Err(err) = Git::git_init(destination_path, "initialized parachain") {
Expand Down
4 changes: 2 additions & 2 deletions crates/pop-cli/src/commands/up/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl UpContractCommand {
if self.gas_limit.is_some() && self.proof_size.is_some() {
weight_limit = Weight::from_parts(self.gas_limit.unwrap(), self.proof_size.unwrap());
} else {
let mut spinner = cliclack::spinner();
let spinner = cliclack::spinner();
spinner.start("Doing a dry run to estimate the gas...");
weight_limit = match dry_run_gas_estimate_instantiate(&instantiate_exec).await {
Ok(w) => {
Expand All @@ -86,7 +86,7 @@ impl UpContractCommand {
},
};
}
let mut spinner = cliclack::spinner();
let spinner = cliclack::spinner();
spinner.start("Uploading and instantiating the contract...");
let contract_address = instantiate_smart_contract(instantiate_exec, weight_limit)
.await
Expand Down
53 changes: 41 additions & 12 deletions crates/pop-cli/src/commands/up/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

use crate::style::{style, Theme};
use clap::Args;
use cliclack::{clear_screen, confirm, intro, log, outro, outro_cancel, set_theme};
use cliclack::{
clear_screen, confirm, intro, log, multi_progress, outro, outro_cancel, set_theme, ProgressBar,
};
use console::{Emoji, Style};
use pop_parachains::{NetworkNode, Zombienet};
use pop_parachains::{NetworkNode, Status, Zombienet};
use std::time::Duration;
use tokio::time::sleep;

#[derive(Args)]
pub(crate) struct ZombienetCommand {
Expand Down Expand Up @@ -45,28 +49,43 @@ impl ZombienetCommand {
let missing = zombienet.missing_binaries();
if missing.len() > 0 {
log::warning(format!(
"The following missing binaries are required: {}",
"⚠️ The following missing binaries are required: {}",
missing.iter().map(|b| b.name.as_str()).collect::<Vec<_>>().join(", ")
))?;
if !confirm("Would you like to source them automatically now?")
if !confirm("📦 Would you like to source them automatically now?")
.initial_value(true)
.interact()?
{
outro_cancel("Cannot deploy parachain to local network until all required binaries are available.")?;
outro_cancel("🚫 Cannot deploy parachain to local network until all required binaries are available.")?;
return Ok(());
}
log::info(format!("They will be cached at {}", &cache.to_str().unwrap()))?;
log::info(format!("ℹ️ They will be cached at {}", &cache.to_str().unwrap()))?;
// Source binaries
let mut spinner = cliclack::spinner();
for binary in missing {
spinner.start(format!("Sourcing {}...", binary.name));
binary.source(&cache).await?;
spinner.start(format!("Sourcing {} complete.", binary.name));
let multi = multi_progress(format!("📦 Sourcing {}...", binary.name));
let progress = multi.add(cliclack::spinner());
let progress_reporter = ProgressReporter(&progress);
for attempt in (0..=1).rev() {
if let Err(e) = binary.source(&cache, progress_reporter).await {
match attempt {
0 => {
progress.error(format!("🚫 Sourcing failed: {e}"));
multi.stop();
return Ok(());
},
_ => {
progress.error("🚫 Sourcing attempt failed, retrying...");
sleep(Duration::from_secs(1)).await;
},
}
}
}
progress.stop(format!("✅ Sourcing {} complete.", binary.name));
multi.stop();
}
spinner.stop("Sourcing complete.");
}
// Finally spawn network and wait for signal to terminate
let mut spinner = cliclack::spinner();
let spinner = cliclack::spinner();
spinner.start("🚀 Launching local network...");
//tracing_subscriber::fmt().init();
match zombienet.spawn().await {
Expand Down Expand Up @@ -130,3 +149,13 @@ impl ZombienetCommand {
Ok(())
}
}

/// Reports any observed status updates to a progress bar.
#[derive(Copy, Clone)]
struct ProgressReporter<'a>(&'a ProgressBar);

impl Status for ProgressReporter<'_> {
fn update(&self, status: &str) {
self.0.start(status.replace(" Compiling", "Compiling"))
}
}
2 changes: 1 addition & 1 deletion crates/pop-parachains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use build::build_parachain;
pub use new_pallet::{create_pallet_template, TemplatePalletConfig};
pub use new_parachain::instantiate_template_dir;
pub use templates::{Config, Provider, Template};
pub use up::Zombienet;
pub use up::{Status, Zombienet};
pub use utils::git::{Git, GitHub, Release};
pub use utils::pallet_helpers::resolve_pallet_path;
// External exports
Expand Down
Loading
Loading