Skip to content

Commit 92d06b8

Browse files
authored
Merge pull request #2242 from wgqqqqq/codex/fix-sherpa-native-cache
fix(ci): isolate sherpa native cache lifecycle
2 parents aeb8099 + cee9d47 commit 92d06b8

2 files changed

Lines changed: 73 additions & 8 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,45 @@ jobs:
197197

198198
- uses: swatinem/rust-cache@v2
199199
with:
200-
shared-key: "ci-check-v4-${{ runner.os }}-no-cargo-bin-v1-sherpa-native-v1"
200+
shared-key: "ci-check-v5-${{ runner.os }}-no-cargo-bin-v1"
201201
cache-bin: false
202-
# sherpa-onnx-sys stores downloaded native archives beside Cargo's
203-
# normal artifacts. Preserve that directory with the build-script
204-
# fingerprints that reference it, or restored test builds cannot link.
205-
cache-directories: |
206-
target/sherpa-onnx-prebuilt
207202
# PR caches are scoped to merge refs; trusted main pushes own shared
208203
# refreshes and retain completed dependency builds after late test failures.
209204
save-if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
210205
cache-on-failure: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
211206

207+
# rust-cache prunes the workspace target directory before saving it, so
208+
# native libraries stored under target need an independent cache lifecycle.
209+
- name: Restore Sherpa native libraries
210+
id: sherpa-native-cache
211+
uses: actions/cache/restore@v5
212+
with:
213+
path: target/sherpa-onnx-prebuilt
214+
key: sherpa-onnx-v1-${{ runner.os }}-${{ runner.arch }}-1.13.4-static
215+
216+
- name: Repair missing Sherpa native state
217+
shell: bash
218+
run: |
219+
if ! find target/sherpa-onnx-prebuilt -type f \
220+
\( -name 'sherpa-onnx-c-api.lib' -o -name 'libsherpa-onnx-c-api.a' \) \
221+
-print -quit 2>/dev/null | grep -q .; then
222+
rm -rf target/sherpa-onnx-prebuilt
223+
cargo clean -p sherpa-onnx-sys
224+
fi
225+
212226
- name: Check compilation
213227
run: cargo check --locked --workspace
214228

229+
- name: Save Sherpa native libraries
230+
if: >-
231+
github.event_name == 'push' &&
232+
github.ref == 'refs/heads/main' &&
233+
steps.sherpa-native-cache.outputs.cache-hit != 'true'
234+
uses: actions/cache/save@v5
235+
with:
236+
path: target/sherpa-onnx-prebuilt
237+
key: sherpa-onnx-v1-${{ runner.os }}-${{ runner.arch }}-1.13.4-static
238+
215239
# The installer is intentionally excluded from the root Cargo workspace,
216240
# so the workspace check above cannot catch drift in its shared Rust APIs.
217241
- name: Check installer compilation

‎scripts/check-github-config.test.mjs‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,49 @@ test('keeps Rust CI independent, restore-only on PRs, and target-focused', () =>
256256
);
257257
assert.equal(
258258
rustCache?.with?.['cache-directories'],
259-
'target/sherpa-onnx-prebuilt\n',
260-
'Rust CI must restore sherpa native libraries with the Cargo fingerprints that reference them',
259+
undefined,
260+
'Rust cache cleanup must not own native libraries stored under target',
261+
);
262+
263+
const restoreSherpaCache = rustJob.steps.find(
264+
(step) => step.name === 'Restore Sherpa native libraries',
265+
);
266+
const repairSherpaState = rustJob.steps.find(
267+
(step) => step.name === 'Repair missing Sherpa native state',
268+
);
269+
const checkCompilation = rustJob.steps.find(
270+
(step) => step.name === 'Check compilation',
271+
);
272+
const saveSherpaCache = rustJob.steps.find(
273+
(step) => step.name === 'Save Sherpa native libraries',
274+
);
275+
const sherpaCacheKey =
276+
'sherpa-onnx-v1-${{ runner.os }}-${{ runner.arch }}-1.13.4-static';
277+
278+
assert.equal(restoreSherpaCache?.uses, 'actions/cache/restore@v5');
279+
assert.equal(restoreSherpaCache?.with?.path, 'target/sherpa-onnx-prebuilt');
280+
assert.equal(restoreSherpaCache?.with?.key, sherpaCacheKey);
281+
assert.match(
282+
repairSherpaState?.run ?? '',
283+
/rm -rf target\/sherpa-onnx-prebuilt/,
284+
);
285+
assert.match(repairSherpaState?.run ?? '', /cargo clean -p sherpa-onnx-sys/);
286+
assert.equal(saveSherpaCache?.uses, 'actions/cache/save@v5');
287+
assert.equal(saveSherpaCache?.with?.path, 'target/sherpa-onnx-prebuilt');
288+
assert.equal(saveSherpaCache?.with?.key, sherpaCacheKey);
289+
assert.equal(
290+
saveSherpaCache?.if,
291+
"github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.sherpa-native-cache.outputs.cache-hit != 'true'",
292+
);
293+
assert.ok(
294+
rustJob.steps.indexOf(restoreSherpaCache) <
295+
rustJob.steps.indexOf(checkCompilation),
296+
'Sherpa native libraries must be restored before cargo check',
297+
);
298+
assert.ok(
299+
rustJob.steps.indexOf(checkCompilation) <
300+
rustJob.steps.indexOf(saveSherpaCache),
301+
'Sherpa native libraries must be saved before rust-cache post cleanup',
261302
);
262303

263304
const commandByStep = new Map(

0 commit comments

Comments
 (0)