mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-03-31 20:17:48 +02:00
Merge 0d93be3424
into 81382a721f
This commit is contained in:
commit
5f0f1db391
5 changed files with 25 additions and 4 deletions
|
@ -14,6 +14,10 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
|
|||
|
||||
## What's New
|
||||
|
||||
### Unreleased
|
||||
|
||||
* Added the `force-overwrite` flag to force overwrite any existing cache for incremental caching
|
||||
|
||||
### v4
|
||||
|
||||
* Updated to node 20
|
||||
|
|
|
@ -29,7 +29,11 @@ inputs:
|
|||
save-always:
|
||||
description: 'Run the post step to save the cache even if another step before fails'
|
||||
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
|
||||
outputs:
|
||||
cache-hit:
|
||||
description: 'A boolean value to indicate an exact match was found for the primary key'
|
||||
|
|
|
@ -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,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 {
|
||||
|
|
|
@ -47,13 +47,21 @@ 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 ((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, {
|
||||
required: true
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue