From 3cb18957ab98544c7f5c92d514e43b0a96829e0c Mon Sep 17 00:00:00 2001 From: Bruno Galvao Date: Thu, 4 Apr 2024 00:32:36 +0900 Subject: [PATCH 1/2] add cargo contract acknowledgement (#95) --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d5aacf8c..5bea5a2f 100644 --- a/README.md +++ b/README.md @@ -210,4 +210,5 @@ pop up parachain -f ./tests/zombienet.toml -p https://github.com/r0gue-io/pop-no Pop CLI would not be possible without these awesome crates! -- Local network deployment powered by [zombienet-sdk](https://github.com/paritytech/zombienet-sdk) \ No newline at end of file +- Local network deployment powered by [zombienet-sdk](https://github.com/paritytech/zombienet-sdk) +- [cargo contract](https://github.com/paritytech/cargo-contract) a setup and deployment tool for developing Wasm based smart contracts via ink! \ No newline at end of file From 3bbe6177e5a8d9e0715e392319e92ea6277782b6 Mon Sep 17 00:00:00 2001 From: CinematicCow <26029731+CinematicCow@users.noreply.github.com> Date: Wed, 3 Apr 2024 23:11:48 +0530 Subject: [PATCH 2/2] feat(new parachain): show polkadot version (#89) * feat(new parachain): get repo release tag * fix: lockfile regex * fix: formatting * chore: log version on new line test: fix mismatch type error * fix: formatting * fixes: review suggestions * fixes: unit test --------- Co-authored-by: Abhishek Shah --- Cargo.lock | 1 + Cargo.toml | 1 + src/commands/new/parachain.rs | 7 +++++-- src/engines/contract_engine.rs | 5 +++-- src/engines/parachain_engine.rs | 18 +++++++++++------- src/helpers.rs | 24 ++++++++++++++++++++++-- 6 files changed, 43 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2055d55f..0da98d92 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5431,6 +5431,7 @@ dependencies = [ "ink_env", "log", "predicates", + "regex", "reqwest", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 211269c4..0344ae21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ tempfile = "3.8" tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } url = { version = "2.5", optional = true } walkdir = "2.4" +regex="1.5.4" # contracts contract-build = { version = "4.0.0-rc.3", optional = true } diff --git a/src/commands/new/parachain.rs b/src/commands/new/parachain.rs index c4e49e4d..b8e8889c 100644 --- a/src/commands/new/parachain.rs +++ b/src/commands/new/parachain.rs @@ -7,7 +7,7 @@ use clap::{Args, Parser}; use std::{fs, path::Path}; use strum_macros::{Display, EnumString}; -use cliclack::{clear_screen, confirm, intro, outro, outro_cancel, set_theme}; +use cliclack::{clear_screen, confirm, intro, log, outro, outro_cancel, set_theme}; #[derive(Clone, Parser, Debug, Display, EnumString, PartialEq)] pub enum Template { @@ -69,7 +69,7 @@ impl NewParachainCommand { } let mut spinner = cliclack::spinner(); spinner.start("Generating parachain..."); - instantiate_template_dir( + let tag = instantiate_template_dir( &self.template, destination_path, Config { @@ -84,6 +84,9 @@ impl NewParachainCommand { } } spinner.stop("Generation complete"); + if let Some(tag) = tag { + log::info(format!("Version: {}", tag))?; + } outro(format!("cd into \"{}\" and enjoy hacking! 🚀", &self.name))?; Ok(()) } diff --git a/src/engines/contract_engine.rs b/src/engines/contract_engine.rs index 09721ec6..d524aa43 100644 --- a/src/engines/contract_engine.rs +++ b/src/engines/contract_engine.rs @@ -19,8 +19,9 @@ pub fn create_smart_contract(name: String, target: &Option) -> anyhow:: } pub fn build_smart_contract(path: &Option) -> anyhow::Result<()> { - // If the user specifies a path (which is not the current directory), it will have to manually add a Cargo.toml file. If not provided, pop-cli will ask the user for a specific path. or - // ask to the user the specific path (Like cargo-contract does) + // If the user specifies a path (which is not the current directory), it will have to manually + // add a Cargo.toml file. If not provided, pop-cli will ask the user for a specific path. or ask + // to the user the specific path (Like cargo-contract does) let manifest_path; if path.is_some() { let full_path: PathBuf = diff --git a/src/engines/parachain_engine.rs b/src/engines/parachain_engine.rs index cf55776d..e00c2b5e 100644 --- a/src/engines/parachain_engine.rs +++ b/src/engines/parachain_engine.rs @@ -20,7 +20,11 @@ pub struct Config { } /// Creates a new template at `target` dir -pub fn instantiate_template_dir(template: &Template, target: &Path, config: Config) -> Result<()> { +pub fn instantiate_template_dir( + template: &Template, + target: &Path, + config: Config, +) -> Result> { sanitize(target)?; use Template::*; let url = match template { @@ -30,15 +34,15 @@ pub fn instantiate_template_dir(template: &Template, target: &Path, config: Conf return instantiate_base_template(target, config); }, }; - clone_and_degit(url, target)?; + let tag = clone_and_degit(url, target)?; Repository::init(target)?; - Ok(()) + Ok(tag) } -pub fn instantiate_base_template(target: &Path, config: Config) -> Result<()> { +pub fn instantiate_base_template(target: &Path, config: Config) -> Result> { let temp_dir = ::tempfile::TempDir::new_in(std::env::temp_dir())?; let source = temp_dir.path(); - clone_and_degit("https://github.com/r0gue-io/base-parachain", source)?; + let tag = clone_and_degit("https://github.com/r0gue-io/base-parachain", source)?; for entry in WalkDir::new(&source) { let entry = entry?; @@ -66,7 +70,7 @@ pub fn instantiate_base_template(target: &Path, config: Config) -> Result<()> { let network = Network { node: "parachain-template-node".into() }; write_to_file(&target.join("network.toml"), network.render().expect("infallible").as_ref()); Repository::init(target)?; - Ok(()) + Ok(tag) } pub fn build_parachain(path: &Option) -> anyhow::Result<()> { @@ -90,7 +94,7 @@ mod tests { decimals: 18, initial_endowment: "1000000".to_string(), }; - let result: anyhow::Result<()> = instantiate_base_template(temp_dir.path(), config); + let result = instantiate_base_template(temp_dir.path(), config); assert!(result.is_ok()); Ok(temp_dir) } diff --git a/src/helpers.rs b/src/helpers.rs index 293b3626..63c4eb68 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,6 +1,7 @@ use anyhow::Result; use cliclack::{log, outro_cancel}; use git2::{IndexAddOption, Repository, ResetType}; +use regex::Regex; use std::{ env::current_dir, fs::{self, OpenOptions}, @@ -43,11 +44,30 @@ pub(crate) fn write_to_file<'a>(path: &Path, contents: &'a str) { } /// Clone `url` into `target` and degit it -pub(crate) fn clone_and_degit(url: &str, target: &Path) -> Result<()> { +pub(crate) fn clone_and_degit(url: &str, target: &Path) -> Result> { let repo = Repository::clone(url, target)?; + + // fetch tags from remote + let release = fetch_latest_tag(&repo); + let git_dir = repo.path(); fs::remove_dir_all(&git_dir)?; - Ok(()) + Ok(release) +} + +/// Fetch the latest release from a repository +fn fetch_latest_tag(repo: &Repository) -> Option { + let version_reg = Regex::new(r"v\d+\.\d+\.\d+").expect("Valid regex"); + let tags = repo.tag_names(None).ok()?; + // Start from latest tags + for tag in tags.iter().rev() { + if let Some(tag) = tag { + if version_reg.is_match(tag) { + return Some(tag.to_string()); + } + } + } + None } /// Init a new git repo on creation of a parachain