mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-23 17:23:59 +08:00
Add update-env-variable to force/disable cache update.
This fixes https://github.com/actions/cache/issues/342
This commit is contained in:
parent
b195c997a4
commit
3d41dc5e6b
7 changed files with 136 additions and 10 deletions
35
src/save.ts
35
src/save.ts
|
@ -33,11 +33,36 @@ async function run(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
return;
|
||||
const envVarName = core.getInput(Inputs.UpdateEnvVariable);
|
||||
let forceUpdate;
|
||||
if (envVarName) {
|
||||
let envVarValue;
|
||||
envVarValue = process.env[envVarName];
|
||||
if (["true"].includes(envVarValue.toLowerCase())) {
|
||||
forcedUpdate = true;
|
||||
} else if (["false"].includes(envVarValue.toLowerCase())) {
|
||||
forcedUpdate = false;
|
||||
}
|
||||
}
|
||||
if (forcedUpdate !== undefined) {
|
||||
if (forceUpdate) {
|
||||
core.info(
|
||||
`Cache saving was forced by setting "${envVarName}" to "${envVarValue}".`
|
||||
);
|
||||
} else {
|
||||
core.info(
|
||||
`Cache saving was disabled by setting "${envVarName}" to "${envVarValue}".`
|
||||
);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
core.info(`"${envVarName}" is not set.`);
|
||||
if (utils.isExactKeyMatch(primaryKey, state)) {
|
||||
core.info(
|
||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue