3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2026-02-15 15:21:53 +00:00

merge all the caches and simplify

This commit is contained in:
Arpad Borsos 2020-10-03 18:39:38 +02:00
parent f77cb1be47
commit e8e3c57b3b
8 changed files with 197 additions and 259 deletions

View file

@ -1,6 +1,6 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { getCaches, isValidEvent } from "./common";
import { getCacheConfig, isValidEvent, stateKey } from "./common";
async function run() {
if (!isValidEvent()) {
@ -10,28 +10,26 @@ async function run() {
try {
core.exportVariable("CARGO_INCREMENTAL", 0);
const caches = await getCaches();
for (const [type, { name, paths, key, restoreKeys }] of Object.entries(caches)) {
const start = Date.now();
core.startGroup(`Restoring ${name}`);
core.info(`Restoring paths:\n ${paths.join("\n ")}.`);
core.info(`Using keys:\n ${[key, ...restoreKeys].join("\n ")}`);
try {
const restoreKey = await cache.restoreCache(paths, key, restoreKeys);
if (restoreKey) {
core.info(`Restored from cache key "${restoreKey}".`);
core.saveState(`CACHEKEY-${type}`, restoreKey);
} else {
core.info("No cache found.");
}
} catch (e) {
core.info(`[warning] ${e.message}`);
const start = Date.now();
const { paths, key, restoreKeys } = await getCacheConfig();
core.info(`Restoring paths:\n ${paths.join("\n ")}.`);
core.info(`Using keys:\n ${[key, ...restoreKeys].join("\n ")}`);
try {
const restoreKey = await cache.restoreCache(paths, key, restoreKeys);
if (restoreKey) {
core.info(`Restored from cache key "${restoreKey}".`);
core.saveState(stateKey, restoreKey);
} else {
core.info("No cache found.");
}
const duration = Math.round((Date.now() - start) / 1000);
if (duration) {
core.info(`Took ${duration}s.`);
}
core.endGroup();
} catch (e) {
core.info(`[warning] ${e.message}`);
}
const duration = Math.round((Date.now() - start) / 1000);
if (duration) {
core.info(`Took ${duration}s.`);
}
} catch (e) {
core.info(`[warning] ${e.message}`);