diff --git a/.github/workflows/bevy_mod_scripting.yml b/.github/workflows/bevy_mod_scripting.yml index 4b4e3490c0..e5afebca0c 100644 --- a/.github/workflows/bevy_mod_scripting.yml +++ b/.github/workflows/bevy_mod_scripting.yml @@ -72,6 +72,9 @@ jobs: echo "Convert to single line JSON" jq -c . matrix.json > matrix-one-line.json echo "matrix=$(cat matrix-one-line.json)" >> $GITHUB_OUTPUT +env: + BENCHER_API_TOKEN: ${{ secrets.BENCHER_API_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} check: needs: [check-needs-run, generate-job-matrix] diff --git a/.github/workflows/snapshot_benchmark_main.yml b/.github/workflows/snapshot_benchmark_main.yml deleted file mode 100644 index 283ffbdb2c..0000000000 --- a/.github/workflows/snapshot_benchmark_main.yml +++ /dev/null @@ -1,32 +0,0 @@ -on: - push: - branches: main - -jobs: - benchmark_base_branch: - name: Continuous Benchmarking with Bencher - permissions: - checks: write - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Run Xtask initializer - run: | - cargo xtask init - - uses: bencherdev/bencher@main - - name: Track base branch benchmarks with Bencher - run: | - bencher run \ - --project bms \ - --token '${{ secrets.BENCHER_API_TOKEN }}' \ - --branch main \ - --testbed ubuntu-latest \ - --threshold-measure latency \ - --threshold-test t_test \ - --threshold-max-sample-size 64 \ - --threshold-upper-boundary 0.99 \ - --thresholds-reset \ - --err \ - --adapter json \ - --github-actions '${{ secrets.GITHUB_TOKEN }}' \ - bencher run --adapter rust_criterion "cargo bench --features lua54" \ No newline at end of file diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rs index 77713de1c9..72bfcba346 100644 --- a/crates/xtask/src/main.rs +++ b/crates/xtask/src/main.rs @@ -349,6 +349,9 @@ impl App { Xtasks::Install { binary } => { cmd.arg("install").arg(binary.as_ref()); } + Xtasks::Bench {} => { + cmd.arg("bench"); + } } cmd @@ -634,6 +637,8 @@ enum Xtasks { /// ] /// CiMatrix, + /// Runs bencher in dry mode by default if not on the main branch + Bench {}, } #[derive(Serialize, Clone)] @@ -709,6 +714,7 @@ impl Xtasks { bevy_features, } => Self::codegen(app_settings, output_dir, bevy_features), Xtasks::Install { binary } => Self::install(app_settings, binary), + Xtasks::Bench {} => Self::bench(app_settings), }?; Ok("".into()) @@ -1208,6 +1214,77 @@ impl Xtasks { Ok(()) } + fn bench(app_settings: GlobalArgs) -> Result<()> { + // first of all figure out which branch we're on + // run // git rev-parse --abbrev-ref HEAD + + let command = Command::new("git") + .args(["rev-parse", "--abbrev-ref", "HEAD"]) + .current_dir(Self::workspace_dir(&app_settings).unwrap()) + .output() + .with_context(|| "Trying to figure out which branch we're on in benchmarking")?; + let branch = String::from_utf8(command.stdout)?; + + let is_main = branch.trim() == "main"; + + // figure out if we're running in github actions + let github_token = std::env::var("GITHUB_TOKEN").ok(); + + // get testbed + // we want this to be a combination of + // is_github_ci? + // OS + // machine id + + let os = std::env::consts::OS; + + let testbed = format!( + "{os}{}", + github_token.is_some().then_some("-gha").unwrap_or_default() + ); + + // also figure out if we're on a fork + + let token = std::env::var("BENCHER_API_TOKEN").ok(); + + let mut bencher_cmd = Command::new("bencher"); + bencher_cmd + .stdout(std::process::Stdio::inherit()) + .stderr(std::process::Stdio::inherit()) + .current_dir(Self::workspace_dir(&app_settings).unwrap()) + .arg("run") + .args(["--project", "bms"]) + .args(["--branch", &format!("\"{branch}\"")]) + .args(["--token", &token.unwrap_or_default()]) + .args(["--testbed", &testbed]) + .args(["--build-time"]) + .args(["--threshold-measure", "latency"]) + .args(["--threshold-test", "t_test"]) + .args(["--threshold-max-sample-size", "64"]) + .args(["--threshold-upper-boundary", "0.99"]) + .args(["--thresholds-reset"]) + .args(["--err"]); + + if let Some(token) = github_token { + bencher_cmd.args(["--github-actions", &token]); + } + + if !is_main { + bencher_cmd.args(["--dry-run"]); + } + + bencher_cmd + .args(["--adapter", "rust_criterion"]) + .arg("cargo bench --features=lua54"); + + let out = bencher_cmd.output()?; + if !out.status.success() { + bail!("Failed to run bencher: {:?}", out); + } + + Ok(()) + } + fn set_cargo_coverage_settings() { // This makes local dev hell // std::env::set_var("CARGO_INCREMENTAL", "0"); @@ -1369,6 +1446,13 @@ impl Xtasks { }, }); + // also run a benchmark + // on non-main branches this will just dry run + output.push(App { + global_args: default_args.clone(), + subcmd: Xtasks::Bench {}, + }); + // and finally run tests with coverage output.push(App { global_args: default_args