From d2e3f417a9f5c5fbb2e1dc8a90d8ec7104e6f036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Sch=C3=BCnadel?= <2677030+schuenadel@users.noreply.github.com> Date: Thu, 7 Apr 2022 10:58:22 +0200 Subject: [PATCH] Set output `cache-hit` to indicate if cache was hit (#275) --- README.md | 2 ++ dist/cleanup/index.js | 2 ++ dist/setup/index.js | 2 ++ src/cache.ts | 2 ++ 4 files changed, 8 insertions(+) diff --git a/README.md b/README.md index c02eb6c..af8ea78 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,8 @@ The action has a built-in functionality for caching and restoring dependencies. - gradle: `**/*.gradle*`, `**/gradle-wrapper.properties` - maven: `**/pom.xml` +The workflow output `cache-hit` is set to indicate if an exact match was found for the key [as actions/cache does](https://github.com/actions/cache/tree/main#outputs). + The cache input is optional, and caching is turned off by default. #### Caching gradle dependencies diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 5457896..5a2461d 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -61925,9 +61925,11 @@ function restore(id) { ]); if (matchedKey) { core.saveState(CACHE_MATCHED_KEY, matchedKey); + core.setOutput('cache-hit', matchedKey === primaryKey); core.info(`Cache restored from key: ${matchedKey}`); } else { + core.setOutput('cache-hit', false); core.info(`${packageManager.id} cache is not found`); } }); diff --git a/dist/setup/index.js b/dist/setup/index.js index b37a811..9f46644 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -18662,9 +18662,11 @@ function restore(id) { ]); if (matchedKey) { core.saveState(CACHE_MATCHED_KEY, matchedKey); + core.setOutput('cache-hit', matchedKey === primaryKey); core.info(`Cache restored from key: ${matchedKey}`); } else { + core.setOutput('cache-hit', false); core.info(`${packageManager.id} cache is not found`); } }); diff --git a/src/cache.ts b/src/cache.ts index fb97fb0..3948a5a 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -77,8 +77,10 @@ export async function restore(id: string) { ]); if (matchedKey) { core.saveState(CACHE_MATCHED_KEY, matchedKey); + core.setOutput('cache-hit', matchedKey === primaryKey); core.info(`Cache restored from key: ${matchedKey}`); } else { + core.setOutput('cache-hit', false); core.info(`${packageManager.id} cache is not found`); } }