ci: harden install smoke npm cache cleanup

This commit is contained in:
Peter Steinberger
2026-04-23 21:19:05 +01:00
parent c5c163d078
commit 78fe353995
2 changed files with 19 additions and 4 deletions

View File

@@ -170,15 +170,28 @@ NPM_CACHE_DIR="${OPENCLAW_INSTALL_SMOKE_NPM_CACHE_DIR:-}"
NPM_CACHE_OWNED=0
NPM_CACHE_DOCKER_ARGS=()
remove_owned_npm_cache() {
if [[ "$NPM_CACHE_OWNED" != "1" || -z "$NPM_CACHE_DIR" || ! -d "$NPM_CACHE_DIR" ]]; then
return
fi
if rm -rf "$NPM_CACHE_DIR" 2>/dev/null; then
return
fi
if command -v sudo >/dev/null 2>&1 && sudo -n rm -rf "$NPM_CACHE_DIR" 2>/dev/null; then
return
fi
echo "WARN: failed to remove temporary npm cache: $NPM_CACHE_DIR" >&2
}
cleanup() {
if [[ -n "$UPDATE_SERVER_PID" ]]; then
kill "$UPDATE_SERVER_PID" >/dev/null 2>&1 || true
wait "$UPDATE_SERVER_PID" >/dev/null 2>&1 || true
fi
if [[ "$NPM_CACHE_OWNED" == "1" && -n "$NPM_CACHE_DIR" ]]; then
rm -rf "$NPM_CACHE_DIR"
fi
rm -rf "$LATEST_DIR" "$UPDATE_DIR"
remove_owned_npm_cache || true
rm -rf "$LATEST_DIR" "$UPDATE_DIR" || true
}
trap cleanup EXIT

View File

@@ -93,6 +93,8 @@ describe("install-sh smoke runner", () => {
expect(script).toContain('NPM_CACHE_DIR="${OPENCLAW_INSTALL_SMOKE_NPM_CACHE_DIR:-}"');
expect(script).toContain("-e npm_config_cache=/npm-cache");
expect(script).toContain('"${NPM_CACHE_DOCKER_ARGS[@]}"');
expect(script).toContain("remove_owned_npm_cache");
expect(script).toContain('sudo -n rm -rf "$NPM_CACHE_DIR"');
expect(script).toContain("==> Run direct npm global smoke");
expect(script).toContain("OPENCLAW_INSTALL_SMOKE_MODE=npm-global");
expect(runner).toContain("run_npm_global_smoke");