Skip to content

Commit 6a898d2

Browse files
mmorel-35voxpelli
authored andcommitted
feat(cache): change key to match actions/cache documentation
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 7c29869 commit 6a898d2

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

__tests__/cache-restore.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ describe('cache-restore', () => {
135135
await restoreCache(packageManager);
136136
expect(hashFilesSpy).toHaveBeenCalled();
137137
expect(infoSpy).toHaveBeenCalledWith(
138-
`Cache restored from key: node-cache-${platform}-${packageManager}-${fileHash}`
138+
`Cache restored from key: ${platform}-setup-node-${packageManager}-${fileHash}`
139139
);
140140
expect(infoSpy).not.toHaveBeenCalledWith(
141-
`${packageManager} cache is not found`
141+
`Cache not found for input keys: ${platform}-setup-node-${packageManager}-${fileHash}, ${platform}-setup-node-${packageManager}-, ${platform}-setup-node-`
142142
);
143143
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
144144
}
@@ -166,7 +166,7 @@ describe('cache-restore', () => {
166166
await restoreCache(packageManager);
167167
expect(hashFilesSpy).toHaveBeenCalled();
168168
expect(infoSpy).toHaveBeenCalledWith(
169-
`${packageManager} cache is not found`
169+
`Cache not found for input keys: ${platform}-setup-node-${packageManager}-${fileHash}, ${platform}-setup-node-${packageManager}-, ${platform}-setup-node-`
170170
);
171171
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', false);
172172
}

dist/setup/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73044,13 +73044,15 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0,
7304473044
if (!fileHash) {
7304573045
throw new Error('Some specified paths were not resolved, unable to cache dependencies.');
7304673046
}
73047-
const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
73047+
const keyPrefix = `${platform}-setup-node-`;
73048+
const primaryKey = `${keyPrefix}${packageManager}-${fileHash}`;
73049+
const restoreKeys = [`${keyPrefix}${packageManager}-`, keyPrefix];
7304873050
core.debug(`primary key is ${primaryKey}`);
7304973051
core.saveState(constants_1.State.CachePrimaryKey, primaryKey);
73050-
const cacheKey = yield cache.restoreCache([cachePath], primaryKey);
73052+
const cacheKey = yield cache.restoreCache([cachePath], primaryKey, restoreKeys);
7305173053
core.setOutput('cache-hit', Boolean(cacheKey));
7305273054
if (!cacheKey) {
73053-
core.info(`${packageManager} cache is not found`);
73055+
core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(', ')}`);
7305473056
return;
7305573057
}
7305673058
core.saveState(constants_1.State.CacheMatchedKey, cacheKey);

src/cache-restore.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ export const restoreCache = async (
3535
'Some specified paths were not resolved, unable to cache dependencies.'
3636
);
3737
}
38-
39-
const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`;
38+
const keyPrefix = `${platform}-setup-node-`;
39+
const primaryKey = `${keyPrefix}${packageManager}-${fileHash}`;
40+
const restoreKeys = [`${keyPrefix}${packageManager}-`, keyPrefix];
4041
core.debug(`primary key is ${primaryKey}`);
41-
4242
core.saveState(State.CachePrimaryKey, primaryKey);
4343

44-
const cacheKey = await cache.restoreCache([cachePath], primaryKey);
44+
const cacheKey = await cache.restoreCache([cachePath], primaryKey, restoreKeys);
4545
core.setOutput('cache-hit', Boolean(cacheKey));
4646

4747
if (!cacheKey) {
48-
core.info(`${packageManager} cache is not found`);
48+
core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(', ')}`);
4949
return;
5050
}
5151

0 commit comments

Comments
 (0)