mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 13:21:10 +00:00
update artifacts script (#1392)
This commit is contained in:
@@ -40,7 +40,10 @@ jobs:
|
|||||||
# - a polkadot.rs file from the full metadata that is checked in integration tests
|
# - a polkadot.rs file from the full metadata that is checked in integration tests
|
||||||
# - a polkadot.json in the `artifacts/demo_chain_specs` directory
|
# - a polkadot.json in the `artifacts/demo_chain_specs` directory
|
||||||
- name: Fetch Artifacts
|
- name: Fetch Artifacts
|
||||||
run: cargo build --bin artifacts
|
run: cargo run --bin artifacts
|
||||||
|
|
||||||
|
- name: Delete substrate node binary
|
||||||
|
run: rm ./substrate-node
|
||||||
|
|
||||||
- name: Create Pull Request
|
- name: Create Pull Request
|
||||||
uses: peter-evans/create-pull-request@v5
|
uses: peter-evans/create-pull-request@v5
|
||||||
|
|||||||
@@ -20,70 +20,60 @@ fn main() {
|
|||||||
let node_url = format!("ws://127.0.0.1:{}", proc.ws_port());
|
let node_url = format!("ws://127.0.0.1:{}", proc.ws_port());
|
||||||
|
|
||||||
// Get the full metadata from the spawned substrate node
|
// Get the full metadata from the spawned substrate node
|
||||||
Command::make(&format!(
|
run_cmd(
|
||||||
"cargo run --bin subxt metadata --version 15 --url {node_url}"
|
&format!("cargo run --bin subxt metadata --version 15 --url {node_url}"),
|
||||||
))
|
Some("artifacts/polkadot_metadata_full.scale"),
|
||||||
.out("artifacts/polkadot_metadata_full.scale");
|
);
|
||||||
|
|
||||||
// Use it to generate polkadot.rs
|
// Use it to generate polkadot.rs
|
||||||
Command::make("cargo run --bin subxt codegen --file artifacts/polkadot_metadata_full.scale")
|
run_cmd(
|
||||||
.pipe("rustfmt")
|
"cargo run --bin subxt codegen --file artifacts/polkadot_metadata_full.scale",
|
||||||
.out("testing/integration-tests/src/full_client/codegen/polkadot.rs");
|
Some("testing/integration-tests/src/full_client/codegen/polkadot.rs"),
|
||||||
|
);
|
||||||
|
run_cmd(
|
||||||
|
"rustfmt testing/integration-tests/src/full_client/codegen/polkadot.rs",
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
// Generate a metadata file that only contains a few pallets that we need for our examples.
|
// Generate a metadata file that only contains a few pallets that we need for our examples.
|
||||||
Command::make(r#"cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets "Balances,Staking,System,Multisig,Timestamp,ParaInherent""#)
|
run_cmd(
|
||||||
.out("artifacts/polkadot_metadata_small.scale");
|
r#"cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets "Balances,Staking,System,Multisig,Timestamp,ParaInherent""#,
|
||||||
|
Some("artifacts/polkadot_metadata_small.scale"),
|
||||||
|
);
|
||||||
|
|
||||||
// Generate a metadata file that contains no pallets
|
// Generate a metadata file that contains no pallets
|
||||||
Command::make(r#"cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets """#)
|
run_cmd(
|
||||||
.out("artifacts/polkadot_metadata_tiny.scale");
|
r#"cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets """#,
|
||||||
|
Some("artifacts/polkadot_metadata_tiny.scale"),
|
||||||
|
);
|
||||||
|
|
||||||
// Generate a metadata file that only contains some custom metadata
|
// Generate a metadata file that only contains some custom metadata
|
||||||
Command::make("cargo run --bin generate-custom-metadata")
|
run_cmd(
|
||||||
.out("artifacts/metadata_with_custom_values.scale");
|
"cargo run --bin generate-custom-metadata",
|
||||||
|
Some("artifacts/metadata_with_custom_values.scale"),
|
||||||
|
);
|
||||||
|
|
||||||
// Generate the polkadot chain spec.
|
// Generate the polkadot chain spec.
|
||||||
Command::make("cargo run --features chain-spec-pruning --bin subxt chain-spec --url wss://rpc.polkadot.io:443 --output-file artifacts/demo_chain_specs/polkadot.json --state-root-hash --remove-substitutes").spawn().unwrap().wait().unwrap();
|
run_cmd("cargo run --features chain-spec-pruning --bin subxt chain-spec --url wss://rpc.polkadot.io:443 --output-file artifacts/demo_chain_specs/polkadot.json --state-root-hash --remove-substitutes", None);
|
||||||
}
|
}
|
||||||
|
|
||||||
trait CommandT {
|
fn run_cmd(cmd: &str, out_path: Option<&str>) {
|
||||||
/// Creates a new command, parsing the arg_string provided.
|
println!("Running Command: {cmd}");
|
||||||
fn make(arg_string: &str) -> Self;
|
// Note: simple space splitting, no fancy parsing of e.g. quotes surrounding whitespace.
|
||||||
|
let mut parts = cmd.split(' ');
|
||||||
/// Pipes the output of the current command to the next command.
|
let program = parts.next().expect("no program in command string");
|
||||||
fn pipe(self, arg_string: &str) -> Self;
|
let mut command = Command::new(program);
|
||||||
|
for e in parts {
|
||||||
/// Writes bytes from stdout to a new file at path.
|
command.arg(e);
|
||||||
fn out(self, path: &str);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandT for Command {
|
|
||||||
fn make(arg_string: &str) -> Self {
|
|
||||||
// Note: simple space splitting, no fancy parsing of e.g. quotes surrounding whitespace.
|
|
||||||
let mut parts = arg_string.split(' ');
|
|
||||||
let program = parts.next().expect("no program in command string");
|
|
||||||
let mut command = Command::new(program);
|
|
||||||
for e in parts {
|
|
||||||
command.arg(e);
|
|
||||||
}
|
|
||||||
command
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pipe(mut self, arg_string: &str) -> Self {
|
if let Some(out_path) = out_path {
|
||||||
// execute self
|
let file = File::create(out_path).unwrap();
|
||||||
let old_cmd = self.stdout(Stdio::piped()).spawn().unwrap();
|
command.stdout(Stdio::from(file));
|
||||||
let mut next_cmd = Self::make(arg_string);
|
|
||||||
next_cmd.stdin(Stdio::from(old_cmd.stdout.unwrap()));
|
|
||||||
next_cmd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn out(mut self, path: &str) {
|
let status = command.spawn().unwrap().wait().unwrap();
|
||||||
dbg!(path);
|
if !status.success() {
|
||||||
let file = File::create(path).unwrap();
|
panic!("Command `{cmd}` failed with status: {status}")
|
||||||
self.stdout(Stdio::from(file))
|
|
||||||
.spawn()
|
|
||||||
.unwrap()
|
|
||||||
.wait()
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user