Skip to content

Commit 3de4f4c

Browse files
authored
Merge pull request #298 from pulp-platform/fischeti/cli-regression-speedup
ci: use cached golden executable for `cli_regression` tests
2 parents b4ddc76 + edb8538 commit 3de4f4c

4 files changed

Lines changed: 92 additions & 47 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ jobs:
3535
toolchain: ${{ matrix.rust }}
3636
- uses: Swatinem/rust-cache@v2
3737
with:
38-
shared-key: ci-test-${{ matrix.os }}-${{ matrix.rust }}
39-
cache-workspace-crates: "true"
38+
shared-key: cargo-${{ matrix.os }}-${{ matrix.rust }}
4039
- name: Build
4140
run: cargo build
4241
- name: Cargo Test
@@ -58,8 +57,7 @@ jobs:
5857
components: clippy
5958
- uses: Swatinem/rust-cache@v2
6059
with:
61-
shared-key: ci-clippy-${{ runner.os }}-stable
62-
cache-workspace-crates: "true"
60+
shared-key: cargo-${{ runner.os }}-stable
6361
- run: cargo clippy
6462

6563
unused-deps:
@@ -70,10 +68,6 @@ jobs:
7068
- uses: dtolnay/rust-toolchain@stable
7169
with:
7270
toolchain: stable
73-
- uses: Swatinem/rust-cache@v2
74-
with:
75-
shared-key: ci-unused-deps-${{ runner.os }}-stable
76-
cache-workspace-crates: "true"
7771
- name: Install machete
7872
run: cargo install cargo-machete
7973
- name: Check for unused dependencies

.github/workflows/cli_regression.yml

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,37 @@ concurrency:
1010

1111
jobs:
1212
test:
13-
runs-on: ubuntu-latest
13+
runs-on: ${{ matrix.runner }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
include:
18+
- runner: ubuntu-latest
19+
target: x86_64-unknown-linux-gnu
20+
golden_bin: target/regression-golden/bender
21+
- runner: windows-latest
22+
target: x86_64-pc-windows-msvc
23+
golden_bin: target/regression-golden/bender.exe
24+
- runner: macos-latest
25+
target: aarch64-apple-darwin
26+
golden_bin: target/regression-golden/bender
1427
steps:
1528
- uses: actions/checkout@v6
1629
with:
1730
submodules: recursive
1831
- uses: dtolnay/rust-toolchain@stable
1932
with:
2033
toolchain: stable
21-
- name: Run CLI Regression
22-
run: cargo test --test cli_regression -- --ignored
23-
env:
24-
BENDER_TEST_GOLDEN_BRANCH: ${{ github.base_ref }}
25-
26-
test-windows:
27-
runs-on: windows-latest
28-
steps:
29-
- uses: actions/checkout@v6
30-
with:
31-
submodules: recursive
32-
- uses: dtolnay/rust-toolchain@stable
33-
with:
34-
toolchain: stable
35-
- name: Run CLI Regression
36-
run: cargo test --test cli_regression -- --ignored
37-
env:
38-
BENDER_TEST_GOLDEN_BRANCH: ${{ github.base_ref }}
39-
40-
test-macos:
41-
runs-on: macos-latest
42-
steps:
43-
- uses: actions/checkout@v6
34+
- uses: Swatinem/rust-cache@v2
4435
with:
45-
submodules: recursive
46-
- uses: dtolnay/rust-toolchain@stable
36+
shared-key: cargo-${{ runner.os }}-stable
37+
- name: Restore CLI regression golden binary
38+
uses: actions/cache/restore@v5
4739
with:
48-
toolchain: stable
40+
path: target/regression-golden
41+
key: golden-bender-${{ matrix.target }}-${{ github.event.pull_request.base.sha || github.sha }}
4942
- name: Run CLI Regression
5043
run: cargo test --test cli_regression -- --ignored
5144
env:
5245
BENDER_TEST_GOLDEN_BRANCH: ${{ github.base_ref }}
46+
BENDER_TEST_GOLDEN_BIN: ${{ matrix.golden_bin }}

.github/workflows/release-build.yml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,23 @@ jobs:
2727
- target: x86_64-unknown-linux-gnu
2828
runner: ubuntu-22.04
2929
container: quay.io/pypa/manylinux_2_28_x86_64
30+
cache_golden_bin: false
3031
- target: aarch64-unknown-linux-gnu
3132
runner: ubuntu-22.04-arm
3233
container: quay.io/pypa/manylinux_2_28_aarch64
33-
- target: x86_64-apple-darwin
34-
runner: macos-latest
34+
cache_golden_bin: false
35+
- target: x86_64-unknown-linux-gnu
36+
runner: ubuntu-latest
37+
cache_golden_bin: true
3538
- target: aarch64-apple-darwin
36-
runner: macos-15
39+
runner: macos-latest
40+
cache_golden_bin: true
41+
- target: x86_64-apple-darwin
42+
runner: macos-15-intel
43+
cache_golden_bin: false
3744
- target: x86_64-pc-windows-msvc
3845
runner: windows-latest
46+
cache_golden_bin: true
3947
steps:
4048
- uses: actions/checkout@v6
4149
with:
@@ -51,9 +59,22 @@ jobs:
5159
if: ${{ !matrix.container }}
5260
with:
5361
toolchain: stable
54-
- uses: Swatinem/rust-cache@v2
55-
with:
56-
shared-key: release-build-${{ matrix.target }}
57-
cache-workspace-crates: "true"
5862
- name: Build (release)
5963
run: cargo build --release
64+
- name: Prepare CLI regression golden binary
65+
if: ${{ matrix.cache_golden_bin && runner.os != 'Windows' }}
66+
run: |
67+
mkdir -p target/regression-golden
68+
cp target/release/bender target/regression-golden/bender
69+
- name: Prepare CLI regression golden binary
70+
if: ${{ matrix.cache_golden_bin && runner.os == 'Windows' }}
71+
shell: pwsh
72+
run: |
73+
New-Item -ItemType Directory -Force -Path target/regression-golden | Out-Null
74+
Copy-Item target/release/bender.exe target/regression-golden/bender.exe
75+
- name: Cache CLI regression golden binary
76+
if: ${{ matrix.cache_golden_bin }}
77+
uses: actions/cache/save@v5
78+
with:
79+
path: target/regression-golden
80+
key: golden-bender-${{ matrix.target }}-${{ github.sha }}

tests/cli_regression.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,54 @@ use pretty_assertions::assert_eq;
1010

1111
static SETUP: OnceLock<(PathBuf, PathBuf)> = OnceLock::new();
1212

13+
fn golden_binary_name() -> &'static str {
14+
if cfg!(windows) {
15+
"bender.exe"
16+
} else {
17+
"bender"
18+
}
19+
}
20+
21+
fn non_empty_env_var(key: &str) -> Option<String> {
22+
std::env::var(key).ok().filter(|value| !value.is_empty())
23+
}
24+
1325
fn get_test_env() -> &'static (PathBuf, PathBuf) {
1426
SETUP.get_or_init(|| {
1527
let root = Path::new("target/tmp_regression");
1628
let install_root = root.join("golden_install");
1729
let repo_dir = Path::new("tests/cli_regression").to_path_buf();
1830

31+
if let Some(prebuilt_bin) = non_empty_env_var("BENDER_TEST_GOLDEN_BIN") {
32+
let bender_exe = std::env::current_dir().unwrap().join(prebuilt_bin);
33+
if bender_exe.exists() {
34+
println!("Using prebuilt golden bender binary: {:?}", bender_exe);
35+
36+
let status = SysCommand::new(&bender_exe)
37+
.arg("checkout")
38+
.current_dir(&repo_dir)
39+
.status()
40+
.expect("Failed to run bender checkout");
41+
assert!(
42+
status.success(),
43+
"Failed to initialize common_cells with golden bender"
44+
);
45+
46+
return (bender_exe, repo_dir);
47+
}
48+
49+
println!(
50+
"Prebuilt golden bender binary not found at {:?}, falling back to cargo install",
51+
bender_exe
52+
);
53+
}
54+
1955
// Install Golden Bender
20-
let bender_exe = install_root.join("bin").join("bender");
56+
let bender_exe = install_root.join("bin").join(golden_binary_name());
2157

22-
let golden_branch = std::env::var("BENDER_TEST_GOLDEN_BRANCH")
23-
.or_else(|_| std::env::var("GITHUB_BASE_REF")) // For GitHub Actions
24-
.unwrap_or_else(|_| "master".to_string());
58+
let golden_branch = non_empty_env_var("BENDER_TEST_GOLDEN_BRANCH")
59+
.or_else(|| non_empty_env_var("GITHUB_BASE_REF")) // For GitHub Actions
60+
.unwrap_or_else(|| "master".to_string());
2561

2662
println!("Using golden bender branch: {}", golden_branch);
2763

@@ -59,7 +95,7 @@ fn get_test_env() -> &'static (PathBuf, PathBuf) {
5995
"Failed to initialize common_cells with bender"
6096
);
6197

62-
(bender_exe, repo_dir)
98+
(bender_exe_abs, repo_dir)
6399
})
64100
}
65101

0 commit comments

Comments
 (0)