-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmod.rs
More file actions
103 lines (88 loc) · 3.08 KB
/
mod.rs
File metadata and controls
103 lines (88 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::api_client::CodSpeedAPIClient;
use crate::binary_installer::ensure_binary_installed;
use crate::config::CodSpeedConfig;
use crate::executor;
use crate::prelude::*;
use crate::project_config::ProjectConfig;
use crate::project_config::merger::ConfigMerger;
use crate::run::uploader::UploadResult;
use clap::Args;
use std::path::Path;
mod poll_results;
/// We temporarily force this name for all exec runs
pub const DEFAULT_REPOSITORY_NAME: &str = "local-runs";
pub const EXEC_HARNESS_COMMAND: &str = "exec-harness";
const EXEC_HARNESS_VERSION: &str = "1.0.0";
#[derive(Args, Debug)]
pub struct ExecArgs {
#[command(flatten)]
pub shared: crate::run::ExecAndRunSharedArgs,
#[command(flatten)]
pub walltime_args: exec_harness::walltime::WalltimeExecutionArgs,
/// Optional benchmark name (defaults to command filename)
#[arg(long)]
pub name: Option<String>,
/// The command to execute with the exec harness
pub command: Vec<String>,
}
impl ExecArgs {
/// Merge CLI args with project config if available
///
/// CLI arguments take precedence over config values.
pub fn merge_with_project_config(mut self, project_config: Option<&ProjectConfig>) -> Self {
if let Some(project_config) = project_config {
// Merge shared args
self.shared =
ConfigMerger::merge_shared_args(&self.shared, project_config.options.as_ref());
// Merge walltime args
self.walltime_args = ConfigMerger::merge_walltime_options(
&self.walltime_args,
project_config
.options
.as_ref()
.and_then(|o| o.walltime.as_ref()),
);
}
self
}
}
pub async fn run(
args: ExecArgs,
api_client: &CodSpeedAPIClient,
codspeed_config: &CodSpeedConfig,
project_config: Option<&ProjectConfig>,
setup_cache_dir: Option<&Path>,
) -> Result<()> {
let merged_args = args.merge_with_project_config(project_config);
let config = crate::executor::Config::try_from(merged_args)?;
let mut execution_context = executor::ExecutionContext::try_from((config, codspeed_config))?;
debug!("config: {:#?}", execution_context.config);
let executor = executor::get_executor_from_mode(
&execution_context.config.mode,
executor::ExecutorCommand::Exec,
);
let get_exec_harness_installer_url = || {
format!(
"https://github.com/CodSpeedHQ/runner/releases/download/exec-harness-v{EXEC_HARNESS_VERSION}/exec-harness-installer.sh"
)
};
// Ensure the exec-harness is installed
ensure_binary_installed(
EXEC_HARNESS_COMMAND,
EXEC_HARNESS_VERSION,
get_exec_harness_installer_url,
)
.await?;
let poll_results_fn = async |upload_result: &UploadResult| {
poll_results::poll_results(api_client, upload_result).await
};
executor::execute_benchmarks(
executor.as_ref(),
&mut execution_context,
setup_cache_dir,
poll_results_fn,
api_client,
)
.await?;
Ok(())
}