diff --git a/action.yml b/action.yml index 4bc7f8e..ae25751 100644 --- a/action.yml +++ b/action.yml @@ -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 " 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 diff --git a/src/config.ts b/src/config.ts index 5ff8ef8..c92f872 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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; }