Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ sensible defaults.
# Can be set to either "github" or "buildjet"
# default: "github"
cache-provider: ""

# Determines whether to cache the ~/.cargo/bin directory.
# default: "true"
cache-bin: ""
```

Further examples are available in the [.github/workflows](./.github/workflows/) directory.
Expand Down Expand Up @@ -169,4 +173,7 @@ to see those details as well as further details related to caching operations.
## Known issues

- The cache cleaning process currently removes all the files from `~/.cargo/bin`
that were present before the action ran (for example `rustc`).
that were present before the action ran (for example `rustc`), by default.
This can be an issue on long-running self-hosted runners, where such state
is expected to be preserved across runs. You can work around this by setting
`cache-bin: "false"`.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ inputs:
description: "Determines which provider to use for caching. Options are github or buildjet, defaults to github."
required: false
default: "github"
cache-bin:
description: "A boolean value indicating whether to cache ${CARGO_HOME}/bin (default: true)"
required: false
outputs:
cache-hit:
description: "A boolean value that indicates an exact match was found."
Expand Down
11 changes: 10 additions & 1 deletion dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88227,6 +88227,8 @@ class CacheConfig {
this.cacheKey = "";
/** The secondary (restore) key that only contains the prefix and environment */
this.restoreKey = "";
/** Whether to cache CARGO_HOME/.bin */
this.cacheBin = true;
/** The workspace configurations */
this.workspaces = [];
/** The cargo binaries present during main step */
Expand Down Expand Up @@ -88299,6 +88301,7 @@ class CacheConfig {
// Construct the lockfiles portion of the key:
// This considers all the files found via globbing for various manifests
// and lockfiles.
self.cacheBin = lib_core.getInput("cache-bin").toLowerCase() == "true";
// Constructs the workspace config and paths to restore:
// The workspaces are given using a `$workspace -> $target` syntax.
const workspaces = [];
Expand Down Expand Up @@ -88393,7 +88396,13 @@ class CacheConfig {
self.keyFiles = sort_and_uniq(keyFiles);
key += `-${lockHash}`;
self.cacheKey = key;
self.cachePaths = [config_CARGO_HOME];
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";
if (cacheTargets === "true") {
self.cachePaths.push(...workspaces.map((ws) => ws.target));
Expand Down
25 changes: 18 additions & 7 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88227,6 +88227,8 @@ class CacheConfig {
this.cacheKey = "";
/** The secondary (restore) key that only contains the prefix and environment */
this.restoreKey = "";
/** Whether to cache CARGO_HOME/.bin */
this.cacheBin = true;
/** The workspace configurations */
this.workspaces = [];
/** The cargo binaries present during main step */
Expand Down Expand Up @@ -88299,6 +88301,7 @@ class CacheConfig {
// Construct the lockfiles portion of the key:
// 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.
const workspaces = [];
Expand Down Expand Up @@ -88393,7 +88396,13 @@ class CacheConfig {
self.keyFiles = sort_and_uniq(keyFiles);
key += `-${lockHash}`;
self.cacheKey = key;
self.cachePaths = [CARGO_HOME];
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";
if (cacheTargets === "true") {
self.cachePaths.push(...workspaces.map((ws) => ws.target));
Expand Down Expand Up @@ -88855,12 +88864,14 @@ async function run() {
catch (e) {
core.debug(`${e.stack}`);
}
try {
core.info(`... Cleaning cargo/bin ...`);
await cleanBin(config.cargoBins);
}
catch (e) {
core.debug(`${e.stack}`);
if (config.cacheBin) {
try {
core.info(`... Cleaning cargo/bin ...`);
await cleanBin(config.cargoBins);
}
catch (e) {
core.debug(`${e.stack}`);
}
}
try {
core.info(`... Cleaning cargo git cache ...`);
Expand Down
15 changes: 13 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> = [];

Expand Down Expand Up @@ -116,6 +119,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.

Expand All @@ -128,7 +133,7 @@ export class CacheConfig {
workspaces.push(new Workspace(root, target));
}
self.workspaces = workspaces;

let keyFiles = await globFiles(".cargo/config.toml\nrust-toolchain\nrust-toolchain.toml");
const parsedKeyFiles = []; // keyFiles that are parsed, pre-processed and hashed

Expand Down Expand Up @@ -234,7 +239,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));
Expand Down
12 changes: 7 additions & 5 deletions src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down