-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(release-runscript): Ask user if they want to retry if a script f…
…ails (#4007) This prevents a situation where they then need to go annoyingly restart the whole process Marked as draft for now to prevent accidental merging until the previous PR in this chain is merged. [← Previous PR](#4004)
- Loading branch information
Showing
5 changed files
with
117 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::utils::input_yes_or_no; | ||
use anyhow::Result; | ||
use itertools::Itertools; | ||
use std::path::PathBuf; | ||
use std::process::{Command, Stdio}; | ||
|
||
pub(crate) fn run_script( | ||
script: PathBuf, | ||
args: &[&str], | ||
cwd: &PathBuf, | ||
) -> Result<std::process::Output> { | ||
loop { | ||
let output = Command::new(&script).args(args).current_dir(cwd).output()?; | ||
|
||
if output.status.success() { | ||
return Ok(output); | ||
} else { | ||
let command_str = format!( | ||
"{} {}", | ||
script.display(), | ||
args.iter().map(|s| format!("\"{}\"", s)).join(" ") | ||
); | ||
let stdout = String::from_utf8_lossy(&output.stdout); | ||
let stderr = String::from_utf8_lossy(&output.stderr); | ||
eprintln!("Script failed: {}", stderr); | ||
eprintln!("Failed to run command: {}", command_str); | ||
if input_yes_or_no("Do you want to try again?", true)? { | ||
continue; | ||
} else { | ||
return Err(anyhow::anyhow!("{}\n{}", stdout, stderr) | ||
.context(format!("Failed to run command: {}", command_str))); | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub(crate) fn run_script_in_current_process( | ||
script: PathBuf, | ||
args: &[&str], | ||
cwd: &PathBuf, | ||
) -> Result<std::process::Output> { | ||
loop { | ||
let output = Command::new(&script) | ||
.args(args) | ||
.current_dir(cwd) | ||
.stdin(Stdio::inherit()) | ||
.stdout(Stdio::inherit()) | ||
.stderr(Stdio::inherit()) | ||
.output()?; | ||
|
||
if output.status.success() { | ||
return Ok(output); | ||
} else { | ||
let command_str = format!( | ||
"{} {}", | ||
script.display(), | ||
args.iter().map(|s| format!("\"{}\"", s)).join(" ") | ||
); | ||
// we can't read stdout or stderr here because it's piped to the current process | ||
eprintln!("Script failed :("); | ||
eprintln!("Failed to run command: {}", command_str); | ||
if input_yes_or_no("Do you want to try again?", true)? { | ||
continue; | ||
} else { | ||
return Err(anyhow::anyhow!("Failed to run command: {}", command_str)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters