From d1178716dbbe024f9d459612c22072517a781faa Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 3 Sep 2021 18:34:37 +0000 Subject: [PATCH] Add 'cache-hit' as output --- __tests__/cache-restore.test.ts | 2 ++ action.yml | 3 +++ dist/setup/index.js | 1 + src/cache-restore.ts | 1 + 4 files changed, 7 insertions(+) diff --git a/__tests__/cache-restore.test.ts b/__tests__/cache-restore.test.ts index 483f8eb6..27f6fa27 100644 --- a/__tests__/cache-restore.test.ts +++ b/__tests__/cache-restore.test.ts @@ -140,6 +140,7 @@ describe('cache-restore', () => { expect(infoSpy).not.toHaveBeenCalledWith( `${packageManager} cache is not found` ); + expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true); } ); }); @@ -167,6 +168,7 @@ describe('cache-restore', () => { expect(infoSpy).toHaveBeenCalledWith( `${packageManager} cache is not found` ); + expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', false); } ); }); diff --git a/action.yml b/action.yml index 66daef0c..e50fa0e6 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,9 @@ inputs: version: description: 'Deprecated. Use node-version instead. Will not be supported after October 1, 2019' deprecationMessage: 'The version property will not be supported after October 1, 2019. Use node-version instead' +outputs: + cache-hit: + description: 'A boolean value to indicate if a cache was hit' runs: using: 'node12' main: 'dist/setup/index.js' diff --git a/dist/setup/index.js b/dist/setup/index.js index d0f495dd..e649b358 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -44674,6 +44674,7 @@ exports.restoreCache = (packageManager, cacheDependencyPath) => __awaiter(void 0 core.debug(`primary key is ${primaryKey}`); core.saveState(constants_1.State.CachePrimaryKey, primaryKey); const cacheKey = yield cache.restoreCache([cachePath], primaryKey); + core.setOutput('cache-hit', Boolean(cacheKey)); if (!cacheKey) { core.info(`${packageManager} cache is not found`); return; diff --git a/src/cache-restore.ts b/src/cache-restore.ts index cd128cb1..d49b27fc 100644 --- a/src/cache-restore.ts +++ b/src/cache-restore.ts @@ -42,6 +42,7 @@ export const restoreCache = async ( core.saveState(State.CachePrimaryKey, primaryKey); const cacheKey = await cache.restoreCache([cachePath], primaryKey); + core.setOutput('cache-hit', Boolean(cacheKey)); if (!cacheKey) { core.info(`${packageManager} cache is not found`);