diff --git a/rs/nervous_system/tools/release-runscript/src/main.rs b/rs/nervous_system/tools/release-runscript/src/main.rs index 35266154870..89f038c9790 100644 --- a/rs/nervous_system/tools/release-runscript/src/main.rs +++ b/rs/nervous_system/tools/release-runscript/src/main.rs @@ -6,13 +6,30 @@ use std::path::PathBuf; use std::process::Command; #[derive(Debug, Parser)] -struct DetermineTargets; +struct DetermineTargets { + #[arg(long)] + commit: String, +} #[derive(Debug, Parser)] -struct RunTests; +struct RunTests { + #[arg(long)] + commit: String, + #[arg(long, num_args = 0..,)] + nns_canisters: Vec, + #[arg(long, num_args = 0..,)] + sns_canisters: Vec, +} #[derive(Debug, Parser)] -struct CreateProposalTexts; +struct CreateProposalTexts { + #[arg(long)] + commit: String, + #[arg(long, num_args = 0..,)] + nns_canisters: Vec, + #[arg(long, num_args = 0..,)] + sns_canisters: Vec, +} #[derive(Debug, Parser)] struct SubmitProposals; @@ -125,10 +142,11 @@ fn run_pick_commit() { ); // Continue to next step. - run_determine_targets(DetermineTargets); + run_determine_targets(DetermineTargets { commit }); } -fn run_determine_targets(_: DetermineTargets) { +fn run_determine_targets(cmd: DetermineTargets) { + let DetermineTargets { commit } = cmd; println!("Now choose which canisters to upgrade. You can run ./testnet/tools/nns-tools/list-new-commits.sh to see the changes for each canister."); // Define the candidate canisters. @@ -165,10 +183,19 @@ fn run_determine_targets(_: DetermineTargets) { ), ); - run_run_tests(RunTests); + run_run_tests(RunTests { + commit, + nns_canisters, + sns_canisters, + }); } -fn run_run_tests(_: RunTests) { +fn run_run_tests(cmd: RunTests) { + let RunTests { + commit, + nns_canisters, + sns_canisters, + } = cmd; print_step(3, "Run NNS Upgrade Tests", "Verify the commit you chose at the previous step has a green check on this page: https://github.com/dfinity/ic/actions/workflows/ci-main.yml?query=branch:master+event:push+is:success @@ -182,26 +209,131 @@ If not, you can also run the upgrade tests manually: - Example: Test at rs/nervous_system/integration_tests/tests/sns_release_qualification.rs", ); - run_create_proposal_texts(CreateProposalTexts); + run_create_proposal_texts(CreateProposalTexts { + commit, + nns_canisters, + sns_canisters, + }); } -fn run_create_proposal_texts(_: CreateProposalTexts) { +fn run_create_proposal_texts(cmd: CreateProposalTexts) { + let CreateProposalTexts { + commit, + nns_canisters, + sns_canisters, + } = cmd; + + // Create proposals directory under ic_dir/proposals/release-{ISO_DATE} + let ic = ic_dir(); + let proposals_dir = ic.join("proposals"); + + // ensure the directory is empty + // check if the directory exists + if proposals_dir.exists() { + println!("Removing existing proposals/ directory"); + std::fs::remove_dir_all(&proposals_dir).unwrap(); + } + std::fs::create_dir_all(&proposals_dir).expect("Failed to create proposals directory"); + + println!( + "Creating proposal texts for {} NNS canisters and {} SNS canisters at commit {}", + nns_canisters.len(), + sns_canisters.len(), + commit + ); + + let mut nns_proposal_text_paths = Vec::new(); + let mut sns_proposal_text_paths = Vec::new(); + + // For each NNS canister, run the prepare-nns-upgrade-proposal-text.sh script and write its output to a file. + for canister in &nns_canisters { + println!("Creating proposal text for NNS canister: {}", canister); + let script = ic.join("testnet/tools/nns-tools/prepare-nns-upgrade-proposal-text.sh"); + let output = Command::new(script) + .arg(canister) + .arg(&commit) + .current_dir(&ic) + .output() + .expect("Failed to run NNS proposal text script"); + if !output.status.success() { + panic!( + "Failed to create proposal text for NNS canister {} due to error: {}", + canister, + String::from_utf8_lossy(&output.stderr) + ); + } + let file_path = proposals_dir.join(format!("nns-{}.md", canister)); + std::fs::write(&file_path, output.stdout).expect("Failed to write NNS proposal file"); + nns_proposal_text_paths.push(file_path); + } + + // For each SNS canister, run the prepare-publish-sns-wasm-proposal-text.sh script. + for canister in &sns_canisters { + println!("Creating proposal text for SNS canister: {}", canister); + let script = ic.join("testnet/tools/nns-tools/prepare-publish-sns-wasm-proposal-text.sh"); + // The SNS script is expected to write directly to the file provided as an argument. + let file_path = proposals_dir.join(format!("sns-{}.md", canister)); + let file_path_str = file_path.to_str().expect("Invalid file path"); + let output = Command::new(script) + .arg(canister) + .arg(&commit) + .arg(file_path_str) + .current_dir(&ic) + .output() + .expect("Failed to run SNS proposal text script"); + if !output.status.success() { + panic!( + "Failed to create proposal text for SNS canister {} due to error: {}", + canister, + String::from_utf8_lossy(&output.stderr) + ); + } + sns_proposal_text_paths.push(file_path); + } + + for proposal_text_path in &nns_proposal_text_paths { + println!( + "Viewing NNS proposal with vscode: {}", + proposal_text_path.display() + ); + let mut cmd = Command::new("code"); + cmd.arg(proposal_text_path); + cmd.current_dir(&ic); + cmd.output() + .expect("Failed to view NNS proposal with vscode"); + } + + for proposal_text_path in &sns_proposal_text_paths { + println!( + "Viewing SNS proposal with vscode: {}", + proposal_text_path.display() + ); + let mut cmd = Command::new("code"); + cmd.arg(proposal_text_path); + cmd.current_dir(&ic); + cmd.output() + .expect("Failed to view SNS proposal with vscode"); + } + + use std::fmt::Write; print_step( 4, "Create Proposal Texts", - "Create proposal text for each canister to be upgraded. -This can be done in parallel with the previous testing step. - -Instructions: -1. Follow format in: testnet/tools/nns-tools/README.md#nnssns-canister-upgrade-proposal-process -2. Name conventions: - - NNS proposals: nns-*.md - - SNS proposals: sns-*.md -3. Organization: - - Put all proposal files in a dedicated directory - - Keep directory clean (nothing else in there) - - This will help with forum post generation later", + &format!("I created proposal texts for each canister to be upgraded in the following directory: {}. +NNS proposal texts: {} +SNS proposal texts: {}", + proposals_dir.display(), + nns_proposal_text_paths.iter().fold(String::new(), |mut acc, path| { + let _ = write!(acc, "\n - {}", path.display()); + acc + }), + sns_proposal_text_paths.iter().fold(String::new(), |mut acc, path| { + let _ = write!(acc, "\n - {}", path.display()); + acc + }) + ) ); + run_submit_proposals(SubmitProposals); }