Skip to content

Commit 2e6702e

Browse files
ci: upload benchmark input files
1 parent fa36e02 commit 2e6702e

File tree

6 files changed

+71
-2
lines changed

6 files changed

+71
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ url = "2.5.0"
383383
validator = "0.12"
384384
void = "1.0.2"
385385
waker-fn = "1.2.0"
386+
walkdir = "2.5"
386387
workspace_tests.path = "workspace_tests"
387388
zstd = "0.13.1"
388389

crates/bench_tools/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ workspace = true
1010
clap = { workspace = true, features = ["derive"] }
1111
criterion.workspace = true
1212
serde = { workspace = true, features = ["derive"] }
13+
tokio = { workspace = true, features = ["full"] }
1314

1415
[dev-dependencies]
1516
glob.workspace = true

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+
3+
/// Default GCS bucket for benchmarks.
4+
pub const BENCHMARKS_BUCKET: &str = "benchmarks_ci";
5+
6+
/// Uploads all files from a local directory to Google Cloud Storage.
7+
///
8+
/// Uses gcloud CLI to upload files. Before running, authenticate with:
9+
/// `gcloud auth application-default login`
10+
///
11+
/// Files are uploaded to: `gs://{BENCHMARKS_BUCKET}/{benchmark_name}/input/`
12+
pub async fn upload_inputs(benchmark_name: &str, input_dir: &Path) {
13+
println!(
14+
"Uploading inputs from {} to gs://{}/{}/input/",
15+
input_dir.display(),
16+
BENCHMARKS_BUCKET,
17+
benchmark_name
18+
);
19+
20+
let source = format!("{}/*", input_dir.display());
21+
let dest = format!("gs://{}/{}/input/", BENCHMARKS_BUCKET, benchmark_name);
22+
23+
// Use gcloud storage cp command to upload files.
24+
let output = tokio::process::Command::new("gcloud")
25+
.args(["storage", "cp", "-r", &source, &dest])
26+
.output()
27+
.await
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: 30 additions & 2 deletions
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,9 +32,19 @@ 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

30-
fn main() {
46+
#[tokio::main]
47+
async fn main() {
3148
let cli = Cli::parse();
3249
match cli.command {
3350
Commands::Run { package: _, out: _ } => {
@@ -59,5 +76,16 @@ fn main() {
5976
}
6077
}
6178
},
79+
Commands::UploadInputs { benchmark, input_dir } => {
80+
// Validate benchmark exists
81+
if find_benchmark_by_name(&benchmark).is_none() {
82+
panic!("Unknown benchmark: {}", benchmark);
83+
}
84+
85+
let input_path = PathBuf::from(&input_dir);
86+
gcs::upload_inputs(&benchmark, &input_path).await;
87+
88+
println!("Input files uploaded successfully!");
89+
}
6290
}
6391
}

0 commit comments

Comments
 (0)