mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-05-05 01:39:53 +02:00
Allow updating cache with 'update' key
This commit is contained in:
parent
eed9cfe64d
commit
2d697b4d9c
6 changed files with 62 additions and 4 deletions
|
@ -1,7 +1,8 @@
|
|||
export enum Inputs {
|
||||
Key = "key",
|
||||
Path = "path",
|
||||
RestoreKeys = "restore-keys"
|
||||
RestoreKeys = "restore-keys",
|
||||
Update = "update"
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
|
|
|
@ -16,15 +16,17 @@ async function run(): Promise<void> {
|
|||
}
|
||||
|
||||
const state = utils.getCacheState();
|
||||
|
||||
// Inputs are re-evaluted before the post action, so we want the original key used for restore
|
||||
// Inputs are re-evaluated before the post action, so we want the original key used for restore
|
||||
const primaryKey = core.getState(State.CachePrimaryKey);
|
||||
if (!primaryKey) {
|
||||
utils.logWarning(`Error retrieving key from state.`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||
if (
|
||||
utils.isExactKeyMatch(primaryKey, state) &&
|
||||
!utils.getInputAsBoolean(Inputs.Update)
|
||||
) {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
|
|
|
@ -56,3 +56,10 @@ export function getInputAsArray(
|
|||
.map(s => s.trim())
|
||||
.filter(x => x !== "");
|
||||
}
|
||||
|
||||
export function getInputAsBoolean(
|
||||
name: string,
|
||||
options?: core.InputOptions
|
||||
): boolean {
|
||||
return core.getInput(name, options) === "true";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue