3
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-04-23 03:45:31 +00:00

Add force-overwrite for cache

This commit is contained in:
Frank Prins 2024-01-22 18:54:37 +01:00
parent a2ed59d39b
commit 7dd9af18b0
4 changed files with 19 additions and 4 deletions

View file

@ -5,7 +5,8 @@ export enum Inputs {
UploadChunkSize = "upload-chunk-size", // Input for cache, save action
EnableCrossOsArchive = "enableCrossOsArchive", // Input for cache, restore, save action
FailOnCacheMiss = "fail-on-cache-miss", // Input for cache, restore action
LookupOnly = "lookup-only" // Input for cache, restore action
LookupOnly = "lookup-only", // Input for cache, restore action
ForceOverwrite = "force-overwrite" // Input for cache action
}
export enum Outputs {

View file

@ -8,6 +8,7 @@ import {
StateProvider
} from "./stateProvider";
import * as utils from "./utils/actionUtils";
import { issueCommand } from "@actions/core/lib/command";
// 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
@ -47,13 +48,18 @@ export async function saveImpl(
// NO-OP in case of SaveOnly action
const restoredKey = stateProvider.getCacheState();
if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
const forceOverwrite = utils.getInputAsBool(Inputs.ForceOverwrite);
if (utils.isExactKeyMatch(primaryKey, restoredKey) && !forceOverwrite) {
core.info(
`Cache hit occurred on the primary key ${primaryKey}, 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) {
await issueCommand('actions-cache delete', {}, primaryKey);
}
const cachePaths = utils.getInputAsArray(Inputs.Path, {
required: true
});