From 6a898d25f06f5e404274fc04835f03f1056b28f8 Mon Sep 17 00:00:00 2001 From: MOREL Matthieu Date: Thu, 26 Aug 2021 15:04:57 +0200 Subject: [PATCH] feat(cache): change key to match actions/cache documentation Signed-off-by: Matthieu MOREL --- __tests__/cache-restore.test.ts | 6 +++--- dist/setup/index.js | 8 +++++--- src/cache-restore.ts | 10 +++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 27f6fa27c..cd9cde55a 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -135,10 +135,10 @@ describe('cache-restore', () => { await restoreCache(packageManager); expect(hashFilesSpy).toHaveBeenCalled(); expect(infoSpy).toHaveBeenCalledWith( - `Cache restored from key: node-cache-${platform}-${packageManager}-${fileHash}` + `Cache restored from key: ${platform}-setup-node-${packageManager}-${fileHash}` ); expect(infoSpy).not.toHaveBeenCalledWith( - `${packageManager} cache is not found` + `Cache not found for input keys: ${platform}-setup-node-${packageManager}-${fileHash}, ${platform}-setup-node-${packageManager}-, ${platform}-setup-node-` ); expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true); } @@ -166,7 +166,7 @@ describe('cache-restore', () => { await restoreCache(packageManager); expect(hashFilesSpy).toHaveBeenCalled(); expect(infoSpy).toHaveBeenCalledWith( - `${packageManager} cache is not found` + `Cache not found for input keys: ${platform}-setup-node-${packageManager}-${fileHash}, ${platform}-setup-node-${packageManager}-, ${platform}-setup-node-` ); expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', false); } diff --git a/dist/setup/index.js b/dist/setup/index.js index ff4bec264..4945fcfce 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -73044,13 +73044,15 @@ const restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0, if (!fileHash) { throw new Error('Some specified paths were not resolved, unable to cache dependencies.'); } - const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`; + const keyPrefix = `${platform}-setup-node-`; + const primaryKey = `${keyPrefix}${packageManager}-${fileHash}`; + const restoreKeys = [`${keyPrefix}${packageManager}-`, keyPrefix]; core.debug(`primary key is ${primaryKey}`); core.saveState(constants_1.State.CachePrimaryKey, primaryKey); - const cacheKey = yield cache.restoreCache([cachePath], primaryKey); + const cacheKey = yield cache.restoreCache([cachePath], primaryKey, restoreKeys); core.setOutput('cache-hit', Boolean(cacheKey)); if (!cacheKey) { - core.info(`${packageManager} cache is not found`); + core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(', ')}`); return; } core.saveState(constants_1.State.CacheMatchedKey, cacheKey); diff --git a/src/cache-restore.ts b/src/cache-restore.ts index 7f761da44..cb81844c5 100644 --- a/src/cache-restore.ts +++ b/src/cache-restore.ts @@ -35,17 +35,17 @@ export const restoreCache = async ( 'Some specified paths were not resolved, unable to cache dependencies.' ); } - - const primaryKey = `node-cache-${platform}-${packageManager}-${fileHash}`; + const keyPrefix = `${platform}-setup-node-`; + const primaryKey = `${keyPrefix}${packageManager}-${fileHash}`; + const restoreKeys = [`${keyPrefix}${packageManager}-`, keyPrefix]; core.debug(`primary key is ${primaryKey}`); - core.saveState(State.CachePrimaryKey, primaryKey); - const cacheKey = await cache.restoreCache([cachePath], primaryKey); + const cacheKey = await cache.restoreCache([cachePath], primaryKey, restoreKeys); core.setOutput('cache-hit', Boolean(cacheKey)); if (!cacheKey) { - core.info(`${packageManager} cache is not found`); + core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(', ')}`); return; }