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

View File

@ -11,13 +11,15 @@ async function run() {
core.exportVariable("CARGO_INCREMENTAL", 0);
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 {
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);
if (restoreKey) {
core.info(`Restored "${path}" from cache key "${restoreKey}".`);
core.saveState(name, restoreKey);
core.info(`Restored from cache key "${restoreKey}".`);
core.saveState(type, restoreKey);
} else {
core.info("No cache found.");
}

View File

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