Add a key for running remote topgrades

This commit is contained in:
Roey Darwish Dror
2019-06-05 14:15:45 +03:00
parent 232c886be6
commit 4a7218293b
5 changed files with 37 additions and 3 deletions

View File

@@ -154,3 +154,8 @@ The configuration should be placed in the following paths depending by the opera
* **macOS** - `~/Library/Preferences/topgrade.toml`
* **Windows** - `%APPDATA%/topgrade.toml`
* **Other Unix systems** - `~/.config/topgrade.toml`
## Remote execution
You can specify a key called `remote_topgrades` in the configuration file. This key should contain a
list of hostnames that have topgrade installed on them. Topgrade will execute Topgrades on these
remote hosts.

View File

@@ -69,6 +69,7 @@ pub struct ConfigFile {
commands: Option<Commands>,
git_repos: Option<Vec<String>>,
disable: Option<Vec<Step>>,
remote_topgrades: Option<Vec<String>>,
}
impl ConfigFile {
@@ -198,4 +199,9 @@ impl Config {
pub fn verbose(&self) -> bool {
self.opt.verbose
}
/// List of remote hosts to run Topgrade in
pub fn remote_topgrades(&self) -> &Option<Vec<String>> {
&self.config_file.remote_topgrades
}
}

View File

@@ -1,5 +1,4 @@
#![allow(clippy::cognitive_complexity)]
mod config;
mod ctrlc;
mod error;
@@ -132,6 +131,17 @@ fn run() -> Result<(), Error> {
#[cfg(windows)]
execute(&mut report, "WSL", || windows::run_wsl_topgrade(run_type), true)?;
if let Some(topgrades) = config.remote_topgrades() {
for remote_topgrade in topgrades {
execute(
&mut report,
remote_topgrade,
|| generic::run_remote_topgrade(run_type, remote_topgrade),
config.no_retry(),
)?;
}
}
#[cfg(target_os = "linux")]
let distribution = linux::Distribution::detect();

View File

@@ -136,3 +136,18 @@ pub fn run_composer_update(base_dirs: &BaseDirs, run_type: RunType) -> Result<()
Ok(())
}
pub fn run_remote_topgrade(run_type: RunType, hostname: &str) -> Result<(), Error> {
let ssh = utils::require("ssh")?;
run_type
.execute(&ssh)
.args(&[
"-t",
hostname,
"env",
&format!("TOPGRADE_PREFIX={}", hostname),
"topgrade",
])
.check_run()
}

View File

@@ -89,8 +89,6 @@ pub fn run_wsl_topgrade(run_type: RunType) -> Result<(), Error> {
.check_output()
.map_err(|_| ErrorKind::SkipStep)?;
print_separator("WSL");
run_type
.execute(&wsl)
.args(&["bash", "-c"])