From 5e9fae966ff78bc09b05b65fda44afba4380386b Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Thu, 11 May 2023 08:01:27 +0100 Subject: [PATCH] fix: cache restore failures (#136) Fix cache restore failures to to upstream bug. Fixes #119 --- dist/restore/index.js | 5 ++++- dist/save/index.js | 5 ++++- src/restore.ts | 5 ++++- src/save.ts | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index 9e923e1..6ea853e 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -60403,7 +60403,10 @@ async function run() { lib_core.saveState(config_STATE_BINS, JSON.stringify([...bins])); lib_core.info(`... Restoring cache ...`); const key = config.cacheKey; - const restoreKey = await cache.restoreCache(config.cachePaths, key, [config.restoreKey]); + // Pass a copy of cachePaths to avoid mutating the original array as reported by: + // https://github.com/actions/toolkit/pull/1378 + // TODO: remove this once the underlying bug is fixed. + const restoreKey = await cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey]); if (restoreKey) { lib_core.info(`Restored from cache key "${restoreKey}".`); lib_core.saveState(STATE_KEY, restoreKey); diff --git a/dist/save/index.js b/dist/save/index.js index b1bc3cb..963ae45 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -60434,7 +60434,10 @@ async function run() { core.info(`[warning] ${e.stack}`); } core.info(`... Saving cache ...`); - await cache.saveCache(config.cachePaths, config.cacheKey); + // Pass a copy of cachePaths to avoid mutating the original array as reported by: + // https://github.com/actions/toolkit/pull/1378 + // TODO: remove this once the underlying bug is fixed. + await cache.saveCache(config.cachePaths.slice(), config.cacheKey); } catch (e) { core.info(`[warning] ${e.stack}`); diff --git a/src/restore.ts b/src/restore.ts index c8320d2..f1280ca 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -34,7 +34,10 @@ async function run() { core.info(`... Restoring cache ...`); const key = config.cacheKey; - const restoreKey = await cache.restoreCache(config.cachePaths, key, [config.restoreKey]); + // Pass a copy of cachePaths to avoid mutating the original array as reported by: + // https://github.com/actions/toolkit/pull/1378 + // TODO: remove this once the underlying bug is fixed. + const restoreKey = await cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey]); if (restoreKey) { core.info(`Restored from cache key "${restoreKey}".`); core.saveState(STATE_KEY, restoreKey); diff --git a/src/save.ts b/src/save.ts index 583e15d..7882120 100644 --- a/src/save.ts +++ b/src/save.ts @@ -66,7 +66,10 @@ async function run() { } core.info(`... Saving cache ...`); - await cache.saveCache(config.cachePaths, config.cacheKey); + // Pass a copy of cachePaths to avoid mutating the original array as reported by: + // https://github.com/actions/toolkit/pull/1378 + // TODO: remove this once the underlying bug is fixed. + await cache.saveCache(config.cachePaths.slice(), config.cacheKey); } catch (e) { core.info(`[warning] ${(e as any).stack}`); }