mirror of
https://code.forgejo.org/actions/cache.git
synced 2026-08-12 22:40:29 +00:00
Add fail-on-error input to fail workflow on cache save errors
This commit is contained in:
parent
27d5ce7f10
commit
b3c661a9c5
8 changed files with 119 additions and 2 deletions
|
|
@ -5,7 +5,9 @@ export enum Inputs {
|
|||
UploadChunkSize = "upload-chunk-size", // Input for cache, save action
|
||||
EnableCrossOsArchive = "enableCrossOsArchive", // Input for cache, restore, save action
|
||||
FailOnCacheMiss = "fail-on-cache-miss", // Input for cache, restore action
|
||||
LookupOnly = "lookup-only" // Input for cache, restore action
|
||||
LookupOnly = "lookup-only", // Input for cache, restore action
|
||||
FailOnError = "fail-on-error", // Input for save action
|
||||
FailOnSaveError = "fail-on-save-error" // Input for cache action (combined), alias for FailOnError
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ export async function saveImpl(
|
|||
stateProvider: IStateProvider
|
||||
): Promise<number | void> {
|
||||
let cacheId = -1;
|
||||
const failOnError =
|
||||
utils.getInputAsBool(Inputs.FailOnSaveError) ||
|
||||
utils.getInputAsBool(Inputs.FailOnError);
|
||||
try {
|
||||
if (!utils.isCacheFeatureAvailable()) {
|
||||
return;
|
||||
|
|
@ -73,7 +76,11 @@ export async function saveImpl(
|
|||
core.info(`Cache saved with key: ${primaryKey}`);
|
||||
}
|
||||
} catch (error: unknown) {
|
||||
utils.logWarning((error as Error).message);
|
||||
if (failOnError) {
|
||||
core.setFailed((error as Error).message);
|
||||
} else {
|
||||
utils.logWarning((error as Error).message);
|
||||
}
|
||||
}
|
||||
return cacheId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,4 +42,6 @@ export function clearInputs(): void {
|
|||
delete process.env[getInputName(Inputs.EnableCrossOsArchive)];
|
||||
delete process.env[getInputName(Inputs.FailOnCacheMiss)];
|
||||
delete process.env[getInputName(Inputs.LookupOnly)];
|
||||
delete process.env[getInputName(Inputs.FailOnError)];
|
||||
delete process.env[getInputName(Inputs.FailOnSaveError)];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue