Skip to content

Commit e871d69

Browse files
HanSur94claude
andcommitted
ci: cache MEX binaries across workflows to avoid redundant compilation
- Build MEX once, cache by hash of C sources + build_mex.m - Download cached artifacts in test, example, and benchmark jobs - Skip octave-dev install when cache hits (only need octave runtime) - Fix benchmark binary_search call (was passing 80 instead of 'left') - macOS MEX build remains standalone (different platform) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent de30613 commit e871d69

3 files changed

Lines changed: 152 additions & 30 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,62 @@ permissions:
1111
pull-requests: write
1212

1313
jobs:
14+
build-mex:
15+
name: Build MEX
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Cache MEX binaries
21+
id: cache-mex
22+
uses: actions/cache@v4
23+
with:
24+
path: |
25+
libs/FastPlot/private/*.mex
26+
libs/SensorThreshold/private/*.mex
27+
key: mex-linux-${{ hashFiles('libs/FastPlot/private/mex_src/**', 'libs/FastPlot/build_mex.m') }}
28+
29+
- name: Install Octave
30+
if: steps.cache-mex.outputs.cache-hit != 'true'
31+
run: sudo apt-get update && sudo apt-get install -y octave octave-dev
32+
33+
- name: Compile MEX files
34+
if: steps.cache-mex.outputs.cache-hit != 'true'
35+
run: octave --eval "setup();"
36+
37+
- name: Upload MEX artifacts
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: mex-linux-bench
41+
path: |
42+
libs/FastPlot/private/*.mex
43+
libs/SensorThreshold/private/*.mex
44+
retention-days: 1
45+
1446
benchmark:
1547
name: Performance Benchmark
48+
needs: build-mex
1649
runs-on: ubuntu-latest
1750
steps:
1851
- uses: actions/checkout@v4
1952

53+
- name: Download MEX binaries
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: mex-linux-bench
57+
2058
- name: Install Octave and Xvfb
21-
run: sudo apt-get update && sudo apt-get install -y octave octave-dev xvfb
59+
run: sudo apt-get update && sudo apt-get install -y octave xvfb
2260

2361
- name: Run benchmark
2462
run: |
2563
xvfb-run octave --eval "
26-
addpath(pwd); setup();
64+
addpath(pwd);
65+
addpath(fullfile(pwd, 'libs', 'FastPlot'));
66+
addpath(fullfile(pwd, 'libs', 'SensorThreshold'));
67+
addpath(fullfile(pwd, 'libs', 'EventDetection'));
68+
addpath(fullfile(pwd, 'libs', 'Dashboard'));
69+
addpath(fullfile(pwd, 'libs', 'WebBridge'));
2770
addpath(fullfile(pwd, 'libs', 'FastPlot', 'private'));
2871
2972
% Quick benchmark: 1M points, 10 zooms
@@ -41,7 +84,7 @@ jobs:
4184
% Measure binary search
4285
tic;
4386
for i = 1:1000
44-
binary_search(x, 20, 80);
87+
binary_search(x, 20, 'left');
4588
end
4689
t_bs = toc / 1000;
4790

.github/workflows/examples.yml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,62 @@ on:
77
branches: [main]
88

99
jobs:
10+
build-mex:
11+
name: Build MEX
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Cache MEX binaries
17+
id: cache-mex
18+
uses: actions/cache@v4
19+
with:
20+
path: |
21+
libs/FastPlot/private/*.mex
22+
libs/SensorThreshold/private/*.mex
23+
key: mex-linux-${{ hashFiles('libs/FastPlot/private/mex_src/**', 'libs/FastPlot/build_mex.m') }}
24+
25+
- name: Install Octave
26+
if: steps.cache-mex.outputs.cache-hit != 'true'
27+
run: sudo apt-get update && sudo apt-get install -y octave octave-dev
28+
29+
- name: Compile MEX files
30+
if: steps.cache-mex.outputs.cache-hit != 'true'
31+
run: octave --eval "setup();"
32+
33+
- name: Upload MEX artifacts
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: mex-linux-examples
37+
path: |
38+
libs/FastPlot/private/*.mex
39+
libs/SensorThreshold/private/*.mex
40+
retention-days: 1
41+
1042
smoke-test:
1143
name: Example Smoke Tests
44+
needs: build-mex
1245
runs-on: ubuntu-latest
1346
steps:
1447
- uses: actions/checkout@v4
1548

49+
- name: Download MEX binaries
50+
uses: actions/download-artifact@v4
51+
with:
52+
name: mex-linux-examples
53+
1654
- name: Install Octave and Xvfb
17-
run: sudo apt-get update && sudo apt-get install -y octave octave-dev xvfb
55+
run: sudo apt-get update && sudo apt-get install -y octave xvfb
1856

1957
- name: Run example smoke tests
2058
run: |
2159
xvfb-run octave --eval "
22-
addpath(pwd); setup();
60+
addpath(pwd);
61+
addpath(fullfile(pwd, 'libs', 'FastPlot'));
62+
addpath(fullfile(pwd, 'libs', 'SensorThreshold'));
63+
addpath(fullfile(pwd, 'libs', 'EventDetection'));
64+
addpath(fullfile(pwd, 'libs', 'Dashboard'));
65+
addpath(fullfile(pwd, 'libs', 'WebBridge'));
2366
examples = {
2467
'example_basic',
2568
'example_multi',

.github/workflows/tests.yml

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,78 @@ jobs:
2525
- name: Run linter
2626
run: mh_lint libs/ tests/ examples/
2727

28+
build-mex:
29+
name: Build MEX (Linux)
30+
if: github.event_name != 'schedule'
31+
runs-on: ubuntu-latest
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Cache MEX binaries
36+
id: cache-mex
37+
uses: actions/cache@v4
38+
with:
39+
path: |
40+
libs/FastPlot/private/*.mex
41+
libs/SensorThreshold/private/*.mex
42+
key: mex-linux-${{ hashFiles('libs/FastPlot/private/mex_src/**', 'libs/FastPlot/build_mex.m') }}
43+
44+
- name: Install Octave
45+
if: steps.cache-mex.outputs.cache-hit != 'true'
46+
run: sudo apt-get update && sudo apt-get install -y octave octave-dev
47+
48+
- name: Compile MEX files
49+
if: steps.cache-mex.outputs.cache-hit != 'true'
50+
run: octave --eval "setup();"
51+
52+
- name: Upload MEX artifacts
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: mex-linux
56+
path: |
57+
libs/FastPlot/private/*.mex
58+
libs/SensorThreshold/private/*.mex
59+
retention-days: 1
60+
2861
octave:
2962
name: Octave Tests
63+
needs: build-mex
3064
if: github.event_name != 'schedule'
3165
runs-on: ubuntu-latest
3266
steps:
3367
- uses: actions/checkout@v4
3468

69+
- name: Download MEX binaries
70+
uses: actions/download-artifact@v4
71+
with:
72+
name: mex-linux
73+
3574
- name: Install Octave and Xvfb
36-
run: sudo apt-get update && sudo apt-get install -y octave octave-dev xvfb
75+
run: sudo apt-get update && sudo apt-get install -y octave xvfb
3776

3877
- name: Run tests
3978
run: |
40-
xvfb-run octave --eval "cd('tests'); r = run_all_tests(); if r.failed > 0; exit(1); end"
79+
xvfb-run octave --eval "
80+
addpath(pwd);
81+
addpath(fullfile(pwd, 'libs', 'FastPlot'));
82+
addpath(fullfile(pwd, 'libs', 'SensorThreshold'));
83+
addpath(fullfile(pwd, 'libs', 'EventDetection'));
84+
addpath(fullfile(pwd, 'libs', 'Dashboard'));
85+
addpath(fullfile(pwd, 'libs', 'WebBridge'));
86+
cd('tests'); r = run_all_tests(); if r.failed > 0; exit(1); end"
87+
88+
mex-build-macos:
89+
name: MEX Build (macOS)
90+
if: github.event_name != 'schedule'
91+
runs-on: macos-latest
92+
steps:
93+
- uses: actions/checkout@v4
94+
95+
- name: Install Octave
96+
run: brew install octave
97+
98+
- name: Compile MEX files
99+
run: octave --eval "setup(); fprintf('All MEX files compiled successfully on %s\n', computer());"
41100

42101
matlab:
43102
name: MATLAB Tests
@@ -64,26 +123,3 @@ jobs:
64123
fail_ci_if_error: false
65124
env:
66125
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
67-
68-
mex-build:
69-
name: MEX Build (${{ matrix.os }})
70-
if: github.event_name != 'schedule'
71-
runs-on: ${{ matrix.os }}
72-
strategy:
73-
fail-fast: false
74-
matrix:
75-
os: [ubuntu-latest, macos-latest]
76-
steps:
77-
- uses: actions/checkout@v4
78-
79-
- name: Install Octave (Ubuntu)
80-
if: runner.os == 'Linux'
81-
run: sudo apt-get update && sudo apt-get install -y octave octave-dev
82-
83-
- name: Install Octave (macOS)
84-
if: runner.os == 'macOS'
85-
run: brew install octave
86-
87-
- name: Compile MEX files
88-
run: |
89-
octave --eval "setup(); fprintf('All MEX files compiled successfully on %s\n', computer());"

0 commit comments

Comments
 (0)