You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cache/src/restore.ts

71 lines
2.0 KiB
TypeScript

import * as cache from "@actions/cache";
5 years ago
import * as core from "@actions/core";
import { Events, Inputs, State } from "./constants";
5 years ago
import * as utils from "./utils/actionUtils";
async function run(): Promise<void> {
5 years ago
try {
// 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;
}
5 years ago
const primaryKey = core.getInput(Inputs.Key, { required: true });
core.saveState(State.CachePrimaryKey, primaryKey);
5 years ago
const restoreKeys = core
.getInput(Inputs.RestoreKeys)
.split("\n")
.filter(x => x !== "");
5 years ago
const cachePaths = core
.getInput(Inputs.Path, { required: true })
.split("\n")
.filter(x => x !== "");
5 years ago
try {
const cacheKey = await cache.restoreCache(
cachePaths,
primaryKey,
restoreKeys
5 years ago
);
if (!cacheKey) {
core.info(
`Cache not found for input keys: ${[
primaryKey,
...restoreKeys
].join(", ")}`
5 years ago
);
return;
}
// Store the matched cache key
utils.setCacheState(cacheKey);
5 years ago
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
5 years ago
utils.setCacheHitOutput(isExactKeyMatch);
core.info(`Cache restored from key: ${cacheKey}`);
5 years ago
} catch (error) {
if (error.name === cache.ValidationError.name) {
throw error;
} else {
utils.logWarning(error.message);
utils.setCacheHitOutput(false);
}
5 years ago
}
} catch (error) {
core.setFailed(error.message);
}
}
run();
export default run;