Skip to content

Commit

Permalink
Also add "force-overwrite" option to save-only action
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinsFrank committed Aug 2, 2024
1 parent b70ee8e commit e457006
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions save/action.yml
Original file line number Diff line number Diff line change
@@ -15,6 +15,10 @@ inputs:
description: 'An optional boolean when enabled, allows windows runners to save caches that can be restored on other platforms'
default: 'false'
required: false
force-overwrite:
description: 'Delete any previous (incremental) cache before pushing a new cache even if a cache for the primary cache key exists'
default: 'false'
required: false
runs:
using: 'node20'
main: '../dist/save-only/index.js'
5 changes: 4 additions & 1 deletion src/saveImpl.ts
Original file line number Diff line number Diff line change
@@ -56,7 +56,10 @@ export async function saveImpl(
return;
}

if (utils.isExactKeyMatch(primaryKey, restoredKey) && forceOverwrite) {
if ((restoredKey == undefined || utils.isExactKeyMatch(primaryKey, restoredKey)) && forceOverwrite) {
core.info(
`Cache hit occurred on the primary key ${primaryKey} or running as save-only and force-overwrite is enabled, deleting cache for key ${primaryKey}.`
);
await issueCommand('actions-cache delete', {}, primaryKey);
}

0 comments on commit e457006

Please sign in to comment.