Skip to content

Commit f53fd04

Browse files
authored
feat(nns-tools): Release runscript automatically grabs the latest commit (dfinity#3713)
After this PR, the runscript acquires the latest commit and shows it to you, saving you from running the command yourself. [← Previous PR](dfinity#3712) | [Next PR →](dfinity#3714)
1 parent 6feb282 commit f53fd04

File tree

1 file changed

+57
-13
lines changed
  • rs/nervous_system/tools/release-runscript/src

1 file changed

+57
-13
lines changed

rs/nervous_system/tools/release-runscript/src/main.rs

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use anyhow::{bail, Result};
22
use clap::{Parser, Subcommand};
33
use colored::*;
44
use std::io::{self, Write};
5+
use std::path::PathBuf;
6+
use std::process::Command;
57

68
#[derive(Debug, Parser)]
79
struct DetermineTargets;
@@ -60,6 +62,12 @@ struct ReleaseRunscript {
6062
step: Option<Step>,
6163
}
6264

65+
fn ic_dir() -> PathBuf {
66+
let workspace_dir =
67+
std::env::var("BUILD_WORKSPACE_DIRECTORY").expect("BUILD_WORKSPACE_DIRECTORY not set");
68+
PathBuf::from(&workspace_dir)
69+
}
70+
6371
fn main() -> Result<()> {
6472
let args = match ReleaseRunscript::try_parse_from(std::env::args()) {
6573
Ok(args) => args,
@@ -86,20 +94,39 @@ fn main() -> Result<()> {
8694
}
8795

8896
fn run_pick_commit() {
89-
print_step(1,
90-
"Pick Release Candidate Commit",
91-
"Run `./testnet/tools/nns-tools/cmd.sh latest_commit_with_prebuilt_artifacts`.
92-
If you would like to pick a different commit, follow these steps:
93-
2. Go to https://github.com/dfinity/ic/actions/workflows/ci-main.yml?query=branch%3Amaster+event%3Apush+is%3Asuccess
94-
3. Find a recent commit with passing CI Main in the master branch
95-
4. Record this commit (e.g., post to Slack)
96-
97-
Pre-built artifacts check:
98-
- Install aws tool if needed
99-
- List available files:
100-
aws s3 ls --no-sign-request s3://dfinity-download-public/ic/${COMMIT}/canisters/
101-
- Note: Our tools download from the analogous https://download.dfinity.systems/... URL",
97+
// Get the ic directory.
98+
let ic = ic_dir();
99+
100+
// Build the absolute path to the cmd.sh script.
101+
let cmd_path = ic.join("testnet/tools/nns-tools/cmd.sh");
102+
103+
// Run the command with the required argument.
104+
let output = Command::new(cmd_path)
105+
.arg("latest_commit_with_prebuilt_artifacts")
106+
.current_dir(&ic)
107+
.output()
108+
.unwrap();
109+
110+
let commit = if output.status.success() {
111+
let commit = String::from_utf8_lossy(&output.stdout).trim().to_string();
112+
println!("A commit with prebuilt artifacts was found with the following command: `./testnet/tools/nns-tools/cmd.sh latest_commit_with_prebuilt_artifacts`.");
113+
input_with_default("Commit to release", &commit)
114+
} else {
115+
println!(
116+
"Automatically determining the commit hash failed with error:\n{}",
117+
String::from_utf8_lossy(&output.stderr)
118+
);
119+
// get input from user for the commit
120+
input("Enter the commit hash, which you can find by running `./testnet/tools/nns-tools/cmd.sh latest_commit_with_prebuilt_artifacts`")
121+
};
122+
123+
print_step(
124+
1,
125+
"Pick Release Candidate Commit",
126+
&format!("Chosen commit: {}", commit),
102127
);
128+
129+
// Continue to next step.
103130
run_determine_targets(DetermineTargets);
104131
}
105132

@@ -322,3 +349,20 @@ fn print_step(number: usize, title: &str, description: &str) {
322349
io::stdin().read_line(&mut input).unwrap();
323350
print!("\x1B[2J\x1B[1;1H");
324351
}
352+
353+
fn input(text: &str) -> String {
354+
print!("{}: ", text);
355+
std::io::stdout().flush().unwrap();
356+
let mut input = String::new();
357+
io::stdin().read_line(&mut input).unwrap();
358+
input.trim().to_string()
359+
}
360+
361+
fn input_with_default(text: &str, default: &str) -> String {
362+
let input = input(&format!("{} ({})", text, default));
363+
if input.is_empty() {
364+
default.to_string()
365+
} else {
366+
input
367+
}
368+
}

0 commit comments

Comments
 (0)