cache/src/restore.ts

59 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-10-30 14:48:49 -04:00
import * as core from "@actions/core";
2021-09-30 15:21:04 -05:00
import { CacheService } from "./cache.service";
import { Inputs, State } from "./constants";
2019-10-30 14:48:49 -04:00
import * as utils from "./utils/actionUtils";
2019-11-13 06:48:02 +09:00
async function run(): Promise<void> {
2019-10-30 14:48:49 -04:00
try {
const primaryKey = core.getInput(Inputs.Key, { required: true });
core.saveState(State.CachePrimaryKey, primaryKey);
2019-10-30 14:48:49 -04:00
2020-06-02 10:21:03 -05:00
const restoreKeys = utils.getInputAsArray(Inputs.RestoreKeys);
const cachePaths = utils.getInputAsArray(Inputs.Path, {
required: true
});
2019-10-30 14:48:49 -04:00
try {
2021-09-30 15:21:04 -05:00
const cache: CacheService = new CacheService(
core.getInput(Inputs.AccessKeyId),
core.getInput(Inputs.SecretAccessKey),
core.getInput(Inputs.Region),
core.getInput(Inputs.Bucket)
);
const cacheKey = await cache.restoreCache(
cachePaths,
primaryKey,
restoreKeys
2019-10-30 14:48:49 -04:00
);
if (!cacheKey) {
core.info(
`Cache not found for input keys: ${[
primaryKey,
...restoreKeys
].join(", ")}`
2019-10-30 14:48:49 -04:00
);
return;
}
// Store the matched cache key
utils.setCacheState(cacheKey);
2019-10-30 14:48:49 -04:00
const isExactKeyMatch = utils.isExactKeyMatch(primaryKey, cacheKey);
2019-10-30 14:48:49 -04:00
utils.setCacheHitOutput(isExactKeyMatch);
core.info(`Cache restored from key: ${cacheKey}`);
2019-10-30 14:48:49 -04:00
} catch (error) {
2021-09-30 15:21:04 -05:00
utils.logWarning(error.message);
utils.setCacheHitOutput(false);
2019-10-30 14:48:49 -04:00
}
} catch (error) {
core.setFailed(error.message);
}
}
run();
export default run;