Reverted wrapper changes

This commit is contained in:
Sankalp Kotewar 2022-11-29 10:56:53 +00:00 committed by GitHub
parent f8717682fb
commit a172494938
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 166 additions and 222 deletions

View file

@ -1,7 +1,81 @@
import restore from "./restoreImpl";
import * as cache from "@actions/cache";
import * as core from "@actions/core";
async function runRestoreStep(): Promise<void> {
await restore();
import { Events, Inputs, State, Variables } from "./constants";
import * as utils from "./utils/actionUtils";
async function run(): Promise<void> {
try {
if (!utils.isCacheFeatureAvailable()) {
utils.setCacheHitOutput(false);
return;
}
// Validate inputs, this can cause task failure
if (!utils.isValidEvent()) {
utils.logWarning(
`Event Validation Error: The event type ${
process.env[Events.Key]
} is not supported because it's not tied to a branch or tag ref.`
);
return;
}
const primaryKey = core.getInput(Inputs.Key, { required: true });
core.saveState(State.CachePrimaryKey, primaryKey);
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
const cachePaths = utils.getInputAsArray(Inputs.Path, {
required: true
});
const cacheKey = await cache.restoreCache(
cachePaths,
primaryKey,
restoreKeys
);
//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`);
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.`
);
}
if (!cacheKey) {
if (core.getInput(Inputs.StrictRestore) == "yes") {
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.`
);
}
core.info(
`Cache not found for input keys: ${[
primaryKey,
...restoreKeys
].join(", ")}`
);
return;
}
// Store the matched cache key
utils.setCacheState(cacheKey);
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
utils.setCacheHitOutput(isExactKeyMatch);
if (!isExactKeyMatch && core.getInput(Inputs.StrictRestore) == "yes") {
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.`
);
}
core.info(`Cache restored from key: ${cacheKey}`);
} catch (error: unknown) {
core.setFailed((error as Error).message);
}
}
runRestoreStep();
run();
export default run;

View file

@ -1,26 +0,0 @@
import * as core from "@actions/core";
import { Inputs } from "../constants";
import restore from "../restoreImpl";
async function runRestoreAction(): Promise<void> {
if (core.getInput(Inputs.SaveOnAnyFailure) != "") {
core.warning(
`${Inputs.SaveOnAnyFailure} value is passed in the input, this input is invalid for the restore-only action and hence will be ignored`
);
}
if (core.getInput(Inputs.UploadChunkSize) != "") {
core.warning(
`${Inputs.UploadChunkSize} value is passed in the input, this input is invalid for the restore-only action and hence will be ignored`
);
}
core.info("before run");
await restore();
core.info("after run");
}
core.info("before runRestoreAction");
runRestoreAction();
core.info("after runRestoreAction");
core.info("after export default runRestoreAction");

View file

@ -1,79 +0,0 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { Events, Inputs, State, Variables } from "./constants";
import * as utils from "./utils/actionUtils";
async function run(): Promise<void> {
try {
if (!utils.isCacheFeatureAvailable()) {
utils.setCacheHitOutput(false);
return;
}
// Validate inputs, this can cause task failure
if (!utils.isValidEvent()) {
utils.logWarning(
`Event Validation Error: The event type ${
process.env[Events.Key]
} is not supported because it's not tied to a branch or tag ref.`
);
return;
}
const primaryKey = core.getInput(Inputs.Key, { required: true });
core.saveState(State.CachePrimaryKey, primaryKey);
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
const cachePaths = utils.getInputAsArray(Inputs.Path, {
required: true
});
const cacheKey = await cache.restoreCache(
cachePaths,
primaryKey,
restoreKeys
);
//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`);
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.`
);
}
if (!cacheKey) {
if (core.getInput(Inputs.StrictRestore) == "yes") {
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.`
);
}
core.info(
`Cache not found for input keys: ${[
primaryKey,
...restoreKeys
].join(", ")}`
);
return;
}
// Store the matched cache key
utils.setCacheState(cacheKey);
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
utils.setCacheHitOutput(isExactKeyMatch);
if (!isExactKeyMatch && core.getInput(Inputs.StrictRestore) == "yes") {
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.`
);
}
core.info(`Cache restored from key: ${cacheKey}`);
} catch (error: unknown) {
core.setFailed((error as Error).message);
}
}
export default run;