Skip to content

feat: add input to only restore cache without saving #844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/cache-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 to true`);
return;
}

if (!cachePaths.length) {
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
Expand Down