3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-04-07 13:45:20 +00:00

improve logging

This commit is contained in:
Arpad Borsos 2020-09-28 11:54:24 +02:00
parent 8902a8fc6c
commit cfcc373039
3 changed files with 32 additions and 14 deletions

View file

@ -15,6 +15,7 @@ export const paths = {
}; };
export interface CacheConfig { export interface CacheConfig {
name: string;
path: string; path: string;
key: string; key: string;
restoreKeys?: Array<string>; restoreKeys?: Array<string>;
@ -45,10 +46,25 @@ export async function getCaches(): Promise<Caches> {
targetKey = `${targetKey}-`; targetKey = `${targetKey}-`;
} }
return { return {
index: { path: paths.index, key: "registry-index-XXX", restoreKeys: ["registry-index"] }, index: {
cache: { path: paths.cache, key: `registry-cache-${lockHash}`, restoreKeys: ["registry-cache"] }, name: "Registry Index",
git: { path: paths.git, key: "git-db" }, path: paths.index,
key: "registry-index-XXX",
restoreKeys: ["registry-index"],
},
cache: {
name: "Registry Cache",
path: paths.cache,
key: `registry-cache-${lockHash}`,
restoreKeys: ["registry-cache"],
},
git: {
name: "Git Dependencies",
path: paths.git,
key: "git-db",
},
target: { target: {
name: "Target",
path: paths.target, path: paths.target,
key: `target-${targetKey}${rustKey}-${lockHash}`, key: `target-${targetKey}${rustKey}-${lockHash}`,
restoreKeys: [`target-${targetKey}${rustKey}`], restoreKeys: [`target-${targetKey}${rustKey}`],

View file

@ -11,13 +11,15 @@ async function run() {
core.exportVariable("CARGO_INCREMENTAL", 0); core.exportVariable("CARGO_INCREMENTAL", 0);
const caches = await getCaches(); const caches = await getCaches();
for (const [name, { path, key, restoreKeys }] of Object.entries(caches)) { for (const [type, { name, path, key, restoreKeys }] of Object.entries(caches)) {
try { try {
core.startGroup(`Restoring "${path}" from "${key}"…`); core.startGroup(`Restoring ${name}"…`);
core.info(`Restoring to path "${path}".`);
core.info(`Using keys:\n ${[key, ...restoreKeys].join("\n ")}`);
const restoreKey = await cache.restoreCache([path], key, restoreKeys); const restoreKey = await cache.restoreCache([path], key, restoreKeys);
if (restoreKey) { if (restoreKey) {
core.info(`Restored "${path}" from cache key "${restoreKey}".`); core.info(`Restored from cache key "${restoreKey}".`);
core.saveState(name, restoreKey); core.saveState(type, restoreKey);
} else { } else {
core.info("No cache found."); core.info("No cache found.");
} }

View file

@ -28,16 +28,16 @@ async function run() {
delete (caches as any).cache; delete (caches as any).cache;
} }
for (const [name, { path, key }] of Object.entries(caches)) { for (const [type, { name, path, key }] of Object.entries(caches)) {
if (core.getState(name) === key) { if (core.getState(type) === key) {
core.info(`Cache for "${path}" up-to-date.`); core.info(`${name} up-to-date.`);
continue; continue;
} }
try { try {
core.startGroup(`Saving "${path}" to cache key "${key}"`); core.startGroup(`Saving ${name}`);
if (await cache.saveCache([path], key)) { core.info(`Saving path "${path}".`);
core.info(`Saved "${path}" to cache key "${key}".`); core.info(`Using key "${key}".`);
} await cache.saveCache([path], key);
} catch (e) { } catch (e) {
core.info(`[warning] ${e.message}`); core.info(`[warning] ${e.message}`);
} finally { } finally {