diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1402469..2cc18345 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,8 +35,7 @@ jobs: toolchain: ${{ matrix.rust }} - uses: Swatinem/rust-cache@v2 with: - shared-key: ci-test-${{ matrix.os }}-${{ matrix.rust }} - cache-workspace-crates: "true" + shared-key: cargo-${{ matrix.os }}-${{ matrix.rust }} - name: Build run: cargo build - name: Cargo Test @@ -58,8 +57,7 @@ jobs: components: clippy - uses: Swatinem/rust-cache@v2 with: - shared-key: ci-clippy-${{ runner.os }}-stable - cache-workspace-crates: "true" + shared-key: cargo-${{ runner.os }}-stable - run: cargo clippy unused-deps: @@ -70,10 +68,6 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - - uses: Swatinem/rust-cache@v2 - with: - shared-key: ci-unused-deps-${{ runner.os }}-stable - cache-workspace-crates: "true" - name: Install machete run: cargo install cargo-machete - name: Check for unused dependencies diff --git a/.github/workflows/cli_regression.yml b/.github/workflows/cli_regression.yml index c01809b5..fec5810a 100644 --- a/.github/workflows/cli_regression.yml +++ b/.github/workflows/cli_regression.yml @@ -10,7 +10,20 @@ concurrency: jobs: test: - runs-on: ubuntu-latest + runs-on: ${{ matrix.runner }} + strategy: + fail-fast: false + matrix: + include: + - runner: ubuntu-latest + target: x86_64-unknown-linux-gnu + golden_bin: target/regression-golden/bender + - runner: windows-latest + target: x86_64-pc-windows-msvc + golden_bin: target/regression-golden/bender.exe + - runner: macos-latest + target: aarch64-apple-darwin + golden_bin: target/regression-golden/bender steps: - uses: actions/checkout@v6 with: @@ -18,35 +31,16 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: toolchain: stable - - name: Run CLI Regression - run: cargo test --test cli_regression -- --ignored - env: - BENDER_TEST_GOLDEN_BRANCH: ${{ github.base_ref }} - - test-windows: - runs-on: windows-latest - steps: - - uses: actions/checkout@v6 - with: - submodules: recursive - - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - - name: Run CLI Regression - run: cargo test --test cli_regression -- --ignored - env: - BENDER_TEST_GOLDEN_BRANCH: ${{ github.base_ref }} - - test-macos: - runs-on: macos-latest - steps: - - uses: actions/checkout@v6 + - uses: Swatinem/rust-cache@v2 with: - submodules: recursive - - uses: dtolnay/rust-toolchain@stable + shared-key: cargo-${{ runner.os }}-stable + - name: Restore CLI regression golden binary + uses: actions/cache/restore@v5 with: - toolchain: stable + path: target/regression-golden + key: golden-bender-${{ matrix.target }}-${{ github.event.pull_request.base.sha || github.sha }} - name: Run CLI Regression run: cargo test --test cli_regression -- --ignored env: BENDER_TEST_GOLDEN_BRANCH: ${{ github.base_ref }} + BENDER_TEST_GOLDEN_BIN: ${{ matrix.golden_bin }} diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index a0c06689..47a3cd7c 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -27,15 +27,23 @@ jobs: - target: x86_64-unknown-linux-gnu runner: ubuntu-22.04 container: quay.io/pypa/manylinux_2_28_x86_64 + cache_golden_bin: false - target: aarch64-unknown-linux-gnu runner: ubuntu-22.04-arm container: quay.io/pypa/manylinux_2_28_aarch64 - - target: x86_64-apple-darwin - runner: macos-latest + cache_golden_bin: false + - target: x86_64-unknown-linux-gnu + runner: ubuntu-latest + cache_golden_bin: true - target: aarch64-apple-darwin - runner: macos-15 + runner: macos-latest + cache_golden_bin: true + - target: x86_64-apple-darwin + runner: macos-15-intel + cache_golden_bin: false - target: x86_64-pc-windows-msvc runner: windows-latest + cache_golden_bin: true steps: - uses: actions/checkout@v6 with: @@ -51,9 +59,22 @@ jobs: if: ${{ !matrix.container }} with: toolchain: stable - - uses: Swatinem/rust-cache@v2 - with: - shared-key: release-build-${{ matrix.target }} - cache-workspace-crates: "true" - name: Build (release) run: cargo build --release + - name: Prepare CLI regression golden binary + if: ${{ matrix.cache_golden_bin && runner.os != 'Windows' }} + run: | + mkdir -p target/regression-golden + cp target/release/bender target/regression-golden/bender + - name: Prepare CLI regression golden binary + if: ${{ matrix.cache_golden_bin && runner.os == 'Windows' }} + shell: pwsh + run: | + New-Item -ItemType Directory -Force -Path target/regression-golden | Out-Null + Copy-Item target/release/bender.exe target/regression-golden/bender.exe + - name: Cache CLI regression golden binary + if: ${{ matrix.cache_golden_bin }} + uses: actions/cache/save@v5 + with: + path: target/regression-golden + key: golden-bender-${{ matrix.target }}-${{ github.sha }} diff --git a/tests/cli_regression.rs b/tests/cli_regression.rs index 076fc0f1..6ced2304 100644 --- a/tests/cli_regression.rs +++ b/tests/cli_regression.rs @@ -10,18 +10,54 @@ use pretty_assertions::assert_eq; static SETUP: OnceLock<(PathBuf, PathBuf)> = OnceLock::new(); +fn golden_binary_name() -> &'static str { + if cfg!(windows) { + "bender.exe" + } else { + "bender" + } +} + +fn non_empty_env_var(key: &str) -> Option { + std::env::var(key).ok().filter(|value| !value.is_empty()) +} + fn get_test_env() -> &'static (PathBuf, PathBuf) { SETUP.get_or_init(|| { let root = Path::new("target/tmp_regression"); let install_root = root.join("golden_install"); let repo_dir = Path::new("tests/cli_regression").to_path_buf(); + if let Some(prebuilt_bin) = non_empty_env_var("BENDER_TEST_GOLDEN_BIN") { + let bender_exe = std::env::current_dir().unwrap().join(prebuilt_bin); + if bender_exe.exists() { + println!("Using prebuilt golden bender binary: {:?}", bender_exe); + + let status = SysCommand::new(&bender_exe) + .arg("checkout") + .current_dir(&repo_dir) + .status() + .expect("Failed to run bender checkout"); + assert!( + status.success(), + "Failed to initialize common_cells with golden bender" + ); + + return (bender_exe, repo_dir); + } + + println!( + "Prebuilt golden bender binary not found at {:?}, falling back to cargo install", + bender_exe + ); + } + // Install Golden Bender - let bender_exe = install_root.join("bin").join("bender"); + let bender_exe = install_root.join("bin").join(golden_binary_name()); - let golden_branch = std::env::var("BENDER_TEST_GOLDEN_BRANCH") - .or_else(|_| std::env::var("GITHUB_BASE_REF")) // For GitHub Actions - .unwrap_or_else(|_| "master".to_string()); + let golden_branch = non_empty_env_var("BENDER_TEST_GOLDEN_BRANCH") + .or_else(|| non_empty_env_var("GITHUB_BASE_REF")) // For GitHub Actions + .unwrap_or_else(|| "master".to_string()); println!("Using golden bender branch: {}", golden_branch); @@ -59,7 +95,7 @@ fn get_test_env() -> &'static (PathBuf, PathBuf) { "Failed to initialize common_cells with bender" ); - (bender_exe, repo_dir) + (bender_exe_abs, repo_dir) }) }