Skip to content

Commit 36844ba

Browse files
committed
Use keyprefix if a cache managed by yarn
Yarn can remove obsolete dependencie so we can re-use the previous cache without its infinitive growing
1 parent 3f3c964 commit 36844ba

File tree

7 files changed

+5380
-5235
lines changed

7 files changed

+5380
-5235
lines changed

__tests__/cache-restore.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ describe('cache-restore', () => {
4545
}
4646
}
4747

48+
let inputs = {} as any;
4849
let saveStateSpy: jest.SpyInstance;
4950
let infoSpy: jest.SpyInstance;
5051
let debugSpy: jest.SpyInstance;
5152
let setOutputSpy: jest.SpyInstance;
5253
let getCommandOutputSpy: jest.SpyInstance;
5354
let restoreCacheSpy: jest.SpyInstance;
5455
let hashFilesSpy: jest.SpyInstance;
56+
let inSpy: jest.SpyInstance;
5557

5658
beforeEach(() => {
5759
// core
@@ -67,6 +69,10 @@ describe('cache-restore', () => {
6769
saveStateSpy = jest.spyOn(core, 'saveState');
6870
saveStateSpy.mockImplementation(() => undefined);
6971

72+
inputs = {};
73+
inSpy = jest.spyOn(core, 'getInput');
74+
inSpy.mockImplementation(name => inputs[name]);
75+
7076
// glob
7177
hashFilesSpy = jest.spyOn(glob, 'hashFiles');
7278
hashFilesSpy.mockImplementation((pattern: string) => {
@@ -131,11 +137,12 @@ describe('cache-restore', () => {
131137
return findCacheFolder(command);
132138
}
133139
});
140+
inputs['node-version'] = 'vABC';
134141

135142
await restoreCache(packageManager, '');
136143
expect(hashFilesSpy).toHaveBeenCalled();
137144
expect(infoSpy).toHaveBeenCalledWith(
138-
`Cache restored from key: node-cache-${platform}-${packageManager}-v2-${fileHash}`
145+
`Cache restored from key: node-cache-${platform}-${packageManager}-v2-vABC-${fileHash}`
139146
);
140147
expect(infoSpy).not.toHaveBeenCalledWith(
141148
`${packageManager} cache is not found`

0 commit comments

Comments
 (0)