mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-23 03:45:31 +00:00
Added test cases
This commit is contained in:
parent
a172494938
commit
9c5a42a7c9
4 changed files with 137 additions and 12 deletions
|
@ -36,17 +36,19 @@ async function run(): Promise<void> {
|
|||
);
|
||||
|
||||
//Check if user wants to save cache despite of failure in any previous job
|
||||
const saveCache = core.getInput(Inputs.SaveOnAnyFailure);
|
||||
if (saveCache === "yes") {
|
||||
core.debug(`save cache input variable is set to yes`);
|
||||
const saveCache = core.getBooleanInput(Inputs.SaveOnAnyFailure);
|
||||
if (saveCache == true) {
|
||||
core.debug(
|
||||
`Exporting environment variable ${Variables.SaveCacheOnAnyFailure}`
|
||||
);
|
||||
core.exportVariable(Variables.SaveCacheOnAnyFailure, saveCache);
|
||||
core.info(
|
||||
`Input Variable ${Variables.SaveCacheOnAnyFailure} is set to yes, the cache will be saved despite of any failure in the build.`
|
||||
`Input Variable ${Variables.SaveCacheOnAnyFailure} is set to true, the cache will be saved despite of any failure in the build.`
|
||||
);
|
||||
}
|
||||
|
||||
if (!cacheKey) {
|
||||
if (core.getInput(Inputs.StrictRestore) == "yes") {
|
||||
if (core.getBooleanInput(Inputs.StrictRestore) == true) {
|
||||
throw new Error(
|
||||
`Cache with the given input key ${primaryKey} is not found, hence exiting the workflow as the strict-restore requirement is not met.`
|
||||
);
|
||||
|
@ -65,7 +67,10 @@ async function run(): Promise<void> {
|
|||
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
|
||||
utils.setCacheHitOutput(isExactKeyMatch);
|
||||
|
||||
if (!isExactKeyMatch && core.getInput(Inputs.StrictRestore) == "yes") {
|
||||
if (
|
||||
!isExactKeyMatch &&
|
||||
core.getBooleanInput(Inputs.StrictRestore) == true
|
||||
) {
|
||||
throw new Error(
|
||||
`Restored cache key doesn't match the given input key ${primaryKey}, hence exiting the workflow as the strict-restore requirement is not met.`
|
||||
);
|
||||
|
|
|
@ -13,18 +13,27 @@ interface CacheInput {
|
|||
path: string;
|
||||
key: string;
|
||||
restoreKeys?: string[];
|
||||
strictRestore?: string;
|
||||
saveOnAnyFailure?: string;
|
||||
}
|
||||
|
||||
export function setInputs(input: CacheInput): void {
|
||||
setInput(Inputs.Path, input.path);
|
||||
setInput(Inputs.Key, input.key);
|
||||
setInput(Inputs.SaveOnAnyFailure, "false");
|
||||
setInput(Inputs.StrictRestore, "false");
|
||||
input.restoreKeys &&
|
||||
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
|
||||
input.strictRestore && setInput(Inputs.StrictRestore, input.strictRestore);
|
||||
input.saveOnAnyFailure &&
|
||||
setInput(Inputs.SaveOnAnyFailure, input.saveOnAnyFailure);
|
||||
}
|
||||
|
||||
export function clearInputs(): void {
|
||||
delete process.env[getInputName(Inputs.Path)];
|
||||
delete process.env[getInputName(Inputs.Key)];
|
||||
delete process.env[getInputName(Inputs.RestoreKeys)];
|
||||
delete process.env[getInputName(Inputs.StrictRestore)];
|
||||
delete process.env[getInputName(Inputs.SaveOnAnyFailure)];
|
||||
delete process.env[getInputName(Inputs.UploadChunkSize)];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue