mirror of
https://github.com/Swatinem/rust-cache.git
synced 2025-08-15 05:05:09 +00:00
Allow opting out of caching CARGO_HOME/bin.
Prevents wiping the bin directory, which is harmful for self-hosted runners.
This commit is contained in:
parent
76686c56f2
commit
c2258624e5
4856
dist/restore/index.js
vendored
4856
dist/restore/index.js
vendored
File diff suppressed because it is too large
Load Diff
4888
dist/save/index.js
vendored
4888
dist/save/index.js
vendored
File diff suppressed because it is too large
Load Diff
@ -24,6 +24,9 @@ export class CacheConfig {
|
|||||||
/** The secondary (restore) key that only contains the prefix and environment */
|
/** The secondary (restore) key that only contains the prefix and environment */
|
||||||
public restoreKey = "";
|
public restoreKey = "";
|
||||||
|
|
||||||
|
/** Whether to cache CARGO_HOME/.bin */
|
||||||
|
public cacheBin: boolean = true;
|
||||||
|
|
||||||
/** The workspace configurations */
|
/** The workspace configurations */
|
||||||
public workspaces: Array<Workspace> = [];
|
public workspaces: Array<Workspace> = [];
|
||||||
|
|
||||||
@ -141,6 +144,8 @@ export class CacheConfig {
|
|||||||
key += `-${lockHash}`;
|
key += `-${lockHash}`;
|
||||||
self.cacheKey = key;
|
self.cacheKey = key;
|
||||||
|
|
||||||
|
self.cacheBin = core.getInput("cache-bin").toLowerCase() == "true";
|
||||||
|
|
||||||
// Constructs the workspace config and paths to restore:
|
// Constructs the workspace config and paths to restore:
|
||||||
// The workspaces are given using a `$workspace -> $target` syntax.
|
// The workspaces are given using a `$workspace -> $target` syntax.
|
||||||
|
|
||||||
@ -154,7 +159,20 @@ export class CacheConfig {
|
|||||||
}
|
}
|
||||||
self.workspaces = workspaces;
|
self.workspaces = workspaces;
|
||||||
|
|
||||||
self.cachePaths = [CARGO_HOME, ...workspaces.map((ws) => ws.target)];
|
// The original action (https://github.com/Swatinem/rust-cache) cached the entire CARGO_HOME,
|
||||||
|
// but cleaned out CARGO_HOME/bin of all binaries that weren't built by the CI run itself.
|
||||||
|
// This had the unfortunate side-effect of nuking rustup/cargo/rustc etc from self-hosted runners.
|
||||||
|
// (This is usually not a problem on hosted runners, since you get a fresh container on each run).
|
||||||
|
// So we edit this action to not cache bin/, and to bypass cleaning that directory out.
|
||||||
|
// TODO: Create an upstream patch for this, controlled by an option.
|
||||||
|
self.cachePaths = [
|
||||||
|
path.join(CARGO_HOME, "registry"),
|
||||||
|
path.join(CARGO_HOME, "git"),
|
||||||
|
...workspaces.map((ws) => ws.target)
|
||||||
|
];
|
||||||
|
if (self.cacheBin) {
|
||||||
|
self.cachePaths = [path.join(CARGO_HOME, "bin"), ...self.cachePaths];
|
||||||
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
12
src/save.ts
12
src/save.ts
@ -49,11 +49,13 @@ async function run() {
|
|||||||
core.info(`[warning] ${(e as any).stack}`);
|
core.info(`[warning] ${(e as any).stack}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (config.cacheBin) {
|
||||||
core.info(`... Cleaning cargo/bin ...`);
|
try {
|
||||||
await cleanBin();
|
core.info(`... Cleaning cargo/bin ...`);
|
||||||
} catch (e) {
|
await cleanBin();
|
||||||
core.info(`[warning] ${(e as any).stack}`);
|
} catch (e) {
|
||||||
|
core.info(`[warning] ${(e as any).stack}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user