1
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2024-11-27 14:39:16 +01:00

Also add "force-overwrite" option to save-only action

This commit is contained in:
PrinsFrank 2024-08-02 21:12:44 +02:00
parent b70ee8ec79
commit 0d93be3424
2 changed files with 10 additions and 4 deletions

View file

@ -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'

View file

@ -8,7 +8,6 @@ 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
@ -51,13 +50,16 @@ 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) {
await issueCommand('actions-cache delete', {}, primaryKey);
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.`
);
await cache.deleteCache(primaryKey)
}
const cachePaths = utils.getInputAsArray(Inputs.Path, {