mirror of
https://github.com/Swatinem/rust-cache
synced 2025-04-29 06:35:53 +00:00
Allow opting out of caching $CARGO_HOME/bin. (#216)
Prevents wiping the bin directory, which is harmful for self-hosted runners.
This commit is contained in:
parent
9a2e0d3212
commit
e8e63cdbf2
6 changed files with 59 additions and 15 deletions
|
@ -25,6 +25,9 @@ export class CacheConfig {
|
|||
/** The secondary (restore) key that only contains the prefix and environment */
|
||||
public restoreKey = "";
|
||||
|
||||
/** Whether to cache CARGO_HOME/.bin */
|
||||
public cacheBin: boolean = true;
|
||||
|
||||
/** The workspace configurations */
|
||||
public workspaces: Array<Workspace> = [];
|
||||
|
||||
|
@ -120,6 +123,8 @@ export class CacheConfig {
|
|||
// This considers all the files found via globbing for various manifests
|
||||
// and lockfiles.
|
||||
|
||||
self.cacheBin = core.getInput("cache-bin").toLowerCase() == "true";
|
||||
|
||||
// Constructs the workspace config and paths to restore:
|
||||
// The workspaces are given using a `$workspace -> $target` syntax.
|
||||
|
||||
|
@ -238,7 +243,13 @@ export class CacheConfig {
|
|||
key += `-${lockHash}`;
|
||||
self.cacheKey = key;
|
||||
|
||||
self.cachePaths = [CARGO_HOME];
|
||||
self.cachePaths = [
|
||||
path.join(CARGO_HOME, "registry"),
|
||||
path.join(CARGO_HOME, "git"),
|
||||
];
|
||||
if (self.cacheBin) {
|
||||
self.cachePaths = [path.join(CARGO_HOME, "bin"), ...self.cachePaths];
|
||||
}
|
||||
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
|
||||
if (cacheTargets === "true") {
|
||||
self.cachePaths.push(...workspaces.map((ws) => ws.target));
|
||||
|
|
12
src/save.ts
12
src/save.ts
|
@ -56,11 +56,13 @@ async function run() {
|
|||
core.debug(`${(e as any).stack}`);
|
||||
}
|
||||
|
||||
try {
|
||||
core.info(`... Cleaning cargo/bin ...`);
|
||||
await cleanBin(config.cargoBins);
|
||||
} catch (e) {
|
||||
core.debug(`${(e as any).stack}`);
|
||||
if (config.cacheBin) {
|
||||
try {
|
||||
core.info(`... Cleaning cargo/bin ...`);
|
||||
await cleanBin(config.cargoBins);
|
||||
} catch (e) {
|
||||
core.debug(`${(e as any).stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue