Skip to content

Commit 5e8981a

Browse files
committed
move bencher check into matrix
1 parent 92ac986 commit 5e8981a

File tree

2 files changed

+85
-34
lines changed

2 files changed

+85
-34
lines changed

.github/workflows/snapshot_benchmark_main.yml

-34
This file was deleted.

crates/xtask/src/main.rs

+85
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::{
88
collections::{HashMap, HashSet},
99
ffi::{OsStr, OsString},
1010
io::Write,
11+
os::unix::process::CommandExt,
1112
path::{Path, PathBuf},
1213
process::Command,
1314
str::FromStr,
@@ -349,6 +350,9 @@ impl App {
349350
Xtasks::Install { binary } => {
350351
cmd.arg("install").arg(binary.as_ref());
351352
}
353+
Xtasks::Bench {} => {
354+
cmd.arg("bench");
355+
}
352356
}
353357

354358
cmd
@@ -634,6 +638,8 @@ enum Xtasks {
634638
/// ]
635639
///
636640
CiMatrix,
641+
/// Runs bencher in dry mode by default if not on the main branch
642+
Bench {},
637643
}
638644

639645
#[derive(Serialize, Clone)]
@@ -709,6 +715,7 @@ impl Xtasks {
709715
bevy_features,
710716
} => Self::codegen(app_settings, output_dir, bevy_features),
711717
Xtasks::Install { binary } => Self::install(app_settings, binary),
718+
Xtasks::Bench {} => Self::bench(app_settings),
712719
}?;
713720

714721
Ok("".into())
@@ -1208,6 +1215,77 @@ impl Xtasks {
12081215
Ok(())
12091216
}
12101217

1218+
fn bench(app_settings: GlobalArgs) -> Result<()> {
1219+
// first of all figure out which branch we're on
1220+
// run // git rev-parse --abbrev-ref HEAD
1221+
1222+
let command = Command::new("git")
1223+
.args(["rev-parse", "--abbrev-ref", "HEAD"])
1224+
.current_dir(Self::workspace_dir(&app_settings).unwrap())
1225+
.output()
1226+
.with_context(|| "Trying to figure out which branch we're on in benchmarking")?;
1227+
let branch = String::from_utf8(command.stdout)?;
1228+
1229+
let is_main = branch.trim() == "main";
1230+
1231+
// figure out if we're running in github actions
1232+
let github_token = std::env::var("GITHUB_TOKEN").ok();
1233+
1234+
// get testbed
1235+
// we want this to be a combination of
1236+
// is_github_ci?
1237+
// OS
1238+
// machine id
1239+
1240+
let os = std::env::consts::OS;
1241+
1242+
let testbed = format!(
1243+
"{os}{}",
1244+
github_token.is_some().then_some("-gha").unwrap_or_default()
1245+
);
1246+
1247+
// also figure out if we're on a fork
1248+
1249+
let token = std::env::var("BENCHER_API_TOKEN").ok();
1250+
1251+
let mut bencher_cmd = Command::new("bencher");
1252+
bencher_cmd
1253+
.stdout(std::process::Stdio::inherit())
1254+
.stderr(std::process::Stdio::inherit())
1255+
.current_dir(Self::workspace_dir(&app_settings).unwrap())
1256+
.arg("run")
1257+
.args(["--project", "bms"])
1258+
.args(["--branch", &format!("\"{branch}\"")])
1259+
.args(["--token", &token.unwrap_or_default()])
1260+
.args(["--testbed", &testbed])
1261+
.args(["--build-time"])
1262+
.args(["--threshold-measure", "latency"])
1263+
.args(["--threshold-test", "t_test"])
1264+
.args(["--threshold-max-sample-size", "64"])
1265+
.args(["--threshold-upper-boundary", "0.99"])
1266+
.args(["--thresholds-reset"])
1267+
.args(["--err"]);
1268+
1269+
if let Some(token) = github_token {
1270+
bencher_cmd.args(["--github-actions", &token]);
1271+
}
1272+
1273+
if !is_main {
1274+
bencher_cmd.args(["--dry-run"]);
1275+
}
1276+
1277+
bencher_cmd
1278+
.args(["--adapter", "rust_criterion"])
1279+
.arg("cargo bench --features=lua54");
1280+
1281+
let out = bencher_cmd.output()?;
1282+
if !out.status.success() {
1283+
bail!("Failed to run bencher: {:?}", out);
1284+
}
1285+
1286+
Ok(())
1287+
}
1288+
12111289
fn set_cargo_coverage_settings() {
12121290
// This makes local dev hell
12131291
// std::env::set_var("CARGO_INCREMENTAL", "0");
@@ -1369,6 +1447,13 @@ impl Xtasks {
13691447
},
13701448
});
13711449

1450+
// also run a benchmark
1451+
// on non-main branches this will just dry run
1452+
output.push(App {
1453+
global_args: default_args.clone(),
1454+
subcmd: Xtasks::Bench {},
1455+
});
1456+
13721457
// and finally run tests with coverage
13731458
output.push(App {
13741459
global_args: default_args

0 commit comments

Comments
 (0)