mirror of
https://github.com/actions/cache.git
synced 2025-04-22 03:56:45 +00:00
Add a restore-only option to support pulling without saving a cache entry
This commit is contained in:
parent
e43776276f
commit
e44e77f968
4 changed files with 56 additions and 1 deletions
|
@ -376,3 +376,47 @@ test("save with valid inputs uploads a cache", async () => {
|
|||
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save skipped with restore only", async () => {
|
||||
const infoMock = jest.spyOn(core, "info");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const cacheEntry: ArtifactCacheEntry = {
|
||||
cacheKey: "Linux-node-",
|
||||
scope: "refs/heads/master",
|
||||
creationTime: "2019-11-13T19:18:02+00:00",
|
||||
archiveLocation: "www.actionscache.test/download"
|
||||
};
|
||||
|
||||
jest.spyOn(core, "getState")
|
||||
// Cache Entry State
|
||||
.mockImplementationOnce(() => {
|
||||
return JSON.stringify(cacheEntry);
|
||||
})
|
||||
// Cache Key State
|
||||
.mockImplementationOnce(() => {
|
||||
return primaryKey;
|
||||
});
|
||||
|
||||
const inputPath = "node_modules";
|
||||
testUtils.setInput(Inputs.Path, inputPath);
|
||||
testUtils.setInput(Inputs.RestoreOnly, "true");
|
||||
|
||||
const cacheId = 4;
|
||||
const reserveCacheMock = jest
|
||||
.spyOn(cacheHttpClient, "reserveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
const saveCacheMock = jest.spyOn(cacheHttpClient, "saveCache");
|
||||
|
||||
await run();
|
||||
|
||||
expect(infoMock).toHaveBeenCalledWith(
|
||||
"Cache action configured for restore-only, skipping save step"
|
||||
);
|
||||
|
||||
expect(reserveCacheMock).toHaveBeenCalledTimes(0);
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
|
|
@ -11,6 +11,9 @@ inputs:
|
|||
restore-keys:
|
||||
description: 'An ordered list of keys to use for restoring the cache if no cache hit occurred for key'
|
||||
required: false
|
||||
restore-only:
|
||||
description: 'Disables saving a new cache entry when true'
|
||||
required: false
|
||||
outputs:
|
||||
cache-hit:
|
||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
export enum Inputs {
|
||||
Key = "key",
|
||||
Path = "path",
|
||||
RestoreKeys = "restore-keys"
|
||||
RestoreKeys = "restore-keys",
|
||||
RestoreOnly = "restore-only"
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
|
|
|
@ -18,6 +18,13 @@ async function run(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (core.getInput(Inputs.RestoreOnly) === "true") {
|
||||
core.info(
|
||||
"Cache action configured for restore-only, skipping save step"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const state = utils.getCacheState();
|
||||
|
||||
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue