Skip to content

Commit 12adb0e

Browse files
Boshenclaude
andcommitted
feat: add cache-save-if input to control cache saving
Allow users to disable cache saving while still restoring caches. This is useful for matrix jobs or limiting cache writes to specific branches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 976b1aa commit 12adb0e

6 files changed

Lines changed: 10 additions & 3 deletions

File tree

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ inputs:
2424
cache-dependency-path:
2525
description: "Path to lock file for cache key generation. Auto-detected if not specified."
2626
required: false
27+
cache-save-if:
28+
description: "Whether to save the cache. If false, cache is only restored. Useful for limiting cache writes to specific branches."
29+
required: false
30+
default: "true"
2731

2832
outputs:
2933
version:

dist/index.mjs

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function printViteVersion(): Promise<void> {
5454

5555
async function runPost(inputs: Inputs): Promise<void> {
5656
// Save cache if enabled
57-
if (inputs.cache) {
57+
if (inputs.cache && inputs.cacheSaveIf) {
5858
await saveCache();
5959
}
6060
}

src/inputs.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe("getInputs", () => {
2828
runInstall: [],
2929
cache: false,
3030
cacheDependencyPath: undefined,
31+
cacheSaveIf: false,
3132
});
3233
});
3334

src/inputs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export function getInputs(): Inputs {
1111
runInstall: parseRunInstall(getInput("run-install")),
1212
cache: getBooleanInput("cache"),
1313
cacheDependencyPath: getInput("cache-dependency-path") || undefined,
14+
cacheSaveIf: getBooleanInput("cache-save-if"),
1415
};
1516
}
1617

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Inputs {
2323
readonly runInstall: RunInstall[];
2424
readonly cache: boolean;
2525
readonly cacheDependencyPath?: string;
26+
readonly cacheSaveIf: boolean;
2627
}
2728

2829
// Lock file types

0 commit comments

Comments
 (0)