Add fail-on-cache-miss option

This commit is contained in:
Marc Mueller 2022-12-22 13:10:47 +01:00
parent 6fd2d4538c
commit a5631aba37
11 changed files with 124 additions and 11 deletions

View file

@ -44,6 +44,11 @@ async function restoreImpl(
);
if (!cacheKey) {
if (core.getBooleanInput(Inputs.FailOnCacheMiss) == true) {
throw new Error(
`Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`
);
}
core.info(
`Cache not found for input keys: ${[
primaryKey,
@ -63,6 +68,15 @@ async function restoreImpl(
);
core.setOutput(Outputs.CacheHit, isExactKeyMatch.toString());
if (
!isExactKeyMatch &&
core.getBooleanInput(Inputs.FailOnCacheMiss) == true
) {
throw new Error(
`Restored cache key doesn't match the given input key. Exiting as fail-on-cache-miss is set. Input key: ${primaryKey}`
);
}
core.info(`Cache restored from key: ${cacheKey}`);
return cacheKey;