Ensure a binary is installed, or install it from a `PinnedBinary` installer script. This function checks if the binary is already installed with the correct version. If not, it downloads and executes the pinned installer script. # Arguments `binary_name` - The binary command name (e.g., "codspeed-memtrack", "codspeed-exec-harness") `version` - The version to install (e.g., "4.4.2-alpha.2") `inst
(
binary_name: &str,
version: &str,
installer: PinnedBinary,
)
| 17 | /// * `version` - The version to install (e.g., "4.4.2-alpha.2") |
| 18 | /// * `installer` - The `PinnedBinary` installer to download. |
| 19 | pub async fn ensure_binary_installed( |
| 20 | binary_name: &str, |
| 21 | version: &str, |
| 22 | installer: PinnedBinary, |
| 23 | ) -> Result<()> { |
| 24 | if is_command_installed( |
| 25 | binary_name, |
| 26 | Version::parse(version).context("Invalid version format")?, |
| 27 | ) { |
| 28 | debug!("{binary_name} version {version} is already installed"); |
| 29 | return Ok(()); |
| 30 | } |
| 31 | |
| 32 | debug!("Downloading installer for {binary_name}"); |
| 33 | |
| 34 | // Download the installer script to a temporary file (with sha256 verification) |
| 35 | let temp_file = NamedTempFile::new().context("Failed to create temporary file")?; |
| 36 | download_pinned_file(installer, temp_file.path()).await?; |
| 37 | |
| 38 | // Execute the installer script |
| 39 | let output = Command::new("sh") |
| 40 | .arg(temp_file.path()) |
| 41 | .output() |
| 42 | .context("Failed to execute installer command")?; |
| 43 | |
| 44 | if !output.status.success() { |
| 45 | bail!( |
| 46 | "Failed to install {binary_name} version {version}. Installer exited with output: {output:?}", |
| 47 | ); |
| 48 | } |
| 49 | |
| 50 | if !is_command_installed( |
| 51 | binary_name, |
| 52 | Version::parse(version).context("Invalid version format")?, |
| 53 | ) { |
| 54 | bail!( |
| 55 | "Could not veryfy installation of {binary_name} version {version} after running installer" |
| 56 | ); |
| 57 | } |
| 58 | |
| 59 | info!("Successfully installed {binary_name} version {version}"); |
| 60 | Ok(()) |
| 61 | } |
| 62 | |
| 63 | /// Check if the given command is installed and its version matches the expected version. |
| 64 | /// |
no test coverage detected