From 9b2bbc4dc7d3480e0d898e28b3b9b3605e3f0cc2 Mon Sep 17 00:00:00 2001 From: d-roak Date: Thu, 24 Aug 2023 10:38:00 +0100 Subject: [PATCH 1/3] add validation of build-spec command in the ci; set madara-path always --- .github/workflows/madara-commands.yml | 30 +++++++ CHANGELOG.md | 3 + crates/node/src/command.rs | 122 +++++++++++++------------- 3 files changed, 94 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/madara-commands.yml diff --git a/.github/workflows/madara-commands.yml b/.github/workflows/madara-commands.yml new file mode 100644 index 0000000000..202fb6eeec --- /dev/null +++ b/.github/workflows/madara-commands.yml @@ -0,0 +1,30 @@ +--- +name: Task - Test Madara Commands + +on: + workflow_dispatch: + workflow_call: + +jobs: + build-spec: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} + fail-on-cache-miss: true + - name: Create build-spec (plain) + run: | + target/madara build-spec --chain local > chain-plain.json + - name: Create build-spec (raw) + run: | + target/madara build-spec --chain chain-plain.json --raw > chain-raw.json + +# TODO: add remaining commands diff --git a/CHANGELOG.md b/CHANGELOG.md index 715322a58f..f140a8a02b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Next release +- ci: add verification if build-spec is working +- bug: fix build-spec not working by setting the madara-path always and fetching + relevant files - ci: added wasm to test - docs: added translation of madara beast article.md to portuguese - ci: disable benchmark for pushes and pr's diff --git a/crates/node/src/command.rs b/crates/node/src/command.rs index 176c239653..7cd1c8a49d 100644 --- a/crates/node/src/command.rs +++ b/crates/node/src/command.rs @@ -56,6 +56,67 @@ impl SubstrateCli for Cli { pub fn run() -> sc_cli::Result<()> { let mut cli = Cli::from_args(); + // alias madara_path <> base_path + // TODO also alias tmp (tmp generates random base_paths that are not specified within + // the command) + let madara_path = match (cli.run.madara_path.clone(), cli.run.run_cmd.shared_params.base_path.clone()) { + (Some(madara_path), _) => { + cli.run.run_cmd.shared_params.base_path = Some(madara_path.clone()); + madara_path.to_str().unwrap().to_string() + } + (_, Some(base_path)) => { + cli.run.madara_path = Some(base_path.clone()); + base_path.to_str().unwrap().to_string() + } + _ => { + let home_path = std::env::var("HOME").unwrap_or(std::env::var("USERPROFILE").unwrap_or(".".into())); + let path = format!("{}/.madara", home_path); + cli.run.run_cmd.shared_params.base_path = Some((path.clone()).into()); + cli.run.madara_path = Some((path.clone()).into()); + path + } + }; + + if let Some(genesis_url) = cli.run.genesis_url.clone() { + // can't copy extra genesis-assets atm + // we can reuse #982 to create the standard to fetch relevant files + utils::fetch_from_url(genesis_url, madara_path.clone() + "/configs/genesis-assets")?; + } else { + // TODO confirm with the CI that we are fetching all and fetch dynamically + // Issue #982 + for file in constants::GENESIS_ASSETS_FILES { + let src_path = utils::get_project_path(); + if let Ok(src_path) = src_path { + let src_path = src_path + "/configs/genesis-assets/" + file; + utils::copy_from_filesystem(src_path, madara_path.clone() + "/genesis-assets")?; + } else { + utils::fetch_from_url( + constants::GENESIS_ASSETS_URL.to_string() + file, + madara_path.clone() + "/genesis-assets", + )?; + } + } + } + + // TODO confirm with the CI that we are fetching all and fetch dynamically + // Issue #982 + for file in constants::CAIRO_CONTRACTS_FILES { + let src_path = utils::get_project_path(); + if let Ok(src_path) = src_path { + let src_path = src_path + "/configs/cairo-contracts/" + file; + utils::copy_from_filesystem(src_path, madara_path.clone() + "/cairo-contracts")?; + } else { + utils::fetch_from_url( + constants::CAIRO_CONTRACTS_URL.to_string() + file, + madara_path.clone() + "/cairo-contracts", + )?; + } + } + + if let (Some(chain_spec_url), None) = (cli.run.chain_spec_url.clone(), cli.run.testnet) { + utils::fetch_from_url(chain_spec_url, madara_path.clone() + "/chain-specs")?; + } + match &cli.subcommand { Some(Subcommand::Key(cmd)) => cmd.run(&cli), Some(Subcommand::BuildSpec(cmd)) => { @@ -189,70 +250,9 @@ pub fn run() -> sc_cli::Result<()> { cli.run.run_cmd.rpc_methods = RpcMethods::Unsafe; } - // alias madara_path <> base_path - // TODO also alias tmp (tmp generates random base_paths that are not specified within - // the command) - let madara_path = match (cli.run.madara_path.clone(), cli.run.run_cmd.shared_params.base_path.clone()) { - (Some(madara_path), _) => { - cli.run.run_cmd.shared_params.base_path = Some(madara_path.clone()); - madara_path.to_str().unwrap().to_string() - } - (_, Some(base_path)) => { - cli.run.madara_path = Some(base_path.clone()); - base_path.to_str().unwrap().to_string() - } - _ => { - let home_path = std::env::var("HOME").unwrap_or(std::env::var("USERPROFILE").unwrap_or(".".into())); - let path = format!("{}/.madara", home_path); - cli.run.run_cmd.shared_params.base_path = Some((path.clone()).into()); - cli.run.madara_path = Some((path.clone()).into()); - path - } - }; - cli.run.run_cmd.network_params.node_key_params.node_key_file = Some((madara_path.clone() + "/p2p-key.ed25519").into()); - if let Some(genesis_url) = cli.run.genesis_url.clone() { - // can't copy extra genesis-assets atm - // we can reuse #982 to create the standard to fetch relevant files - utils::fetch_from_url(genesis_url, madara_path.clone() + "/configs/genesis-assets")?; - } else { - // TODO confirm with the CI that we are fetching all and fetch dynamically - // Issue #982 - for file in constants::GENESIS_ASSETS_FILES { - let src_path = utils::get_project_path(); - if let Ok(src_path) = src_path { - let src_path = src_path + "/configs/genesis-assets/" + file; - utils::copy_from_filesystem(src_path, madara_path.clone() + "/genesis-assets")?; - } else { - utils::fetch_from_url( - constants::GENESIS_ASSETS_URL.to_string() + file, - madara_path.clone() + "/genesis-assets", - )?; - } - } - } - - // TODO confirm with the CI that we are fetching all and fetch dynamically - // Issue #982 - for file in constants::CAIRO_CONTRACTS_FILES { - let src_path = utils::get_project_path(); - if let Ok(src_path) = src_path { - let src_path = src_path + "/configs/cairo-contracts/" + file; - utils::copy_from_filesystem(src_path, madara_path.clone() + "/cairo-contracts")?; - } else { - utils::fetch_from_url( - constants::CAIRO_CONTRACTS_URL.to_string() + file, - madara_path.clone() + "/cairo-contracts", - )?; - } - } - - if let (Some(chain_spec_url), None) = (cli.run.chain_spec_url.clone(), cli.run.testnet) { - utils::fetch_from_url(chain_spec_url, madara_path.clone() + "/chain-specs")?; - } - if let Some(Testnet::Sharingan) = cli.run.testnet { let src_path = utils::get_project_path(); if let Ok(src_path) = src_path { From 1f8759300fd156a4d06f0a5865978aee3c851974 Mon Sep 17 00:00:00 2001 From: d-roak Date: Thu, 24 Aug 2023 10:40:45 +0100 Subject: [PATCH 2/3] activate madara_commands task in the ci --- .github/workflows/pull-request.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index da9f8f9a6a..661485255b 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -21,6 +21,11 @@ jobs: uses: ./.github/workflows/rust-build.yml needs: changelog + madara_commands: + name: Test Madara commands + uses: ./.github/workflows/madara-commands.yml + needs: rust_build + linters_cargo: name: Run Cargo linters uses: ./.github/workflows/linters-cargo.yml From 81a52a24e292f72a85d8f59cb46b8c378ef5bdc9 Mon Sep 17 00:00:00 2001 From: d-roak Date: Thu, 24 Aug 2023 10:47:34 +0100 Subject: [PATCH 3/3] fix bin path --- .github/workflows/madara-commands.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/madara-commands.yml b/.github/workflows/madara-commands.yml index 202fb6eeec..1e7558b02d 100644 --- a/.github/workflows/madara-commands.yml +++ b/.github/workflows/madara-commands.yml @@ -22,9 +22,9 @@ jobs: fail-on-cache-miss: true - name: Create build-spec (plain) run: | - target/madara build-spec --chain local > chain-plain.json + target/release/madara build-spec --chain local > chain-plain.json - name: Create build-spec (raw) run: | - target/madara build-spec --chain chain-plain.json --raw > chain-raw.json + target/release/madara build-spec --chain chain-plain.json --raw > chain-raw.json # TODO: add remaining commands