mirror of
https://github.com/Swatinem/rust-cache
synced 2025-06-07 09:03:26 +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
8f842c2d45
commit
5ed697a689
5 changed files with 69 additions and 15 deletions
|
@ -40,6 +40,9 @@ inputs:
|
||||||
description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github."
|
description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github."
|
||||||
required: false
|
required: false
|
||||||
default: "github"
|
default: "github"
|
||||||
|
cache-bin:
|
||||||
|
description: "A boolean value indicating whether to cache ${CARGO_HOME}/bin (default: true)"
|
||||||
|
required: false
|
||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: "A boolean value that indicates an exact match was found."
|
description: "A boolean value that indicates an exact match was found."
|
||||||
|
|
17
dist/restore/index.js
vendored
17
dist/restore/index.js
vendored
|
@ -88227,6 +88227,8 @@ class CacheConfig {
|
||||||
this.cacheKey = "";
|
this.cacheKey = "";
|
||||||
/** The secondary (restore) key that only contains the prefix and environment */
|
/** The secondary (restore) key that only contains the prefix and environment */
|
||||||
this.restoreKey = "";
|
this.restoreKey = "";
|
||||||
|
/** Whether to cache CARGO_HOME/.bin */
|
||||||
|
this.cacheBin = true;
|
||||||
/** The workspace configurations */
|
/** The workspace configurations */
|
||||||
this.workspaces = [];
|
this.workspaces = [];
|
||||||
/** The cargo binaries present during main step */
|
/** The cargo binaries present during main step */
|
||||||
|
@ -88299,6 +88301,7 @@ class CacheConfig {
|
||||||
// Construct the lockfiles portion of the key:
|
// Construct the lockfiles portion of the key:
|
||||||
// This considers all the files found via globbing for various manifests
|
// This considers all the files found via globbing for various manifests
|
||||||
// and lockfiles.
|
// and lockfiles.
|
||||||
|
self.cacheBin = lib_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.
|
||||||
const workspaces = [];
|
const workspaces = [];
|
||||||
|
@ -88393,7 +88396,19 @@ class CacheConfig {
|
||||||
self.keyFiles = sort_and_uniq(keyFiles);
|
self.keyFiles = sort_and_uniq(keyFiles);
|
||||||
key += `-${lockHash}`;
|
key += `-${lockHash}`;
|
||||||
self.cacheKey = key;
|
self.cacheKey = key;
|
||||||
self.cachePaths = [config_CARGO_HOME];
|
// 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 = [
|
||||||
|
external_path_default().join(config_CARGO_HOME, "registry"),
|
||||||
|
external_path_default().join(config_CARGO_HOME, "git"),
|
||||||
|
];
|
||||||
|
if (self.cacheBin) {
|
||||||
|
self.cachePaths = [external_path_default().join(config_CARGO_HOME, "bin"), ...self.cachePaths];
|
||||||
|
}
|
||||||
const cacheTargets = lib_core.getInput("cache-targets").toLowerCase() || "true";
|
const cacheTargets = lib_core.getInput("cache-targets").toLowerCase() || "true";
|
||||||
if (cacheTargets === "true") {
|
if (cacheTargets === "true") {
|
||||||
self.cachePaths.push(...workspaces.map((ws) => ws.target));
|
self.cachePaths.push(...workspaces.map((ws) => ws.target));
|
||||||
|
|
31
dist/save/index.js
vendored
31
dist/save/index.js
vendored
|
@ -88227,6 +88227,8 @@ class CacheConfig {
|
||||||
this.cacheKey = "";
|
this.cacheKey = "";
|
||||||
/** The secondary (restore) key that only contains the prefix and environment */
|
/** The secondary (restore) key that only contains the prefix and environment */
|
||||||
this.restoreKey = "";
|
this.restoreKey = "";
|
||||||
|
/** Whether to cache CARGO_HOME/.bin */
|
||||||
|
this.cacheBin = true;
|
||||||
/** The workspace configurations */
|
/** The workspace configurations */
|
||||||
this.workspaces = [];
|
this.workspaces = [];
|
||||||
/** The cargo binaries present during main step */
|
/** The cargo binaries present during main step */
|
||||||
|
@ -88299,6 +88301,7 @@ class CacheConfig {
|
||||||
// Construct the lockfiles portion of the key:
|
// Construct the lockfiles portion of the key:
|
||||||
// This considers all the files found via globbing for various manifests
|
// This considers all the files found via globbing for various manifests
|
||||||
// and lockfiles.
|
// and lockfiles.
|
||||||
|
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.
|
||||||
const workspaces = [];
|
const workspaces = [];
|
||||||
|
@ -88393,7 +88396,19 @@ class CacheConfig {
|
||||||
self.keyFiles = sort_and_uniq(keyFiles);
|
self.keyFiles = sort_and_uniq(keyFiles);
|
||||||
key += `-${lockHash}`;
|
key += `-${lockHash}`;
|
||||||
self.cacheKey = key;
|
self.cacheKey = key;
|
||||||
self.cachePaths = [CARGO_HOME];
|
// 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 = [
|
||||||
|
external_path_default().join(CARGO_HOME, "registry"),
|
||||||
|
external_path_default().join(CARGO_HOME, "git"),
|
||||||
|
];
|
||||||
|
if (self.cacheBin) {
|
||||||
|
self.cachePaths = [external_path_default().join(CARGO_HOME, "bin"), ...self.cachePaths];
|
||||||
|
}
|
||||||
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
|
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
|
||||||
if (cacheTargets === "true") {
|
if (cacheTargets === "true") {
|
||||||
self.cachePaths.push(...workspaces.map((ws) => ws.target));
|
self.cachePaths.push(...workspaces.map((ws) => ws.target));
|
||||||
|
@ -88855,12 +88870,14 @@ async function run() {
|
||||||
catch (e) {
|
catch (e) {
|
||||||
core.debug(`${e.stack}`);
|
core.debug(`${e.stack}`);
|
||||||
}
|
}
|
||||||
try {
|
if (config.cacheBin) {
|
||||||
core.info(`... Cleaning cargo/bin ...`);
|
try {
|
||||||
await cleanBin(config.cargoBins);
|
core.info(`... Cleaning cargo/bin ...`);
|
||||||
}
|
await cleanBin(config.cargoBins);
|
||||||
catch (e) {
|
}
|
||||||
core.debug(`${e.stack}`);
|
catch (e) {
|
||||||
|
core.debug(`${e.stack}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
core.info(`... Cleaning cargo git cache ...`);
|
core.info(`... Cleaning cargo git cache ...`);
|
||||||
|
|
|
@ -25,6 +25,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> = [];
|
||||||
|
|
||||||
|
@ -116,6 +119,8 @@ export class CacheConfig {
|
||||||
// This considers all the files found via globbing for various manifests
|
// This considers all the files found via globbing for various manifests
|
||||||
// and lockfiles.
|
// and lockfiles.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
@ -128,7 +133,7 @@ export class CacheConfig {
|
||||||
workspaces.push(new Workspace(root, target));
|
workspaces.push(new Workspace(root, target));
|
||||||
}
|
}
|
||||||
self.workspaces = workspaces;
|
self.workspaces = workspaces;
|
||||||
|
|
||||||
let keyFiles = await globFiles(".cargo/config.toml\nrust-toolchain\nrust-toolchain.toml");
|
let keyFiles = await globFiles(".cargo/config.toml\nrust-toolchain\nrust-toolchain.toml");
|
||||||
const parsedKeyFiles = []; // keyFiles that are parsed, pre-processed and hashed
|
const parsedKeyFiles = []; // keyFiles that are parsed, pre-processed and hashed
|
||||||
|
|
||||||
|
@ -234,7 +239,19 @@ export class CacheConfig {
|
||||||
key += `-${lockHash}`;
|
key += `-${lockHash}`;
|
||||||
self.cacheKey = key;
|
self.cacheKey = key;
|
||||||
|
|
||||||
self.cachePaths = [CARGO_HOME];
|
// 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"),
|
||||||
|
];
|
||||||
|
if (self.cacheBin) {
|
||||||
|
self.cachePaths = [path.join(CARGO_HOME, "bin"), ...self.cachePaths];
|
||||||
|
}
|
||||||
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
|
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
|
||||||
if (cacheTargets === "true") {
|
if (cacheTargets === "true") {
|
||||||
self.cachePaths.push(...workspaces.map((ws) => ws.target));
|
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}`);
|
core.debug(`${(e as any).stack}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (config.cacheBin) {
|
||||||
core.info(`... Cleaning cargo/bin ...`);
|
try {
|
||||||
await cleanBin(config.cargoBins);
|
core.info(`... Cleaning cargo/bin ...`);
|
||||||
} catch (e) {
|
await cleanBin(config.cargoBins);
|
||||||
core.debug(`${(e as any).stack}`);
|
} catch (e) {
|
||||||
|
core.debug(`${(e as any).stack}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue