mirror of
https://code.forgejo.org/actions/cache.git
synced 2024-12-01 10:51:08 -05:00
Also add "force-overwrite" option to save-only action
This commit is contained in:
parent
b70ee8ec79
commit
0d93be3424
2 changed files with 10 additions and 4 deletions
|
@ -15,6 +15,10 @@ inputs:
|
||||||
description: 'An optional boolean when enabled, allows windows runners to save caches that can be restored on other platforms'
|
description: 'An optional boolean when enabled, allows windows runners to save caches that can be restored on other platforms'
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: 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:
|
runs:
|
||||||
using: 'node20'
|
using: 'node20'
|
||||||
main: '../dist/save-only/index.js'
|
main: '../dist/save-only/index.js'
|
||||||
|
|
|
@ -8,7 +8,6 @@ import {
|
||||||
StateProvider
|
StateProvider
|
||||||
} from "./stateProvider";
|
} from "./stateProvider";
|
||||||
import * as utils from "./utils/actionUtils";
|
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
|
// 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
|
// @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);
|
const forceOverwrite = utils.getInputAsBool(Inputs.ForceOverwrite);
|
||||||
if (utils.isExactKeyMatch(primaryKey, restoredKey) && !forceOverwrite) {
|
if (utils.isExactKeyMatch(primaryKey, restoredKey) && !forceOverwrite) {
|
||||||
core.info(
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (utils.isExactKeyMatch(primaryKey, restoredKey) && forceOverwrite) {
|
if ((restoredKey == undefined || utils.isExactKeyMatch(primaryKey, restoredKey)) && forceOverwrite) {
|
||||||
await issueCommand('actions-cache delete', {}, primaryKey);
|
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, {
|
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||||
|
|
Loading…
Reference in a new issue