Saving state early to take care of all cases

This commit is contained in:
Sankalp Kotewar 2022-11-21 08:45:08 +00:00 committed by GitHub
parent 8c4782cf33
commit 91d3f2deb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View file

@ -35,6 +35,15 @@ async function run(): Promise<void> {
restoreKeys
);
//Check if user wants to save cache despite of failure in any previous job
const saveCache = core.getInput(Inputs.SaveCacheOnAnyFailure);
if (saveCache === "yes") {
core.saveState(State.SaveCache, saveCache);
core.info(
`Input save-cache-on-any-failure is set to yes, the cache will be saved despite of any failure in the build.`
);
}
if (!cacheKey) {
if (core.getInput(Inputs.StrictRestore) == "true") {
throw new Error(
@ -63,15 +72,6 @@ async function run(): Promise<void> {
);
}
core.info(`Cache restored from key: ${cacheKey}`);
const saveCache = core.getInput(Inputs.SaveCacheOnAnyFailure);
if (saveCache === "yes") {
core.saveState(State.SaveCache, saveCache);
core.info(
`Input save-cache-on-any-failure is set to yes, the cache will be saved despite of any failure in the build.`
);
}
} catch (error: unknown) {
core.setFailed((error as Error).message);
}