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 5afc636
Showing 6 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion dist/restore-only/index.js
Original file line number Diff line number Diff line change
@@ -59324,7 +59324,8 @@ var Inputs;
Inputs["UploadChunkSize"] = "upload-chunk-size";
Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive";
Inputs["FailOnCacheMiss"] = "fail-on-cache-miss";
Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action
Inputs["LookupOnly"] = "lookup-only";
Inputs["ForceOverwrite"] = "force-overwrite"; // Input for cache action
})(Inputs = exports.Inputs || (exports.Inputs = {}));
var Outputs;
(function (Outputs) {
3 changes: 2 additions & 1 deletion dist/restore/index.js
Original file line number Diff line number Diff line change
@@ -59324,7 +59324,8 @@ var Inputs;
Inputs["UploadChunkSize"] = "upload-chunk-size";
Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive";
Inputs["FailOnCacheMiss"] = "fail-on-cache-miss";
Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action
Inputs["LookupOnly"] = "lookup-only";
Inputs["ForceOverwrite"] = "force-overwrite"; // Input for cache action
})(Inputs = exports.Inputs || (exports.Inputs = {}));
var Outputs;
(function (Outputs) {
13 changes: 10 additions & 3 deletions dist/save-only/index.js
Original file line number Diff line number Diff line change
@@ -59324,7 +59324,8 @@ var Inputs;
Inputs["UploadChunkSize"] = "upload-chunk-size";
Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive";
Inputs["FailOnCacheMiss"] = "fail-on-cache-miss";
Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action
Inputs["LookupOnly"] = "lookup-only";
Inputs["ForceOverwrite"] = "force-overwrite"; // Input for cache action
})(Inputs = exports.Inputs || (exports.Inputs = {}));
var Outputs;
(function (Outputs) {
@@ -59392,6 +59393,7 @@ const core = __importStar(__nccwpck_require__(2186));
const constants_1 = __nccwpck_require__(9042);
const stateProvider_1 = __nccwpck_require__(1527);
const utils = __importStar(__nccwpck_require__(6850));
const command_1 = __nccwpck_require__(7351);
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
// throw an uncaught exception. Instead of failing this action, just warn.
@@ -59418,10 +59420,15 @@ function saveImpl(stateProvider) {
// If matched restore key is same as primary key, then do not save cache
// NO-OP in case of SaveOnly action
const restoredKey = stateProvider.getCacheState();
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
const forceOverwrite = utils.getInputAsBool(constants_1.Inputs.ForceOverwrite);
if (utils.isExactKeyMatch(primaryKey, restoredKey) && !forceOverwrite) {
core.info(`Cache hit occurred on the primary key "${primaryKey}" and force-overwrite is disabled, not saving cache.`);
return;
}
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}".`);
yield (0, command_1.issueCommand)('actions-cache delete', {}, primaryKey);
}
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
required: true
});
13 changes: 10 additions & 3 deletions dist/save/index.js
Original file line number Diff line number Diff line change
@@ -59324,7 +59324,8 @@ var Inputs;
Inputs["UploadChunkSize"] = "upload-chunk-size";
Inputs["EnableCrossOsArchive"] = "enableCrossOsArchive";
Inputs["FailOnCacheMiss"] = "fail-on-cache-miss";
Inputs["LookupOnly"] = "lookup-only"; // Input for cache, restore action
Inputs["LookupOnly"] = "lookup-only";
Inputs["ForceOverwrite"] = "force-overwrite"; // Input for cache action
})(Inputs = exports.Inputs || (exports.Inputs = {}));
var Outputs;
(function (Outputs) {
@@ -59392,6 +59393,7 @@ const core = __importStar(__nccwpck_require__(2186));
const constants_1 = __nccwpck_require__(9042);
const stateProvider_1 = __nccwpck_require__(1527);
const utils = __importStar(__nccwpck_require__(6850));
const command_1 = __nccwpck_require__(7351);
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
// throw an uncaught exception. Instead of failing this action, just warn.
@@ -59418,10 +59420,15 @@ function saveImpl(stateProvider) {
// If matched restore key is same as primary key, then do not save cache
// NO-OP in case of SaveOnly action
const restoredKey = stateProvider.getCacheState();
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
core.info(`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`);
const forceOverwrite = utils.getInputAsBool(constants_1.Inputs.ForceOverwrite);
if (utils.isExactKeyMatch(primaryKey, restoredKey) && !forceOverwrite) {
core.info(`Cache hit occurred on the primary key "${primaryKey}" and force-overwrite is disabled, not saving cache.`);
return;
}
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}".`);
yield (0, command_1.issueCommand)('actions-cache delete', {}, primaryKey);
}
const cachePaths = utils.getInputAsArray(constants_1.Inputs.Path, {
required: true
});
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'
7 changes: 5 additions & 2 deletions src/saveImpl.ts
Original file line number Diff line number Diff line change
@@ -51,12 +51,15 @@ export async function saveImpl(
const forceOverwrite = utils.getInputAsBool(Inputs.ForceOverwrite);
if (utils.isExactKeyMatch(primaryKey, restoredKey) && !forceOverwrite) {
core.info(
`Cache hit occurred on the primary key ${primaryKey} and force-overwrite is disabled, not saving cache.`
`Cache hit occurred on the primary key "${primaryKey}" and force-overwrite is disabled, not saving cache.`
);
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 5afc636

Please sign in to comment.