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: add ability to run a script once network is initialized #180

Merged
merged 13 commits into from
May 23, 2024
17 changes: 17 additions & 0 deletions crates/pop-cli/src/commands/up/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use cliclack::{
clear_screen, confirm, intro, log, multi_progress, outro, outro_cancel, set_theme, ProgressBar,
};
use console::{Emoji, Style};
use duct::cmd;
use pop_parachains::{NetworkNode, Status, Zombienet};
use std::time::Duration;
use tokio::time::sleep;
Expand All @@ -26,6 +27,12 @@ pub(crate) struct ZombienetCommand {
/// The url of the git repository of a parachain to be used, with branch/release tag specified as #fragment (e.g. 'https://github.com/org/repository#tag'). A specific binary name can also be optionally specified via query string parameter (e.g. 'https://github.com/org/repository?binaryname#tag'), defaulting to the name of the repository when not specified.
#[arg(short, long)]
parachain: Option<Vec<String>>,
/// The path to a script to be run after the network has been set up.
#[clap(name = "init", short = 'i', long)]
setup_script: Option<String>,
evilrobot-01 marked this conversation as resolved.
Show resolved Hide resolved
/// The script arguments, encoded as strings.
#[clap(name = "args", short = 'a', long, num_args = 0..)]
args: Vec<String>,
/// Whether the output should be verbose.
#[arg(short, long, action)]
verbose: bool,
Expand Down Expand Up @@ -138,6 +145,16 @@ impl ZombienetCommand {
}
}

if self.setup_script.is_some() {
spinner.set_message("Initializing your setup script...");
// sleep for 15 seconds to allow the network to start up
sleep(Duration::from_secs(15)).await;
brunopgalvao marked this conversation as resolved.
Show resolved Hide resolved
cmd(self.setup_script.clone().unwrap(), self.args.clone())
.run()
.map_err(|e| anyhow::Error::new(e).context("Error running the script"))?;
clear_screen()?;
}

spinner.stop(result);
tokio::signal::ctrl_c().await?;
outro("Done")?;
Expand Down
2 changes: 2 additions & 0 deletions tests/zombienet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ chain = "rococo-local"

[[relaychain.nodes]]
name = "alice"
rpc_port = 8833
evilrobot-01 marked this conversation as resolved.
Show resolved Hide resolved
validator = true

[[relaychain.nodes]]
Expand All @@ -22,4 +23,5 @@ default_command = "pop-node"

[[parachains.collators]]
name = "pop"
rpc_port = 9944
args = ["-lruntime::contracts=debug"]
Loading