From 885d76835660dd8ac799715699e3e07c524454ca Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 21 Nov 2022 08:35:34 +0000 Subject: [PATCH] Added logic fo saving cache on any failure --- dist/restore/index.js | 7 +++++++ dist/save/index.js | 2 ++ src/constants.ts | 6 ++++-- src/restore.ts | 9 +++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index ea383f5..bb55c86 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -4948,6 +4948,7 @@ var Inputs; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; Inputs["StrictRestore"] = "strict-restore"; + Inputs["SaveCacheOnAnyFailure"] = "save-cache-on-any-failure"; })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { @@ -4957,6 +4958,7 @@ var State; (function (State) { State["CachePrimaryKey"] = "CACHE_KEY"; State["CacheMatchedKey"] = "CACHE_RESULT"; + State["SaveCache"] = "SAVE_CACHE"; })(State = exports.State || (exports.State = {})); var Events; (function (Events) { @@ -49003,6 +49005,11 @@ function run() { throw new Error(`Restored cache key doesn't match the given input key ${primaryKey}, hence exiting the workflow as the strict-restore requirement is not met.`); } core.info(`Cache restored from key: ${cacheKey}`); + const saveCache = core.getInput(constants_1.Inputs.SaveCacheOnAnyFailure); + if (saveCache === "yes") { + core.saveState(constants_1.State.SaveCache, saveCache); + core.info(`Input save-cache-on-any-failure is set to yes, the cache will be saved despite of any failure in the build.`); + } } catch (error) { core.setFailed(error.message); diff --git a/dist/save/index.js b/dist/save/index.js index 8f63267..b4d2721 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -4948,6 +4948,7 @@ var Inputs; Inputs["RestoreKeys"] = "restore-keys"; Inputs["UploadChunkSize"] = "upload-chunk-size"; Inputs["StrictRestore"] = "strict-restore"; + Inputs["SaveCacheOnAnyFailure"] = "save-cache-on-any-failure"; })(Inputs = exports.Inputs || (exports.Inputs = {})); var Outputs; (function (Outputs) { @@ -4957,6 +4958,7 @@ var State; (function (State) { State["CachePrimaryKey"] = "CACHE_KEY"; State["CacheMatchedKey"] = "CACHE_RESULT"; + State["SaveCache"] = "SAVE_CACHE"; })(State = exports.State || (exports.State = {})); var Events; (function (Events) { diff --git a/src/constants.ts b/src/constants.ts index 058493c..03440d3 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -3,7 +3,8 @@ export enum Inputs { Path = "path", RestoreKeys = "restore-keys", UploadChunkSize = "upload-chunk-size", - StrictRestore = "strict-restore" + StrictRestore = "strict-restore", + SaveCacheOnAnyFailure = "save-cache-on-any-failure" } export enum Outputs { @@ -12,7 +13,8 @@ export enum Outputs { export enum State { CachePrimaryKey = "CACHE_KEY", - CacheMatchedKey = "CACHE_RESULT" + CacheMatchedKey = "CACHE_RESULT", + SaveCache = "SAVE_CACHE" } export enum Events { diff --git a/src/restore.ts b/src/restore.ts index da5620c..0ae4ca6 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -63,6 +63,15 @@ async function run(): Promise { ); } core.info(`Cache restored from key: ${cacheKey}`); + + const saveCache = core.getInput(Inputs.SaveCacheOnAnyFailure); + + if (saveCache === "yes") { + core.saveState(State.SaveCache, saveCache); + core.info( + `Input save-cache-on-any-failure is set to yes, the cache will be saved despite of any failure in the build.` + ); + } } catch (error: unknown) { core.setFailed((error as Error).message); }