From 860bb139dc711587ce3904e443ba3f84b5acbc8a Mon Sep 17 00:00:00 2001 From: Ari Kishon <37385467+Ari-Kishon@users.noreply.github.com> Date: Thu, 31 Aug 2023 12:29:33 +0300 Subject: [PATCH 1/4] feat(cache): add flag to only restore cache --- action.yml | 3 +++ src/cache-save.ts | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/action.yml b/action.yml index 56025a40..534de6c7 100644 --- a/action.yml +++ b/action.yml @@ -25,6 +25,9 @@ inputs: description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.' cache-dependency-path: description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.' + cache-restore-only: + description: 'Set this option if you dont want to save the cache when it couldnt be restored.' + default: false # TODO: add input to control forcing to pull from cloud or dist. # escape valve for someone having issues or needing the absolute latest which isn't cached yet outputs: diff --git a/src/cache-save.ts b/src/cache-save.ts index 0b071019..09b9ad93 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -33,6 +33,10 @@ const cachePackages = async (packageManager: string) => { core.debug(`Caching for '${packageManager}' is not supported`); return; } + if (core.getInput('cache-restore-only') == true ){ + core.info(`Cache was not saved since 'cache-restore-only' was set }`); + return; + } if (!cachePaths.length) { // TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?) From 99e06de4da4210a44361006b15e474e1ad917c53 Mon Sep 17 00:00:00 2001 From: Ariki Date: Thu, 31 Aug 2023 13:07:22 +0300 Subject: [PATCH 2/4] build --- dist/cache-save/index.js | 4 ++++ src/cache-save.ts | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 2287d08a..81a0817a 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -60395,6 +60395,10 @@ const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, func core.debug(`Caching for '${packageManager}' is not supported`); return; } + if (core.getInput('cache-restore-only') == 'true') { + core.info(`Cache was not saved since 'cache-restore-only' was set to true}`); + return; + } if (!cachePaths.length) { // TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?) // export declare function getInput(name: string, options?: InputOptions): string; diff --git a/src/cache-save.ts b/src/cache-save.ts index 09b9ad93..57449913 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -33,8 +33,10 @@ const cachePackages = async (packageManager: string) => { core.debug(`Caching for '${packageManager}' is not supported`); return; } - if (core.getInput('cache-restore-only') == true ){ - core.info(`Cache was not saved since 'cache-restore-only' was set }`); + if (core.getInput('cache-restore-only') == 'true') { + core.info( + `Cache was not saved since 'cache-restore-only' was set to true}` + ); return; } From 0e31e1abff2d690b0f91894524c87540a32b4300 Mon Sep 17 00:00:00 2001 From: Ariki Date: Thu, 31 Aug 2023 15:27:44 +0300 Subject: [PATCH 3/4] fix typo --- dist/cache-save/index.js | 2 +- src/cache-save.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/dist/cache-save/index.js b/dist/cache-save/index.js index 81a0817a..654cbbf9 100644 --- a/dist/cache-save/index.js +++ b/dist/cache-save/index.js @@ -60396,7 +60396,7 @@ const cachePackages = (packageManager) => __awaiter(void 0, void 0, void 0, func return; } if (core.getInput('cache-restore-only') == 'true') { - core.info(`Cache was not saved since 'cache-restore-only' was set to true}`); + core.info(`Cache was not saved since 'cache-restore-only' was set to true`); return; } if (!cachePaths.length) { diff --git a/src/cache-save.ts b/src/cache-save.ts index 57449913..352b1a53 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -34,9 +34,7 @@ const cachePackages = async (packageManager: string) => { return; } if (core.getInput('cache-restore-only') == 'true') { - core.info( - `Cache was not saved since 'cache-restore-only' was set to true}` - ); + core.info(`Cache was not saved since 'cache-restore-only' was set to true`); return; } From 1dbaf4855d86fc58c931fdd50636b8503f95b9ac Mon Sep 17 00:00:00 2001 From: Ari Kishon <37385467+Ari-Kishon@users.noreply.github.com> Date: Thu, 31 Aug 2023 15:39:42 +0300 Subject: [PATCH 4/4] chore: update readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 8c15b445..c27a8755 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,10 @@ See [action.yml](action.yml) # Default: '' cache-dependency-path: '' + # Set this option if you dont want the action to save the cache if it couldnt be restored + # Default: false + cache-restore-only: '' + # Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, # and set up auth to read in from env.NODE_AUTH_TOKEN. # Default: ''