diff --git a/Cargo.lock b/Cargo.lock index 686cdaf6..3c6275c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5463,7 +5463,6 @@ dependencies = [ "subxt 0.34.0", "subxt-signer 0.34.0", "tempfile", - "tokio", "url", ] diff --git a/Cargo.toml b/Cargo.toml index ef0dfbe5..34e9ff08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,32 @@ git2 = "0.18" tempfile = "3.8" tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] } url = { version = "2.5"} + +# contracts +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-weights = { version = "29.0.0" } +contract-build = { version = "4.0.2" } +contract-extrinsics = { version = "4.0.0-rc.3"} + +# parachains +askama = "0.12" +regex="1.5.4" +walkdir = "2.4" +indexmap = { version = "2.2"} +toml_edit = { version = "0.22" } +symlink = { version = "0.1" } +reqwest = { version = "0.11" } +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-support = { git = "https://github.com/r0gue-io/zombienet-sdk", branch = "pop", version = "0.1.0-alpha.1" } + +# pop-cli +clap = { version = "4.4", features = ["derive"] } +cliclack = "0.1" +console = "0.15" +strum = "0.26" +strum_macros = "0.26" diff --git a/README.md b/README.md index 5ca12ee1..2aa0cfa0 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ cargo install --locked --git https://github.com/r0gue-io/pop-cli ### Parachains -Use `pop` to generate a new parachain from a template: +Use `pop` to create a new Parachain project: ```sh # Create a minimal parachain @@ -29,7 +29,7 @@ pop new parachain my-app cpt pop new parachain my-app fpt ``` -Use `pop` to build your parachain. +Use `pop` to build your Parachain: ```sh # Build your parachain @@ -57,50 +57,49 @@ There's also the shorter version: pop new parachain my-app -s DOT -d 6 -i 1_000_000_000 ``` -To create a new pallet, simply `pop new pallet`. And that's it. You will have a new `pallet-template` ready for hacking. -To customize the new pallet you can follow these options: +Finally, to build your Parachain: ```sh -# create a pallet with name `pallet-awesome` in the current working directory -pop new pallet pallet-awesome -# or with options -pop new pallet pallet-awesome --authors Me --description "This pallet oozes awesomeness" --path my_app/pallets +cd my-app +pop build parachain --release ``` -Finally, you would need to build and run it. +## Spawn Network using Zombienet -```sh -cd my-app -pop build parachain --release +You can spawn a local network using [zombienet](https://github.com/paritytech/zombienet-sdk) as follows: + +```shell +pop up parachain -f ./tests/zombienet.toml -p https://github.com/r0gue-io/pop-node ``` -For running any parachain, we recommend using [zombienet](https://github.com/paritytech/zombienet). -See below for more information about using `pop up parachain` to help you with this. +> :information_source: Pop CLI will automatically source the necessary polkadot binaries. Currently, these will be built +> if on a non-linux system. + ### Contracts -Use `pop` to create a smart contract: +Use `pop` to create a new Smart Contract project: ```sh -# Create a minimal smart contract +# Create a minimal Smart Contract pop new contract my_contract ``` -Test the smart contract: +Test the Smart Contract: ```sh -# Test an existing smart contract +# Test an existing Smart Contract pop test contract -p ./my_contract ``` -Build the smart contract: +Build the Smart Contract: ```sh -# Build an existing smart contract +# Build an existing Smart Contract pop build contract -p ./my_contract ``` -To deploy a contract you need your chain running. For testing purposes one option is to +To deploy a Smart Contract you need a chain running. For testing purposes one option is to run [substrate-contracts-node](https://github.com/paritytech/substrate-contracts-node): ```sh @@ -110,7 +109,7 @@ substrate-contracts-node > :information_source: We plan to automate this in the future. -Deploy and instantiate the smart contract: +Deploy and instantiate the Smart Contract: ```sh pop up contract -p ./my_contract --constructor new --args "false" --suri //Alice @@ -136,7 +135,7 @@ check [cargo-contract documentation](https://github.com/paritytech/cargo-contrac Interacting with the Smart Contract: 1. Read-only Operations: For operations that only require reading from the blockchain state. This approach does not - require to submit an extrinsic (skip the flag `x/--execute`). + require to submit an extrinsic. Example using the get() message: ```sh @@ -144,7 +143,7 @@ pop call contract -p ./my_contract --contract $INSTANTIATED_CONTRACT_ADDRESS --m ``` 2. State-modifying Operations: For operations that change a storage value, thus altering the blockchain state. Include - the `x/--execute` flag to submit an extrinsic on-chain. + the `x / --execute` flag to submit an extrinsic on-chain. Example executing the `flip()` message: @@ -152,7 +151,7 @@ Example executing the `flip()` message: pop call contract -p ./my_contract --contract $INSTANTIATED_CONTRACT_ADDRESS --message flip --suri //Alice -x ``` -### E2E testing +## E2E testing For end-to-end testing you will need to have a Substrate node with `pallet contracts`. You do not need to run it in the background since the node is started for each test independently. @@ -168,13 +167,25 @@ If you want to run any other node with `pallet-contracts` you need to change `CO export CONTRACTS_NODE="YOUR_CONTRACTS_NODE_PATH" ``` -Run e2e testing on the smart contract: +Run e2e testing on the Smart Contract: ```sh # Run e2e tests for an existing smart contract pop test contract -p ./my_contract --features e2e-tests ``` +### Pallets + +To create a new Pallet, simply run `pop new pallet`. You will have a new pallet ready for hacking. +To customize the new Pallet you can follow these options: + +```sh +# create a pallet with name `pallet-awesome` in the current working directory +pop new pallet pallet-awesome +# or with options +pop new pallet pallet-awesome --authors Me --description "This pallet oozes awesomeness" --path my_app/pallets +``` + ## Building Pop CLI locally Build the tool locally with all the features: @@ -183,30 +194,18 @@ Build the tool locally with all the features: cargo build --all-features ``` -Build the tool only for parachain functionality: +Build the tool only for Parachain functionality: ```sh cargo build --features parachain ``` -Build the tool only for contracts functionality: +Build the tool only for Smart Contracts functionality: ```sh cargo build --features contract ``` -## Spawn Network using Zombienet - -You can spawn a local network using [zombienet](https://github.com/paritytech/zombienet-sdk) as follows: - -```shell -pop up parachain -f ./tests/zombienet.toml -p https://github.com/r0gue-io/pop-node -``` - -> :information_source: Pop CLI will automatically source the necessary polkadot binaries. Currently, these will be built -> if on a non-linux system. - - ## Testing Pop CLI To test the tool locally. @@ -217,29 +216,29 @@ Run the unit tests: cargo test ``` -Due to the time it can take to build a test or a contract some tests has been separate to the normal testing flow. +Due to the time it can take to build a Parachain or a Smart Contract, some tests have been separated from the normal testing flow. -To run the unit tests that involves building a contract: +To run the unit tests that involves building a Smart Contract: ```sh cargo test --features unit_contract ``` -To run the unit tests that involves building a parachain: +To run the unit tests that involves building a Parachain: ```sh cargo test --features unit_parachain ``` -Then we have some tests that check all the flow is correct: +Then we have some tests that check all the flows are correct: -Run the e2e tests for contracts functionality: +Run the e2e tests for Smart Contracts functionality: ```sh cargo test --features e2e_contract ``` -Run the e2e tests for parachain functionality: +Run the e2e tests for Parachain functionality: ```sh cargo test --features e2e_parachain @@ -255,4 +254,4 @@ cargo test --all-features Pop CLI would not be possible without these awesome crates! - 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! +- [cargo contract](https://github.com/paritytech/cargo-contract) a setup and deployment tool for developing Wasm based Smart Contracts via ink! diff --git a/crates/pop-cli/Cargo.toml b/crates/pop-cli/Cargo.toml index ffb5652f..3b4643fe 100644 --- a/crates/pop-cli/Cargo.toml +++ b/crates/pop-cli/Cargo.toml @@ -16,21 +16,21 @@ url.workspace = true tokio.workspace = true # pop-cli -clap = { version = "4.4", features = ["derive"] } -cliclack = "0.1" -console = "0.15" -strum = "0.26" -strum_macros = "0.26" +clap.workspace = true +cliclack.workspace = true +console.workspace = true +strum.workspace = true +strum_macros.workspace = true # contracts -pop-contracts = { version = "0.1.0", path = "../pop-contracts", optional = true} -sp-core = { version = "30.0.0", optional = true } -sp-weights = { version = "29.0.0", optional = true } +pop-contracts = { path = "../pop-contracts", optional = true} +sp-core = { workspace = true, optional = true } +sp-weights = { workspace = true, optional = true } # parachains -pop-parachains = { version = "0.1.0", path = "../pop-parachains", optional = true } -dirs = { version = "5.0", optional = true } -git2.workspace = true +pop-parachains = { path = "../pop-parachains", optional = true } +dirs = { version = "5.0", optional = true} +git2.workspace = true [dev-dependencies] assert_cmd = "2.0.14" diff --git a/crates/pop-cli/README.md b/crates/pop-cli/README.md index 5ca12ee1..2aa0cfa0 100644 --- a/crates/pop-cli/README.md +++ b/crates/pop-cli/README.md @@ -18,7 +18,7 @@ cargo install --locked --git https://github.com/r0gue-io/pop-cli ### Parachains -Use `pop` to generate a new parachain from a template: +Use `pop` to create a new Parachain project: ```sh # Create a minimal parachain @@ -29,7 +29,7 @@ pop new parachain my-app cpt pop new parachain my-app fpt ``` -Use `pop` to build your parachain. +Use `pop` to build your Parachain: ```sh # Build your parachain @@ -57,50 +57,49 @@ There's also the shorter version: pop new parachain my-app -s DOT -d 6 -i 1_000_000_000 ``` -To create a new pallet, simply `pop new pallet`. And that's it. You will have a new `pallet-template` ready for hacking. -To customize the new pallet you can follow these options: +Finally, to build your Parachain: ```sh -# create a pallet with name `pallet-awesome` in the current working directory -pop new pallet pallet-awesome -# or with options -pop new pallet pallet-awesome --authors Me --description "This pallet oozes awesomeness" --path my_app/pallets +cd my-app +pop build parachain --release ``` -Finally, you would need to build and run it. +## Spawn Network using Zombienet -```sh -cd my-app -pop build parachain --release +You can spawn a local network using [zombienet](https://github.com/paritytech/zombienet-sdk) as follows: + +```shell +pop up parachain -f ./tests/zombienet.toml -p https://github.com/r0gue-io/pop-node ``` -For running any parachain, we recommend using [zombienet](https://github.com/paritytech/zombienet). -See below for more information about using `pop up parachain` to help you with this. +> :information_source: Pop CLI will automatically source the necessary polkadot binaries. Currently, these will be built +> if on a non-linux system. + ### Contracts -Use `pop` to create a smart contract: +Use `pop` to create a new Smart Contract project: ```sh -# Create a minimal smart contract +# Create a minimal Smart Contract pop new contract my_contract ``` -Test the smart contract: +Test the Smart Contract: ```sh -# Test an existing smart contract +# Test an existing Smart Contract pop test contract -p ./my_contract ``` -Build the smart contract: +Build the Smart Contract: ```sh -# Build an existing smart contract +# Build an existing Smart Contract pop build contract -p ./my_contract ``` -To deploy a contract you need your chain running. For testing purposes one option is to +To deploy a Smart Contract you need a chain running. For testing purposes one option is to run [substrate-contracts-node](https://github.com/paritytech/substrate-contracts-node): ```sh @@ -110,7 +109,7 @@ substrate-contracts-node > :information_source: We plan to automate this in the future. -Deploy and instantiate the smart contract: +Deploy and instantiate the Smart Contract: ```sh pop up contract -p ./my_contract --constructor new --args "false" --suri //Alice @@ -136,7 +135,7 @@ check [cargo-contract documentation](https://github.com/paritytech/cargo-contrac Interacting with the Smart Contract: 1. Read-only Operations: For operations that only require reading from the blockchain state. This approach does not - require to submit an extrinsic (skip the flag `x/--execute`). + require to submit an extrinsic. Example using the get() message: ```sh @@ -144,7 +143,7 @@ pop call contract -p ./my_contract --contract $INSTANTIATED_CONTRACT_ADDRESS --m ``` 2. State-modifying Operations: For operations that change a storage value, thus altering the blockchain state. Include - the `x/--execute` flag to submit an extrinsic on-chain. + the `x / --execute` flag to submit an extrinsic on-chain. Example executing the `flip()` message: @@ -152,7 +151,7 @@ Example executing the `flip()` message: pop call contract -p ./my_contract --contract $INSTANTIATED_CONTRACT_ADDRESS --message flip --suri //Alice -x ``` -### E2E testing +## E2E testing For end-to-end testing you will need to have a Substrate node with `pallet contracts`. You do not need to run it in the background since the node is started for each test independently. @@ -168,13 +167,25 @@ If you want to run any other node with `pallet-contracts` you need to change `CO export CONTRACTS_NODE="YOUR_CONTRACTS_NODE_PATH" ``` -Run e2e testing on the smart contract: +Run e2e testing on the Smart Contract: ```sh # Run e2e tests for an existing smart contract pop test contract -p ./my_contract --features e2e-tests ``` +### Pallets + +To create a new Pallet, simply run `pop new pallet`. You will have a new pallet ready for hacking. +To customize the new Pallet you can follow these options: + +```sh +# create a pallet with name `pallet-awesome` in the current working directory +pop new pallet pallet-awesome +# or with options +pop new pallet pallet-awesome --authors Me --description "This pallet oozes awesomeness" --path my_app/pallets +``` + ## Building Pop CLI locally Build the tool locally with all the features: @@ -183,30 +194,18 @@ Build the tool locally with all the features: cargo build --all-features ``` -Build the tool only for parachain functionality: +Build the tool only for Parachain functionality: ```sh cargo build --features parachain ``` -Build the tool only for contracts functionality: +Build the tool only for Smart Contracts functionality: ```sh cargo build --features contract ``` -## Spawn Network using Zombienet - -You can spawn a local network using [zombienet](https://github.com/paritytech/zombienet-sdk) as follows: - -```shell -pop up parachain -f ./tests/zombienet.toml -p https://github.com/r0gue-io/pop-node -``` - -> :information_source: Pop CLI will automatically source the necessary polkadot binaries. Currently, these will be built -> if on a non-linux system. - - ## Testing Pop CLI To test the tool locally. @@ -217,29 +216,29 @@ Run the unit tests: cargo test ``` -Due to the time it can take to build a test or a contract some tests has been separate to the normal testing flow. +Due to the time it can take to build a Parachain or a Smart Contract, some tests have been separated from the normal testing flow. -To run the unit tests that involves building a contract: +To run the unit tests that involves building a Smart Contract: ```sh cargo test --features unit_contract ``` -To run the unit tests that involves building a parachain: +To run the unit tests that involves building a Parachain: ```sh cargo test --features unit_parachain ``` -Then we have some tests that check all the flow is correct: +Then we have some tests that check all the flows are correct: -Run the e2e tests for contracts functionality: +Run the e2e tests for Smart Contracts functionality: ```sh cargo test --features e2e_contract ``` -Run the e2e tests for parachain functionality: +Run the e2e tests for Parachain functionality: ```sh cargo test --features e2e_parachain @@ -255,4 +254,4 @@ cargo test --all-features Pop CLI would not be possible without these awesome crates! - 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! +- [cargo contract](https://github.com/paritytech/cargo-contract) a setup and deployment tool for developing Wasm based Smart Contracts via ink! diff --git a/crates/pop-contracts/Cargo.toml b/crates/pop-contracts/Cargo.toml index 57024a5c..2b2f4665 100644 --- a/crates/pop-contracts/Cargo.toml +++ b/crates/pop-contracts/Cargo.toml @@ -11,16 +11,15 @@ anyhow.workspace = true duct.workspace = true url.workspace = true -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-weights = { version = "29.0.0" } +subxt-signer.workspace = true +subxt.workspace = true +ink_env.workspace = true +sp-core.workspace = true +sp-weights.workspace = true # cargo-contracts -contract-build = { version = "4.0.2" } -contract-extrinsics = { version = "4.0.0-rc.3"} +contract-build.workspace = true +contract-extrinsics.workspace = true [dev-dependencies] tempfile.workspace = true -tokio.workspace = true \ No newline at end of file diff --git a/crates/pop-contracts/README.md b/crates/pop-contracts/README.md index 4f96413d..c7fe3b4c 100644 --- a/crates/pop-contracts/README.md +++ b/crates/pop-contracts/README.md @@ -1,6 +1,8 @@ # pop-contracts -A crate for generating, building, deploying and calling [`ink!`](https://github.com/paritytech/ink) smart contracts. +A crate for generating, building, deploying and calling [`ink!`](https://github.com/paritytech/ink) Smart Contracts. + +> :information_source: A [crates.io](https://crates.io/crates/pop-contracts) version will be available soon! ## Usage @@ -57,7 +59,7 @@ let contract_address = instantiate_smart_contract(instantiate_exec, Weight::fro .map_err(|err| anyhow!("{} {}", "ERROR:", format!("{err:?}")))?; ``` -If you don't know the gas_limit and proof_size you can perform a dry run to estimate gas before instatiante the smart contract: +If you don't know the `gas_limit` and `proof_size`, you can perform a dry run to estimate the gas amount before instatianting the Smart Contract: ```rust use pop_contracts::{ instantiate_smart_contract, dry_run_gas_estimate_instantiate}; @@ -67,7 +69,7 @@ let contract_address = instantiate_smart_contract(instantiate_exec, weight_limi .map_err(|err| anyhow!("{} {}", "ERROR:", format!("{err:?}")))?; ``` -Call a deployed Smart Contract: +Call a deployed (and instantiated) Smart Contract: ```rust use pop_contracts::{set_up_call, CallOpts}; @@ -86,13 +88,13 @@ let call_opts = CallOpts { } let call_exec = set_up_call(call_opts).await?; ``` -For operations that only require reading from the blockchain state. This approach does not require to submit an extrinsic: +For operations that only require reading from the blockchain state, it does not require to submit an extrinsic: ```rust use pop_contracts::dry_run_call; let call_dry_run_result = dry_run_call(&call_exec).await?; ``` -For operations that change a storage value, thus altering the blockchain state: +For operations that change a storage value, thus altering the blockchain state, requires to submit an extrinsic: ```rust use pop_contracts::call_smart_contract; @@ -101,7 +103,7 @@ let call_result = call_smart_contract(call_exec, Weight::from_parts(gas_limit, p .await .map_err(|err| anyhow!("{} {}", "ERROR:", format!("{err:?}")))?; ``` -Same as above if you don't know the gas_limit and proof_size you can perform a dry run to estimate gas before the smart contract: +Same as above, if you don't know the `gas_limit` and `proof_size`, you can perform a dry run to estimate the gas amount before calling the Smart Contract: ```rust use pop_contracts::{ call_smart_contract, dry_run_gas_estimate_call}; @@ -113,4 +115,4 @@ let contract_address = call_smart_contract(call_exec, weight_limit, url) ``` ## Acknowledgements -`pop-contracts` would not be possible without this awesome crate: [`cargo-contract`](https://github.com/paritytech/cargo-contract). \ No newline at end of file +`pop-contracts` would not be possible without the awesome crate: [`cargo-contract`](https://github.com/paritytech/cargo-contract). diff --git a/crates/pop-parachains/Cargo.toml b/crates/pop-parachains/Cargo.toml index 2b4901eb..9b994845 100644 --- a/crates/pop-parachains/Cargo.toml +++ b/crates/pop-parachains/Cargo.toml @@ -14,15 +14,15 @@ tempfile.workspace = true url.workspace = true tokio.workspace = true -askama = "0.12" -regex="1.5.4" -walkdir = "2.4" -indexmap = { version = "2.2"} -toml_edit = { version = "0.22" } -symlink = { version = "0.1" } -reqwest = { version = "0.11" } -serde_json = { version = "1.0"} -serde = { version = "1.0", features = ["derive"] } +askama.workspace = true +regex.workspace = true +walkdir.workspace = true +indexmap.workspace = true +toml_edit.workspace = true +symlink.workspace = true +reqwest.workspace = true +serde_json.workspace = true +serde.workspace = true # Zombienet -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" } \ No newline at end of file +zombienet-sdk.workspace = true +zombienet-support.workspace = true diff --git a/crates/pop-parachains/README.md b/crates/pop-parachains/README.md index 6f857e8b..bf10722d 100644 --- a/crates/pop-parachains/README.md +++ b/crates/pop-parachains/README.md @@ -1,7 +1,8 @@ # pop-parachains -A crate for generating, building and running parachains and pallets. +A crate for generating, building and running Parachains and Pallets. +> :information_source: A [crates.io](https://crates.io/crates/pop-parachains) version will be available soon! ## Usage Generate a new Parachain: @@ -49,7 +50,7 @@ let mut zombienet = Zombienet::new( zombienet.spawn().await? ``` -To download missing binaries before run the network: +To download the missing binaries before starting the network: ```rust // Check if any binaries need to be sourced let missing = zombienet.missing_binaries(); @@ -75,4 +76,4 @@ create_pallet_template(path,pallet_config)?; ``` ## Acknowledgements -`pop-parachains` would not be possible without this awesome crate: [zombienet-sdk](https://github.com/paritytech/zombienet-sdk). \ No newline at end of file +`pop-parachains` would not be possible without the awesome crate: [zombienet-sdk](https://github.com/paritytech/zombienet-sdk). diff --git a/crates/pop-parachains/src/up.rs b/crates/pop-parachains/src/up.rs index 48ea9c10..1ac9697d 100644 --- a/crates/pop-parachains/src/up.rs +++ b/crates/pop-parachains/src/up.rs @@ -17,6 +17,7 @@ use zombienet_sdk::{Network, NetworkConfig, NetworkConfigExt}; use zombienet_support::fs::local::LocalFileSystem; const POLKADOT_SDK: &str = "https://github.com/paritytech/polkadot-sdk"; +const POLKADOT_DEFAULT_VERSION: &str = "v1.10.0"; pub struct Zombienet { /// The cache location, used for caching binaries. @@ -354,11 +355,18 @@ impl Zombienet { } async fn latest_polkadot_release() -> Result { - let repo = Url::parse(POLKADOT_SDK).expect("valid polkadot-sdk repository url"); - let release_tag = GitHub::get_latest_release(&repo).await?; - Ok(release_tag - .strip_prefix("polkadot-") - .map_or_else(|| release_tag.clone(), |v| v.to_string())) + let repo = Url::parse(POLKADOT_SDK).expect("repository url valid"); + // Fetching latest releases + for release in GitHub::get_latest_releases(&repo).await? { + if !release.prerelease && release.tag_name.starts_with("polkadot-v") { + return Ok(release + .tag_name + .strip_prefix("polkadot-") + .map_or_else(|| release.tag_name.clone(), |v| v.to_string())); + } + } + // It should never reach this point, but in case we download a default version of polkadot + Ok(POLKADOT_DEFAULT_VERSION.to_string()) } } diff --git a/crates/pop-parachains/src/utils/git.rs b/crates/pop-parachains/src/utils/git.rs index ef1f293d..264ae487 100644 --- a/crates/pop-parachains/src/utils/git.rs +++ b/crates/pop-parachains/src/utils/git.rs @@ -21,7 +21,7 @@ impl Git { Ok(()) } /// Clone `url` into `target` and degit it - pub(crate) fn clone_and_degit(url: &str, target: &Path) -> Result> { + pub fn clone_and_degit(url: &str, target: &Path) -> Result> { let repo = Repository::clone(url, target)?; // fetch tags from remote @@ -67,27 +67,21 @@ impl Git { } pub struct GitHub; -type Tag = String; impl GitHub { - pub async fn get_latest_release(repo: &Url) -> Result { + pub async fn get_latest_releases(repo: &Url) -> Result> { static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")); let client = reqwest::ClientBuilder::new().user_agent(APP_USER_AGENT).build()?; let response = client .get(format!( - "https://api.github.com/repos/{}/{}/releases/latest", + "https://api.github.com/repos/{}/{}/releases", Self::org(repo)?, Self::name(repo)? )) .send() .await?; - let value = response.json::().await?; - value - .get("tag_name") - .and_then(|v| v.as_str()) - .map(|v| v.to_owned()) - .ok_or(anyhow!("the github release tag was not found")) + Ok(response.json::>().await?) } fn org(repo: &Url) -> Result<&str> { @@ -114,3 +108,9 @@ impl GitHub { format!("{}/releases/download/{tag}/{artifact}", repo.as_str()) } } + +#[derive(serde::Deserialize)] +pub struct Release { + pub(crate) tag_name: String, + pub(crate) prerelease: bool, +}