Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runner): support debian 11 and 12 #17

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/runner/check_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ use std::process::Command;

use crate::prelude::*;

/// Returns the OS and version of the system
///
/// ## Example output
/// ```
/// ("Ubuntu", "20.04")
/// ("Ubuntu", "22.04")
/// ("Debian", "11")
/// ("Debian", "12")
/// ```
fn get_os_details() -> Result<(String, String)> {
let lsb_output = Command::new("lsb_release")
.args(["-i", "-r", "-s"])
Expand Down Expand Up @@ -36,20 +45,28 @@ fn get_arch() -> Result<String> {
Ok(output_str.trim().to_string())
}

#[derive(Eq, PartialEq, Hash)]
pub struct SystemInfo {
pub os: String,
pub os_version: String,
pub arch: String,
}

/// Checks if the system is supported
///
/// Supported systems:
/// - Ubuntu 20.04 on amd64
/// - Ubuntu 22.04 on amd64
/// - Debian 11 on amd64
/// - Debian 12 on amd64
pub fn check_system() -> Result<SystemInfo> {
let (os, os_version) = get_os_details()?;
debug!("OS: {}, Version: {}", os, os_version);
if os != "Ubuntu" {
bail!("Only Ubuntu is supported at the moment");
}
if !["20.04", "22.04"].contains(&os_version.as_str()) {
bail!("Only Ubuntu 20.04 and 22.04 are supported at the moment");
match (os.as_str(), os_version.as_str()) {
("Ubuntu", "20.04") | ("Ubuntu", "22.04") | ("Debian", "11") | ("Debian", "12") => (),
("Ubuntu", _) => bail!("Only Ubuntu 20.04 and 22.04 are supported at the moment"),
("Debian", _) => bail!("Only Debian 11 and 12 are supported at the moment"),
_ => bail!("Only Ubuntu and Debian are supported at the moment"),
}
let arch = get_arch()?;
debug!("Arch: {}", arch);
Expand Down
82 changes: 81 additions & 1 deletion src/runner/setup.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::{
collections::HashMap,
env,
process::{Command, Stdio},
};

use lazy_static::lazy_static;
use url::Url;

use super::{check_system::SystemInfo, helpers::download_file::download_file};
Expand Down Expand Up @@ -37,9 +39,66 @@ fn run_with_sudo(command_args: &[&str]) -> Result<()> {
Ok(())
}

lazy_static! {
static ref SYSTEM_INFO_TO_CODSPEED_VALGRIND_FILENAME: HashMap<SystemInfo, String> = {
let mut m = HashMap::new();
m.insert(
SystemInfo {
os: "Ubuntu".to_string(),
os_version: "20.04".to_string(),
arch: "amd64".to_string(),
},
format!(
"valgrind_{}_ubuntu-{}_amd64.deb",
VALGRIND_CODSPEED_VERSION, "20.04"
),
);
m.insert(
SystemInfo {
os: "Ubuntu".to_string(),
os_version: "22.04".to_string(),
arch: "amd64".to_string(),
},
format!(
"valgrind_{}_ubuntu-{}_amd64.deb",
VALGRIND_CODSPEED_VERSION, "22.04"
),
);
m.insert(
SystemInfo {
os: "Debian".to_string(),
os_version: "11".to_string(),
arch: "amd64".to_string(),
},
format!(
"valgrind_{}_ubuntu-{}_amd64.deb",
VALGRIND_CODSPEED_VERSION, "20.04"
),
);
m.insert(
SystemInfo {
os: "Debian".to_string(),
os_version: "12".to_string(),
arch: "amd64".to_string(),
},
format!(
"valgrind_{}_ubuntu-{}_amd64.deb",
VALGRIND_CODSPEED_VERSION, "20.04"
),
);
m
};
}

async fn install_valgrind(system_info: &SystemInfo) -> Result<()> {
debug!("Installing valgrind");
let valgrind_deb_url = format!("https://github.com/CodSpeedHQ/valgrind-codspeed/releases/download/{}/valgrind_{}_ubuntu-{}_amd64.deb", VALGRIND_CODSPEED_VERSION, VALGRIND_CODSPEED_VERSION, system_info.os_version);
let valgrind_deb_url = format!(
"https://github.com/CodSpeedHQ/valgrind-codspeed/releases/download/{}/{}",
VALGRIND_CODSPEED_VERSION,
SYSTEM_INFO_TO_CODSPEED_VALGRIND_FILENAME
.get(system_info)
.context("Unsupported system")?
);
let deb_path = env::temp_dir().join("valgrind-codspeed.deb");
download_file(&Url::parse(valgrind_deb_url.as_str()).unwrap(), &deb_path).await?;

Expand Down Expand Up @@ -85,3 +144,24 @@ pub async fn setup(system_info: &SystemInfo, config: &Config) -> Result<()> {
info!("Environment ready");
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_system_info_to_codspeed_valgrind_version() {
let system_info = SystemInfo {
os: "Debian".to_string(),
os_version: "11".to_string(),
arch: "amd64".to_string(),
};
assert_eq!(
SYSTEM_INFO_TO_CODSPEED_VALGRIND_FILENAME[&system_info],
format!(
"valgrind_{}_ubuntu-{}_amd64.deb",
VALGRIND_CODSPEED_VERSION, "20.04"
)
);
}
}
Loading