Skip to content

Commit 7d610f0

Browse files
Merge pull request #526 from IvanZosimov/CacheVersionUpdate
Add support for the @actions/cache library 3.0.0
2 parents cdcc53e + bcb9f31 commit 7d610f0

File tree

9 files changed

+2968
-1285
lines changed

9 files changed

+2968
-1285
lines changed

.licenses/npm/@actions/cache.dep.yml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.licenses/npm/@actions/http-client-2.0.1.dep.yml

+32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__tests__/cache-save.test.ts

+57
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,63 @@ describe('run', () => {
294294
);
295295
expect(setFailedSpy).not.toHaveBeenCalled();
296296
});
297+
298+
it('save with -1 cacheId , should not fail workflow', async () => {
299+
inputs['cache'] = 'npm';
300+
getStateSpy.mockImplementation((name: string) => {
301+
if (name === State.CacheMatchedKey) {
302+
return npmFileHash;
303+
} else {
304+
return yarnFileHash;
305+
}
306+
});
307+
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`);
308+
saveCacheSpy.mockImplementation(() => {
309+
return -1;
310+
});
311+
312+
await run();
313+
314+
expect(getInputSpy).toHaveBeenCalled();
315+
expect(getStateSpy).toHaveBeenCalledTimes(2);
316+
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1);
317+
expect(debugSpy).toHaveBeenCalledWith(`npm path is ${commonPath}/npm`);
318+
expect(infoSpy).not.toHaveBeenCalledWith(
319+
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
320+
);
321+
expect(saveCacheSpy).toHaveBeenCalled();
322+
expect(infoSpy).not.toHaveBeenLastCalledWith(
323+
`Cache saved with the key: ${yarnFileHash}`
324+
);
325+
expect(setFailedSpy).not.toHaveBeenCalled();
326+
});
327+
328+
it('saves with error from toolkit, should fail workflow', async () => {
329+
inputs['cache'] = 'npm';
330+
getStateSpy.mockImplementation((name: string) => {
331+
if (name === State.CacheMatchedKey) {
332+
return npmFileHash;
333+
} else {
334+
return yarnFileHash;
335+
}
336+
});
337+
getCommandOutputSpy.mockImplementationOnce(() => `${commonPath}/npm`);
338+
saveCacheSpy.mockImplementation(() => {
339+
throw new cache.ValidationError('Validation failed');
340+
});
341+
342+
await run();
343+
344+
expect(getInputSpy).toHaveBeenCalled();
345+
expect(getStateSpy).toHaveBeenCalledTimes(2);
346+
expect(getCommandOutputSpy).toHaveBeenCalledTimes(1);
347+
expect(debugSpy).toHaveBeenCalledWith(`npm path is ${commonPath}/npm`);
348+
expect(infoSpy).not.toHaveBeenCalledWith(
349+
`Cache hit occurred on the primary key ${npmFileHash}, not saving cache.`
350+
);
351+
expect(saveCacheSpy).toHaveBeenCalled();
352+
expect(setFailedSpy).toHaveBeenCalled();
353+
});
297354
});
298355

299356
afterEach(() => {

0 commit comments

Comments
 (0)