ci: harden install smoke npm cache cleanup · openclaw/openclaw@78fe353
steipete
·
2026-04-24
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -170,15 +170,28 @@ NPM_CACHE_DIR="${OPENCLAW_INSTALL_SMOKE_NPM_CACHE_DIR:-}"
|
170 | 170 | NPM_CACHE_OWNED=0 |
171 | 171 | NPM_CACHE_DOCKER_ARGS=() |
172 | 172 | |
| 173 | +remove_owned_npm_cache() { |
| 174 | +if [[ "$NPM_CACHE_OWNED" != "1" || -z "$NPM_CACHE_DIR" || ! -d "$NPM_CACHE_DIR" ]]; then |
| 175 | +return |
| 176 | +fi |
| 177 | + |
| 178 | +if rm -rf "$NPM_CACHE_DIR" 2>/dev/null; then |
| 179 | +return |
| 180 | +fi |
| 181 | +if command -v sudo >/dev/null 2>&1 && sudo -n rm -rf "$NPM_CACHE_DIR" 2>/dev/null; then |
| 182 | +return |
| 183 | +fi |
| 184 | + |
| 185 | +echo "WARN: failed to remove temporary npm cache: $NPM_CACHE_DIR" >&2 |
| 186 | +} |
| 187 | + |
173 | 188 | cleanup() { |
174 | 189 | if [[ -n "$UPDATE_SERVER_PID" ]]; then |
175 | 190 | kill "$UPDATE_SERVER_PID" >/dev/null 2>&1 || true |
176 | 191 | wait "$UPDATE_SERVER_PID" >/dev/null 2>&1 || true |
177 | 192 | fi |
178 | | -if [[ "$NPM_CACHE_OWNED" == "1" && -n "$NPM_CACHE_DIR" ]]; then |
179 | | - rm -rf "$NPM_CACHE_DIR" |
180 | | -fi |
181 | | - rm -rf "$LATEST_DIR" "$UPDATE_DIR" |
| 193 | + remove_owned_npm_cache || true |
| 194 | + rm -rf "$LATEST_DIR" "$UPDATE_DIR" || true |
182 | 195 | } |
183 | 196 | |
184 | 197 | trap cleanup EXIT |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -93,6 +93,8 @@ describe("install-sh smoke runner", () => {
|
93 | 93 | expect(script).toContain('NPM_CACHE_DIR="${OPENCLAW_INSTALL_SMOKE_NPM_CACHE_DIR:-}"'); |
94 | 94 | expect(script).toContain("-e npm_config_cache=/npm-cache"); |
95 | 95 | expect(script).toContain('"${NPM_CACHE_DOCKER_ARGS[@]}"'); |
| 96 | +expect(script).toContain("remove_owned_npm_cache"); |
| 97 | +expect(script).toContain('sudo -n rm -rf "$NPM_CACHE_DIR"'); |
96 | 98 | expect(script).toContain("==> Run direct npm global smoke"); |
97 | 99 | expect(script).toContain("OPENCLAW_INSTALL_SMOKE_MODE=npm-global"); |
98 | 100 | expect(runner).toContain("run_npm_global_smoke"); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。