10
0
Fork 0
mirror of https://github.com/actions/cache.git synced 2026-04-04 22:06:57 +00:00
This commit is contained in:
Guillermo Mazzola 2026-04-01 23:00:56 +02:00 committed by GitHub
commit 8ae5f7ce12
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 63 additions and 5 deletions

View file

@ -90,6 +90,7 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir
* `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: `false`
* `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: `false`
* `lookup-only` - If true, only checks if cache entry exists and skips download. Does not change save cache behavior. Default: `false`
* `restore-only` - If true, only restores cache and skips save cache behavior. Default: `false`. Set it to `${{ github.event.repository != null && github.ref_name != github.event.repository.default_branch }}` to only save the cache when running on the default branch.
#### Environment Variables

View file

@ -406,3 +406,34 @@ test("save with valid inputs uploads a cache", async () => {
expect(failedMock).toHaveBeenCalledTimes(0);
});
test("save with restore-only should no-op", async () => {
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
const savedCacheKey = "Linux-node-";
jest.spyOn(core, "getState")
// Cache Entry State
.mockImplementationOnce(() => {
return savedCacheKey;
})
// Cache Key State
.mockImplementationOnce(() => {
return primaryKey;
});
const inputPath = "node_modules";
testUtils.setInput(Inputs.Path, inputPath);
testUtils.setInput(Inputs.RestoreOnly, "true");
const infoMock = jest.spyOn(core, "info");
const saveCacheMock = jest.spyOn(cache, "saveCache");
await saveImpl(new StateProvider());
expect(saveCacheMock).toHaveBeenCalledTimes(0);
expect(infoMock).toHaveBeenCalledWith(
"Skipping saving cache as 'restore-only' option is set."
);
});

View file

@ -26,6 +26,10 @@ inputs:
description: 'Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache'
default: 'false'
required: false
restore-only:
description: 'Downloads the cache if it exists, but skips saving it at the end of the job'
default: 'false'
required: false
save-always:
description: 'Run the post step to save the cache even if another step before fails'
default: 'false'

View file

@ -46306,7 +46306,8 @@ var Inputs;
Inputs["UploadChunkSize"] = "upload-chunk-size";
Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive";
Inputs["FailOnCacheMiss"] = "fail-on-cache-miss";
Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action
Inputs["LookupOnly"] = "lookup-only";
Inputs["RestoreOnly"] = "restore-only"; // Input for cache, restore action
})(Inputs || (exports.Inputs = Inputs = {}));
var Outputs;
(function (Outputs) {

View file

@ -46306,7 +46306,8 @@ var Inputs;
Inputs["UploadChunkSize"] = "upload-chunk-size";
Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive";
Inputs["FailOnCacheMiss"] = "fail-on-cache-miss";
Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action
Inputs["LookupOnly"] = "lookup-only";
Inputs["RestoreOnly"] = "restore-only"; // Input for cache, restore action
})(Inputs || (exports.Inputs = Inputs = {}));
var Outputs;
(function (Outputs) {

View file

@ -46306,7 +46306,8 @@ var Inputs;
Inputs["UploadChunkSize"] = "upload-chunk-size";
Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive";
Inputs["FailOnCacheMiss"] = "fail-on-cache-miss";
Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action
Inputs["LookupOnly"] = "lookup-only";
Inputs["RestoreOnly"] = "restore-only"; // Input for cache, restore action
})(Inputs || (exports.Inputs = Inputs = {}));
var Outputs;
(function (Outputs) {
@ -46401,6 +46402,10 @@ function saveImpl(stateProvider) {
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`);
return;
}
if (utils.getInputAsBool(constants_1.Inputs.RestoreOnly)) {
core.info("Skipping saving cache as 'restore-only' option is set.");
return;
}
// If restore has stored a primary key in state, reuse that
// Else re-evaluate from inputs
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey) ||

7
dist/save/index.js vendored
View file

@ -46306,7 +46306,8 @@ var Inputs;
Inputs["UploadChunkSize"] = "upload-chunk-size";
Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive";
Inputs["FailOnCacheMiss"] = "fail-on-cache-miss";
Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action
Inputs["LookupOnly"] = "lookup-only";
Inputs["RestoreOnly"] = "restore-only"; // Input for cache, restore action
})(Inputs || (exports.Inputs = Inputs = {}));
var Outputs;
(function (Outputs) {
@ -46401,6 +46402,10 @@ function saveImpl(stateProvider) {
utils.logWarning(`Event Validation Error: The event type ${process.env[constants_1.Events.Key]} is not supported because it's not tied to a branch or tag ref.`);
return;
}
if (utils.getInputAsBool(constants_1.Inputs.RestoreOnly)) {
core.info("Skipping saving cache as 'restore-only' option is set.");
return;
}
// If restore has stored a primary key in state, reuse that
// Else re-evaluate from inputs
const primaryKey = stateProvider.getState(constants_1.State.CachePrimaryKey) ||

View file

@ -5,7 +5,8 @@ export enum Inputs {
UploadChunkSize = "upload-chunk-size", // Input for cache, save action
EnableCrossOsArchive = "enableCrossOsArchive", // Input for cache, restore, save action
FailOnCacheMiss = "fail-on-cache-miss", // Input for cache, restore action
LookupOnly = "lookup-only" // Input for cache, restore action
LookupOnly = "lookup-only", // Input for cache, restore action
RestoreOnly = "restore-only" // Input for cache, restore action
}
export enum Outputs {

View file

@ -32,6 +32,11 @@ export async function saveImpl(
return;
}
if (utils.getInputAsBool(Inputs.RestoreOnly)) {
core.info("Skipping saving cache as 'restore-only' option is set.");
return;
}
// If restore has stored a primary key in state, reuse that
// Else re-evaluate from inputs
const primaryKey =

View file

@ -16,6 +16,7 @@ interface CacheInput {
enableCrossOsArchive?: boolean;
failOnCacheMiss?: boolean;
lookupOnly?: boolean;
restoreOnly?: boolean;
}
export function setInputs(input: CacheInput): void {
@ -32,6 +33,8 @@ export function setInputs(input: CacheInput): void {
setInput(Inputs.FailOnCacheMiss, input.failOnCacheMiss.toString());
input.lookupOnly !== undefined &&
setInput(Inputs.LookupOnly, input.lookupOnly.toString());
input.restoreOnly !== undefined &&
setInput(Inputs.RestoreOnly, input.restoreOnly.toString());
}
export function clearInputs(): void {
@ -42,4 +45,5 @@ export function clearInputs(): void {
delete process.env[getInputName(Inputs.EnableCrossOsArchive)];
delete process.env[getInputName(Inputs.FailOnCacheMiss)];
delete process.env[getInputName(Inputs.LookupOnly)];
delete process.env[getInputName(Inputs.RestoreOnly)];
}