diff --git a/dinghy-lib/src/config.rs b/dinghy-lib/src/config.rs index 9fbc478..7156265 100644 --- a/dinghy-lib/src/config.rs +++ b/dinghy-lib/src/config.rs @@ -148,6 +148,16 @@ pub struct SshDeviceConfiguration { pub remote_shell_vars: collections::HashMap, pub install_adhoc_rsync_local_path: Option, pub use_legacy_scp_protocol_for_adhoc_rsync_copy: Option, + /// Shell commands run on the device, in order, immediately before the runnable, in the + /// same remote shell invocation. A failing command does not abort the runnable or affect + /// the reported exit status. + #[serde(default)] + pub pre_run_commands: Vec, + /// Shell commands run on the device, in order, immediately after the runnable exits, in + /// the same remote shell invocation. Runs even if the runnable fails; does not affect the + /// reported exit status, which is always the runnable's own. + #[serde(default)] + pub post_run_commands: Vec, } #[derive(Clone, Serialize, Deserialize, Debug)] diff --git a/dinghy-lib/src/ssh/device.rs b/dinghy-lib/src/ssh/device.rs index 3fe501b..27a1559 100644 --- a/dinghy-lib/src/ssh/device.rs +++ b/dinghy-lib/src/ssh/device.rs @@ -228,14 +228,20 @@ impl Device for SshDevice { log::info!("Install {:?}", build.runnable.id); let (build_bundle, remote_bundle) = self.install_app(&project, &build)?; log::debug!("Installed {:?}", build.runnable.id); - let command = format!( - "cd '{}' ; {} DINGHY=1 LD_LIBRARY_PATH=\"{}:$LD_LIBRARY_PATH\" {} {}", - path_to_str(&remote_bundle.bundle_dir)?, + let run = format!( + "{} DINGHY=1 LD_LIBRARY_PATH=\"{}:$LD_LIBRARY_PATH\" {} {}", envs.join(" "), path_to_str(&remote_bundle.lib_dir)?, path_to_str(&remote_bundle.bundle_exe)?, args.join(" ") ); + let mut parts = vec![format!("cd '{}'", path_to_str(&remote_bundle.bundle_dir)?)]; + parts.extend(self.conf.pre_run_commands.iter().cloned()); + parts.push(run); + parts.push("RC=$?".to_string()); + parts.extend(self.conf.post_run_commands.iter().cloned()); + parts.push("exit $RC".to_string()); + let command = parts.join(" ; "); log::trace!("Ssh command: {}", command); log::info!("Run {} on {}", build.runnable.id, self.id,); if get_current_verbosity() < 1 {