From 70758ffdc7fafcf0ff9ca2eb6017bce7a7665dcc Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Tue, 28 Jan 2025 21:14:58 -0800 Subject: [PATCH] better logging, better staging --- src/cleanup.ts | 6 +++++- src/save.ts | 15 +++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cleanup.ts b/src/cleanup.ts index 85e6903..b4700b1 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -79,11 +79,15 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT await fillModifiedTimes(incrementalDir); // Write the modified times to the incremental folder - core.debug(`writing incremental-restore.json for ${incrementalDir} with ${modifiedTimes} files`); + core.debug(`writing incremental-restore.json for ${incrementalDir} files`); + for (const file of modifiedTimes.keys()) { + core.debug(` ${file} -> ${modifiedTimes.get(file)}`); + } const contents = JSON.stringify({ modifiedTimes }); await fs.promises.writeFile(path.join(incrementalDir, "incremental-restore.json"), contents); } + await rmExcept(profileDir, keepProfile); const keepPkg = new Set(packages.map((p) => p.name)); diff --git a/src/save.ts b/src/save.ts index 78532fd..b91beeb 100644 --- a/src/save.ts +++ b/src/save.ts @@ -4,6 +4,7 @@ import * as exec from "@actions/exec"; import { cleanBin, cleanGit, cleanRegistry, cleanTargetDir } from "./cleanup"; import { CacheConfig, isCacheUpToDate } from "./config"; import { getCacheProvider, reportError } from "./utils"; +import { rm } from "fs/promises"; process.on("uncaughtException", (e) => { core.error(e.message); @@ -72,16 +73,22 @@ async function run() { core.debug(`${(e as any).stack}`); } + // Save the incremental cache before we delete it + if (config.incremental) { + core.info(`... Saving incremental cache ...`); + await cacheProvider.cache.saveCache(config.incrementalPaths.slice(), config.incrementalKey); + for (const path of config.incrementalPaths) { + core.debug(` deleting ${path}`); + await rm(path); + } + } + core.info(`... Saving cache ...`); // Pass a copy of cachePaths to avoid mutating the original array as reported by: // https://github.com/actions/toolkit/pull/1378 // TODO: remove this once the underlying bug is fixed. await cacheProvider.cache.saveCache(config.cachePaths.slice(), config.cacheKey); - if (config.incremental) { - core.info(`... Saving incremental cache ...`); - await cacheProvider.cache.saveCache(config.incrementalPaths.slice(), config.incrementalKey); - } } catch (e) { reportError(e); }