mirror of
https://github.com/actions/cache.git
synced 2024-11-22 18:01:26 +01:00
feat: force-update
This commit is contained in:
parent
c7c46bcb6d
commit
17151cf67e
4 changed files with 37 additions and 3 deletions
|
@ -142,6 +142,38 @@ test("save with exact match returns early", async () => {
|
|||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save with force-update", async () => {
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
||||
const primaryKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
|
||||
const savedCacheKey = primaryKey;
|
||||
|
||||
jest.spyOn(core, "getState")
|
||||
// Cache Entry State
|
||||
.mockImplementationOnce(() => {
|
||||
return savedCacheKey;
|
||||
})
|
||||
// Cache Key State
|
||||
.mockImplementationOnce(() => {
|
||||
return primaryKey;
|
||||
});
|
||||
|
||||
testUtils.setInput(Inputs.ForceUpdate, "true");
|
||||
testUtils.setInput(Inputs.Path, "node_modules");
|
||||
|
||||
const cacheId = 4;
|
||||
const saveCacheMock = jest
|
||||
.spyOn(cache, "saveCache")
|
||||
.mockImplementationOnce(() => {
|
||||
return Promise.resolve(cacheId);
|
||||
});
|
||||
|
||||
await run();
|
||||
|
||||
expect(saveCacheMock).toHaveBeenCalledTimes(1);
|
||||
expect(failedMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test("save with missing input outputs warning", async () => {
|
||||
const logWarningMock = jest.spyOn(actionUtils, "logWarning");
|
||||
const failedMock = jest.spyOn(core, "setFailed");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export enum Inputs {
|
||||
ForceUpdate = "force-update",
|
||||
Key = "key",
|
||||
Path = "path",
|
||||
RestoreKeys = "restore-keys",
|
||||
|
|
|
@ -27,8 +27,6 @@ async function run(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
const state = utils.getCacheState();
|
||||
|
||||
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
||||
const primaryKey = core.getState(State.CachePrimaryKey);
|
||||
if (!primaryKey) {
|
||||
|
@ -36,7 +34,9 @@ async function run(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||
const forceUpdate = core.getInput(Inputs.ForceUpdate) === "true";
|
||||
const state = utils.getCacheState();
|
||||
if (utils.isExactKeyMatch(primaryKey, state) && !forceUpdate) {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
|
|
|
@ -23,6 +23,7 @@ export function setInputs(input: CacheInput): void {
|
|||
}
|
||||
|
||||
export function clearInputs(): void {
|
||||
delete process.env[getInputName(Inputs.ForceUpdate)];
|
||||
delete process.env[getInputName(Inputs.Path)];
|
||||
delete process.env[getInputName(Inputs.Key)];
|
||||
delete process.env[getInputName(Inputs.RestoreKeys)];
|
||||
|
|
Loading…
Reference in a new issue