1
0
Fork 0
mirror of https://code.forgejo.org/actions/cache.git synced 2025-05-05 01:39:53 +02:00

Fix caching using update key

This commit is contained in:
Eliza Brock Marcum 2020-06-24 13:50:45 -05:00
parent 2d697b4d9c
commit 5b41e77e7a
5 changed files with 21 additions and 28 deletions

View file

@ -16,21 +16,25 @@ async function run(): Promise<void> {
}
const state = utils.getCacheState();
// Inputs are re-evaluated before the post action, so we want the original key used for restore
// Inputs are re-evaluted 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) &&
!utils.getInputAsBoolean(Inputs.Update)
) {
core.info(
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
);
return;
if (utils.isExactKeyMatch(primaryKey, state)) {
if (core.getInput(Inputs.Update) === "true") {
core.info(
`Cache hit occurred on the primary key ${primaryKey}, but updates were enabled, so updating cache.`
);
} else {
core.info(
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
);
return;
}
}
const cachePaths = utils.getInputAsArray(Inputs.Path, {

View file

@ -56,10 +56,3 @@ 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";
}

View file

@ -13,11 +13,13 @@ interface CacheInput {
path: string;
key: string;
restoreKeys?: string[];
update: string;
}
export function setInputs(input: CacheInput): void {
setInput(Inputs.Path, input.path);
setInput(Inputs.Key, input.key);
setInput(Inputs.Update, input.update);
input.restoreKeys &&
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
}
@ -25,5 +27,6 @@ export function setInputs(input: CacheInput): void {
export function clearInputs(): void {
delete process.env[getInputName(Inputs.Path)];
delete process.env[getInputName(Inputs.Key)];
delete process.env[getInputName(Inputs.Update)];
delete process.env[getInputName(Inputs.RestoreKeys)];
}