Skip to content

Commit 9403273

Browse files
ci: upload benchmark input files
1 parent 050880e commit 9403273

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

crates/bench_tools/src/gcs.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::path::Path;
2+
use std::process::Command;
3+
4+
/// Default GCS bucket for benchmarks.
5+
pub const BENCHMARKS_BUCKET: &str = "apollo_benchmarks";
6+
7+
/// Uploads all files from a local directory to Google Cloud Storage.
8+
///
9+
/// Uses gcloud CLI to upload files. Before running, authenticate with:
10+
/// `gcloud auth application-default login`
11+
///
12+
/// Files are uploaded to: `gs://{BENCHMARKS_BUCKET}/{benchmark_name}/input/`
13+
pub fn upload_inputs(benchmark_name: &str, input_dir: &Path) {
14+
println!(
15+
"Uploading inputs from {} to gs://{}/{}/input/",
16+
input_dir.display(),
17+
BENCHMARKS_BUCKET,
18+
benchmark_name
19+
);
20+
21+
let source = format!("{}/*", input_dir.display());
22+
let dest = format!("gs://{}/{}/input/", BENCHMARKS_BUCKET, benchmark_name);
23+
24+
// Use gcloud storage cp command to upload files.
25+
let output = Command::new("gcloud")
26+
.args(["storage", "cp", "-r", &source, &dest])
27+
.output()
28+
.expect("Failed to upload inputs to GCS");
29+
30+
if !output.status.success() {
31+
let stderr = String::from_utf8_lossy(&output.stderr);
32+
panic!("Failed to upload inputs to GCS: {}", stderr);
33+
}
34+
35+
println!("{}", String::from_utf8_lossy(&output.stdout).trim());
36+
println!("Input files uploaded successfully!");
37+
}

crates/bench_tools/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#[cfg(test)]
22
pub(crate) mod benches;
3+
pub mod gcs;
34
pub mod types;

crates/bench_tools/src/main.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
use bench_tools::types::benchmark_config::{find_benchmarks_by_package, BENCHMARKS};
1+
use std::path::PathBuf;
2+
3+
use bench_tools::gcs;
4+
use bench_tools::types::benchmark_config::{
5+
find_benchmark_by_name,
6+
find_benchmarks_by_package,
7+
BENCHMARKS,
8+
};
29
use clap::{Parser, Subcommand};
310

411
#[derive(Parser)]
@@ -25,6 +32,15 @@ enum Commands {
2532
#[arg(short, long)]
2633
package: Option<String>,
2734
},
35+
/// Upload benchmark input files to GCS.
36+
UploadInputs {
37+
/// Benchmark name.
38+
#[arg(long)]
39+
benchmark: String,
40+
/// Local directory containing input files.
41+
#[arg(long)]
42+
input_dir: String,
43+
},
2844
}
2945

3046
fn main() {
@@ -59,5 +75,16 @@ fn main() {
5975
}
6076
}
6177
},
78+
Commands::UploadInputs { benchmark, input_dir } => {
79+
// Validate benchmark exists.
80+
if find_benchmark_by_name(&benchmark).is_none() {
81+
panic!("Unknown benchmark: {}", benchmark);
82+
}
83+
84+
let input_path = PathBuf::from(&input_dir);
85+
gcs::upload_inputs(&benchmark, &input_path);
86+
87+
println!("Input files uploaded successfully!");
88+
}
6289
}
6390
}

0 commit comments

Comments
 (0)