diff --git a/dist/restore/index.js b/dist/restore/index.js index 72cc878..dc66796 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -87373,26 +87373,8 @@ async function run() { lookupOnly, }); if (restoreKey) { - const match = restoreKey === key; + let match = restoreKey === key; lib_core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`); - // Restore the incremental-restore.json file and write the mtimes to all the files in the list - if (config.incremental) { - try { - const restoreJson = external_path_default().join(config_CARGO_HOME, "incremental-restore.json"); - const restoreString = await external_fs_default().promises.readFile(restoreJson, "utf8"); - const restoreData = JSON.parse(restoreString); - const incrementalKey = await cacheProvider.cache.restoreCache(restoreData.roots, config.incrementalKey, [config.restoreKey], { lookupOnly }); - lib_core.debug(`restoring incremental builds from ${incrementalKey}`); - for (const [file, mtime] of Object.entries(restoreData.times)) { - lib_core.debug(`restoring ${file} with mtime ${mtime}`); - await external_fs_default().promises.utimes(file, new Date(mtime), new Date(mtime)); - } - } - catch (err) { - lib_core.debug(`Could not restore incremental cache - ${err}`); - lib_core.debug(`${err.stack}`); - } - } if (!match) { // pre-clean the target directory on cache mismatch for (const workspace of config.workspaces) { @@ -87404,6 +87386,28 @@ async function run() { // We restored the cache but it is not a full match. config.saveState(); } + // Restore the incremental-restore.json file and write the mtimes to all the files in the list + if (config.incremental) { + try { + const restoreJson = external_path_default().join(config_CARGO_HOME, "incremental-restore.json"); + const restoreString = await external_fs_default().promises.readFile(restoreJson, "utf8"); + const restoreData = JSON.parse(restoreString); + if (restoreData.roots.length == 0) { + throw new Error("No incremental roots found"); + } + const incrementalKey = await cacheProvider.cache.restoreCache(restoreData.roots, config.incrementalKey, [config.restoreKey], { lookupOnly }); + lib_core.debug(`restoring incremental builds from ${incrementalKey}`); + for (const [file, mtime] of Object.entries(restoreData.times)) { + lib_core.debug(`restoring ${file} with mtime ${mtime}`); + await external_fs_default().promises.utimes(file, new Date(mtime), new Date(mtime)); + } + } + catch (err) { + lib_core.debug(`Could not restore incremental cache - ${err}`); + lib_core.debug(`${err.stack}`); + match = false; + } + } setCacheHitOutput(match); } else { diff --git a/dist/save/index.js b/dist/save/index.js index c1a8ccc..d21f420 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -87334,6 +87334,9 @@ async function rmRF(dirName) { ;// CONCATENATED MODULE: ./src/incremental.ts // import * as core from "@actions/core"; // import * as io from "@actions/io"; +// import { CARGO_HOME } from "./config"; +// import { exists } from "./utils"; +// import { Packages } from "./workspace"; async function saveMtimes(targetDirs) { @@ -87480,30 +87483,6 @@ async function macOsWorkaround() { } catch { } } -// async function saveIncrementalDirs(incrementalDir: string) { -// // Traverse the incremental folder recursively and collect the modified times in a map -// const modifiedTimes = new Map(); -// const fillModifiedTimes = async (dir: string) => { -// const dirEntries = await fs.promises.opendir(dir); -// for await (const dirent of dirEntries) { -// if (dirent.isDirectory()) { -// await fillModifiedTimes(path.join(dir, dirent.name)); -// } else { -// const fileName = path.join(dir, dirent.name); -// const { mtime } = await fs.promises.stat(fileName); -// modifiedTimes.set(fileName, mtime.getTime()); -// } -// } -// }; -// await fillModifiedTimes(incrementalDir); -// // Write the modified times to the incremental folder -// 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); -// } })(); diff --git a/src/incremental.ts b/src/incremental.ts index b33272e..2738179 100644 --- a/src/incremental.ts +++ b/src/incremental.ts @@ -1,12 +1,12 @@ // import * as core from "@actions/core"; // import * as io from "@actions/io"; -import fs from "fs"; -import path from "path"; - // import { CARGO_HOME } from "./config"; // import { exists } from "./utils"; // import { Packages } from "./workspace"; +import fs from "fs"; +import path from "path"; + export type MtimeData = { roots: Array, times: Map diff --git a/src/restore.ts b/src/restore.ts index 81f9142..9a8c7e9 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -49,9 +49,21 @@ async function run() { lookupOnly, }); if (restoreKey) { - const match = restoreKey === key; + let match = restoreKey === key; core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`); + if (!match) { + // pre-clean the target directory on cache mismatch + for (const workspace of config.workspaces) { + try { + await cleanTargetDir(workspace.target, [], true); + } catch { } + } + + // We restored the cache but it is not a full match. + config.saveState(); + } + // Restore the incremental-restore.json file and write the mtimes to all the files in the list if (config.incremental) { try { @@ -59,6 +71,10 @@ async function run() { const restoreString = await fs.promises.readFile(restoreJson, "utf8"); const restoreData: MtimeData = JSON.parse(restoreString); + if (restoreData.roots.length == 0) { + throw new Error("No incremental roots found"); + } + const incrementalKey = await cacheProvider.cache.restoreCache(restoreData.roots, config.incrementalKey, [config.restoreKey], { lookupOnly }); core.debug(`restoring incremental builds from ${incrementalKey}`); @@ -70,21 +86,10 @@ async function run() { } catch (err) { core.debug(`Could not restore incremental cache - ${err}`); core.debug(`${(err as any).stack}`); + match = false; } } - if (!match) { - // pre-clean the target directory on cache mismatch - for (const workspace of config.workspaces) { - try { - await cleanTargetDir(workspace.target, [], true); - } catch { } - } - - // We restored the cache but it is not a full match. - config.saveState(); - } - setCacheHitOutput(match); } else { core.info(`No cache found for ${config.cacheKey} - this key was found ${restoreKey}`); diff --git a/src/save.ts b/src/save.ts index 259087b..be36fbc 100644 --- a/src/save.ts +++ b/src/save.ts @@ -120,31 +120,3 @@ async function macOsWorkaround() { await exec.exec("sudo", ["/usr/sbin/purge"], { silent: true }); } catch { } } - - -// async function saveIncrementalDirs(incrementalDir: string) { -// // Traverse the incremental folder recursively and collect the modified times in a map -// const modifiedTimes = new Map(); -// const fillModifiedTimes = async (dir: string) => { -// const dirEntries = await fs.promises.opendir(dir); -// for await (const dirent of dirEntries) { -// if (dirent.isDirectory()) { -// await fillModifiedTimes(path.join(dir, dirent.name)); -// } else { -// const fileName = path.join(dir, dirent.name); -// const { mtime } = await fs.promises.stat(fileName); -// modifiedTimes.set(fileName, mtime.getTime()); -// } -// } -// }; -// await fillModifiedTimes(incrementalDir); - -// // Write the modified times to the incremental folder -// 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); - -// }