added prefix-key, cache-directories, and cache-targets as features

This commit is contained in:
Mikhail Katychev 2022-10-17 16:36:37 -05:00
parent 22c9328bcb
commit e713427804
No known key found for this signature in database
GPG Key ID: 9E8549CD2CEB5E59
2 changed files with 22 additions and 2 deletions

View File

@ -2,6 +2,10 @@ name: "Rust Cache"
description: "A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults."
author: "Arpad Borsos <swatinem@swatinem.de>"
inputs:
prefix-key:
description: "The prefix cache key, this can be changed to start a new cache manually"
required: false
default: "v0-rust"
shared-key:
description: "An additional cache key that is stable over multiple jobs"
required: false
@ -14,6 +18,13 @@ inputs:
workspaces:
description: "Paths to multiple Cargo workspaces and their target directories, separated by newlines"
required: false
cache-directories:
description: "Additional non workspace directories, separated by newlines"
required: false
cache-targets:
description: "Determines whether workspace targets are cached"
required: false
default: "true"
cache-on-failure:
description: "Cache even if the build fails. Defaults to false"
required: false

View File

@ -50,7 +50,7 @@ export class CacheConfig {
// This uses either the `shared-key` input,
// or the `key` input combined with the `job` key.
let key = `v0-rust`;
let key = core.getInput("prefix-key");
const sharedKey = core.getInput("shared-key");
if (sharedKey) {
@ -154,7 +154,16 @@ export class CacheConfig {
}
self.workspaces = workspaces;
self.cachePaths = [CARGO_HOME, ...workspaces.map((ws) => ws.target)];
self.cachePaths = [CARGO_HOME];
const cacheTargets = core.getInput("cache-targets").toLowerCase();
if (cacheTargets === "true") {
self.cachePaths.push(...workspaces.map((ws) => ws.target));
}
const cacheDirectories = core.getInput("cache-directories");
for (const dir of cacheDirectories.trim().split("\n")) {
self.cachePaths.push(dir);
}
return self;
}