diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index dded39ef432..cdb726d29d4 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -55,7 +55,7 @@ jobs: run: cargo codspeed build -p bench - name: Run the benchmarks - uses: CodSpeedHQ/action@v1 + uses: CodSpeedHQ/action@v2 with: run: cargo codspeed run -p bench token: ${{ secrets.CODSPEED_TOKEN }} diff --git a/crates/bench/src/lib.rs b/crates/bench/src/lib.rs index 0e91a93f253..0663a729a8a 100644 --- a/crates/bench/src/lib.rs +++ b/crates/bench/src/lib.rs @@ -3,8 +3,20 @@ use std::path::PathBuf; use rolldown::{Bundler, InputItem, InputOptions, OutputOptions}; pub fn repo_root() -> PathBuf { - let project_root = PathBuf::from(&std::env::var("CARGO_MANIFEST_DIR").unwrap()); - project_root.parent().unwrap().parent().unwrap().to_path_buf() + let cargo_manifest_dir = std::env::var("CARGO_MANIFEST_DIR").map(PathBuf::from); + let project_root = if let Ok(cargo_manifest_dir) = cargo_manifest_dir { + cargo_manifest_dir.parent().unwrap().parent().unwrap().to_path_buf() + } else { + std::env::current_dir().expect("failed to get current dir") + }; + + assert_eq!( + project_root.file_name().unwrap(), + "rolldown", + "Benchmark must be run from the root of the repo, got wrong `project_root` {}", + project_root.display() + ); + project_root } pub async fn run_fixture(fixture_path: PathBuf) {