Skip to content

Commit

Permalink
Merge branch 'main' into peter/feat-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
brunopgalvao authored May 10, 2024
2 parents c802275 + 738e0d6 commit 04d6e26
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 81 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ jobs:
git-user: ${{ env.GITHUB_ACTOR }}

- name: Run integration tests
run: cargo test --test parachain
run: cargo test --test parachain
27 changes: 27 additions & 0 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: pop install

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

defaults:
run:
shell: bash

jobs:
ubuntu:
runs-on: ubuntu-latest
container: ubuntu
steps:
- uses: actions/checkout@v4
- name: Install prerequisites
run: apt-get update && apt-get -y install build-essential cmake curl git
- name: Install Rust
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- name: Install Pop
run: |
. "$HOME/.cargo/env"
cargo install --locked --path ./crates/pop-cli
pop --version
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: rustup target add ${{ matrix.platform.target }}

- name: Build pop-cli
run: cargo build --profile=production -p pop-cli --target ${{ matrix.platform.target }} --features static-ssl
run: cargo build --profile=production -p pop-cli --target ${{ matrix.platform.target }}

- name: Package binary (Linux)
if: contains(matrix.platform.target, 'linux')
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ If no guidance is needed, proceed with:
pop new parachain my-app
```

`pop-cli` supports diverse project templates, to use a specific one use the flag `--template`:
```sh
# Create an assets parachain
pop new parachain my-app pop -t assets
# Create a contracts parachain
pop new parachain my-app pop -t contracts
# Create a evm parachain
pop new parachain my-app pop -t evm
```

We also integrate other provider templates in the tool, check them running:

```sh
Expand Down
6 changes: 3 additions & 3 deletions crates/pop-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ sp-weights = { workspace = true, optional = true }

# parachains
pop-parachains = { path = "../pop-parachains", optional = true }
dirs = { workspace = true, optional = true }
git2.workspace = true
dirs = { version = "5.0", optional = true }
git2 = { workspace = true, features = ["vendored-openssl"] }

# telemetry
pop-telemetry = { path = "../pop-telemetry", optional = true }
Expand All @@ -54,4 +54,4 @@ parachain = [
"dep:pop-parachains",
"dep:dirs",
]
telemetry = ["dep:pop-telemetry"]
telemetry = ["dep:pop-telemetry"]
12 changes: 6 additions & 6 deletions crates/pop-cli/src/commands/new/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async fn guide_user_to_generate_parachain() -> Result<NewParachainCommand> {
decimals: 12,
initial_endowment: "1u64 << 60".to_string(),
};
if matches!(template, Template::Base) {
if template.matches(&Provider::Pop) {
customizable_options = prompt_customizable_options()?;
}

Expand Down Expand Up @@ -221,7 +221,7 @@ fn get_customization_value(
decimals: Option<u8>,
initial_endowment: Option<String>,
) -> Result<Config> {
if !matches!(template, Template::Base)
if !matches!(template, Template::Standard)
&& (symbol.is_some() || decimals.is_some() || initial_endowment.is_some())
{
log::warning("Customization options are not available for this template")?;
Expand Down Expand Up @@ -335,7 +335,7 @@ mod tests {
let command = NewParachainCommand {
name: Some(dir.path().join("test_parachain").to_str().unwrap().to_string()),
provider: Some(Provider::Pop),
template: Some(Template::Base),
template: Some(Template::Standard),
release_tag: None,
symbol: Some("UNIT".to_string()),
decimals: Some(12),
Expand All @@ -353,19 +353,19 @@ mod tests {

#[test]
fn test_is_template_supported() -> Result<()> {
is_template_supported(&Provider::Pop, &Template::Base)?;
is_template_supported(&Provider::Pop, &Template::Standard)?;
assert!(is_template_supported(&Provider::Pop, &Template::ParityContracts).is_err());
assert!(is_template_supported(&Provider::Pop, &Template::ParityFPT).is_err());

assert!(is_template_supported(&Provider::Parity, &Template::Base).is_err());
assert!(is_template_supported(&Provider::Parity, &Template::Standard).is_err());
is_template_supported(&Provider::Parity, &Template::ParityContracts)?;
is_template_supported(&Provider::Parity, &Template::ParityFPT)
}

#[test]
fn test_get_customization_values() -> Result<()> {
let config = get_customization_value(
&Template::Base,
&Template::Standard,
Some("DOT".to_string()),
Some(6),
Some("10000".to_string()),
Expand Down
15 changes: 13 additions & 2 deletions crates/pop-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// SPDX-License-Identifier: GPL-3.0

#[cfg(not(any(feature = "contract", feature = "parachain")))]
compile_error!("feature \"contract\" or feature \"parachain\" must be enabled");

#[cfg(any(feature = "parachain", feature = "contract"))]
mod commands;
#[cfg(any(feature = "parachain", feature = "contract"))]
mod style;

use anyhow::{anyhow, Result};
#[cfg(feature = "parachain")]
use anyhow::anyhow;
use anyhow::Result;
use clap::{Parser, Subcommand};
use commands::*;
#[cfg(feature = "telemetry")]
use pop_telemetry::{config_file_path, record_cli_command, record_cli_used, Telemetry};
use serde_json::{json, Value};
#[cfg(feature = "parachain")]
use std::{fs::create_dir_all, path::PathBuf};

#[derive(Parser)]
Expand All @@ -25,16 +30,19 @@ pub struct Cli {
enum Commands {
/// Generate a new parachain, pallet or smart contract.
#[clap(alias = "n")]
#[cfg(any(feature = "parachain", feature = "contract"))]
New(new::NewArgs),
/// Build a parachain or smart contract.
#[clap(alias = "b")]
#[cfg(any(feature = "parachain", feature = "contract"))]
Build(build::BuildArgs),
/// Call a smart contract.
#[clap(alias = "c")]
#[cfg(feature = "contract")]
Call(call::CallArgs),
/// Deploy a parachain or smart contract.
#[clap(alias = "u")]
#[cfg(any(feature = "parachain", feature = "contract"))]
Up(up::UpArgs),
/// Test a smart contract.
#[clap(alias = "t")]
Expand All @@ -49,6 +57,7 @@ async fn main() -> Result<()> {

let cli = Cli::parse();
let res = match cli.command {
#[cfg(any(feature = "parachain", feature = "contract"))]
Commands::New(args) => match args.command {
#[cfg(feature = "parachain")]
new::NewCommands::Parachain(cmd) => match cmd.execute().await {
Expand All @@ -69,6 +78,7 @@ async fn main() -> Result<()> {
cmd.execute().await.map(|_| json!("default"))
},
},
#[cfg(any(feature = "parachain", feature = "contract"))]
Commands::Build(args) => match &args.command {
#[cfg(feature = "parachain")]
build::BuildCommands::Parachain(cmd) => cmd.execute().map(|_| Value::Null),
Expand All @@ -79,6 +89,7 @@ async fn main() -> Result<()> {
Commands::Call(args) => match &args.command {
call::CallCommands::Contract(cmd) => cmd.execute().await.map(|_| Value::Null),
},
#[cfg(any(feature = "parachain", feature = "contract"))]
Commands::Up(args) => match &args.command {
#[cfg(feature = "parachain")]
up::UpCommands::Parachain(cmd) => cmd.execute().await.map(|_| Value::Null),
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-cli/src/style.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-3.0

use cliclack::ThemeState;
#[cfg(any(feature = "parachain", feature = "contract"))]
pub(crate) use console::style;
use console::Style;

Expand Down
2 changes: 1 addition & 1 deletion crates/pop-parachains/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Generate a new Parachain:
```rust
use pop_parachains::{instantiate_template_dir, Config, Git, Template};

let template = Template::Base;
let template = Template::Standard;
let destination_path = ...;
let config = Config {
symbol: ...,
Expand Down
14 changes: 7 additions & 7 deletions crates/pop-parachains/src/new_parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
git::Git,
helpers::{sanitize, write_to_file},
},
Config, Template,
Config, Provider, Template,
};
use anyhow::Result;
use std::{fs, path::Path};
Expand All @@ -21,21 +21,21 @@ pub fn instantiate_template_dir(
) -> Result<Option<String>> {
sanitize(target)?;

if matches!(template, &Template::Base) {
return instantiate_base_template(target, config, tag_version);
if template.matches(&Provider::Pop) {
return instantiate_standard_template(template, target, config, tag_version);
}
let tag = Git::clone_and_degit(template.repository_url()?, target, tag_version)?;
Ok(tag)
}

pub fn instantiate_base_template(
pub fn instantiate_standard_template(
template: &Template,
target: &Path,
config: Config,
tag_version: Option<String>,
) -> Result<Option<String>> {
let temp_dir = ::tempfile::TempDir::new_in(std::env::temp_dir())?;
let source = temp_dir.path();
let template = crate::templates::Template::Base;

let tag = Git::clone_and_degit(template.repository_url()?, source, tag_version)?;

Expand Down Expand Up @@ -80,12 +80,12 @@ mod tests {
decimals: 18,
initial_endowment: "1000000".to_string(),
};
instantiate_base_template(temp_dir.path(), config, None)?;
instantiate_standard_template(&Template::Standard, temp_dir.path(), config, None)?;
Ok(temp_dir)
}

#[test]
fn test_parachain_instantiate_base_template() -> Result<()> {
fn test_parachain_instantiate_standard_template() -> Result<()> {
let temp_dir =
setup_template_and_instantiate().expect("Failed to setup template and instantiate");

Expand Down
Loading

0 comments on commit 04d6e26

Please sign in to comment.