From fca91510b6c4ce9588673e46940aae6f2870ed12 Mon Sep 17 00:00:00 2001 From: Nick Mosher Date: Fri, 8 Jul 2022 20:47:09 -0400 Subject: [PATCH] Rename config variable to 'workspace-paths' --- dist/restore/index.js | 310 +++------------------ dist/save/index.js | 430 ++++------------------------- package-lock.json | 617 +----------------------------------------- src/common.ts | 22 +- src/restore.ts | 8 +- src/save.ts | 7 +- 6 files changed, 108 insertions(+), 1286 deletions(-) diff --git a/dist/restore/index.js b/dist/restore/index.js index cfbd8cd..901c94e 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -61585,6 +61585,9 @@ __nccwpck_require__.r(__webpack_exports__); var cache = __nccwpck_require__(7799); // EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js var core = __nccwpck_require__(2186); +// EXTERNAL MODULE: external "path" +var external_path_ = __nccwpck_require__(1017); +var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_); // EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js var exec = __nccwpck_require__(1514); // EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js @@ -61600,262 +61603,7 @@ var external_fs_default = /*#__PURE__*/__nccwpck_require__.n(external_fs_); // EXTERNAL MODULE: external "os" var external_os_ = __nccwpck_require__(2037); var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_); -// EXTERNAL MODULE: external "path" -var external_path_ = __nccwpck_require__(1017); -var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_); ;// CONCATENATED MODULE: ./src/common.ts -<<<<<<< HEAD - - - - - - - - -process.on("uncaughtException", (e) => { - core.info(`[warning] ${e.message}`); - if (e.stack) { - core.info(e.stack); - } -}); -const cwd = core.getInput("working-directory"); -// TODO: this could be read from .cargo config file directly -const targetDir = core.getInput("target-dir") || "./target"; -if (cwd) { - process.chdir(cwd); -} -const stateBins = "RUST_CACHE_BINS"; -const stateKey = "RUST_CACHE_KEY"; -const stateHash = "RUST_CACHE_HASH"; -const home = external_os_default().homedir(); -const cargoHome = process.env.CARGO_HOME || external_path_default().join(home, ".cargo"); -const paths = { - cargoHome, - index: external_path_default().join(cargoHome, "registry/index"), - cache: external_path_default().join(cargoHome, "registry/cache"), - git: external_path_default().join(cargoHome, "git"), - target: targetDir, -}; -const RefKey = "GITHUB_REF"; -function isValidEvent() { - return RefKey in process.env && Boolean(process.env[RefKey]); -} -async function getCacheConfig() { - let lockHash = core.getState(stateHash); - if (!lockHash) { - lockHash = await getLockfileHash(); - core.saveState(stateHash, lockHash); - } - let key = `v0-rust-`; - const sharedKey = core.getInput("sharedKey"); - if (sharedKey) { - key += `${sharedKey}-`; - } - else { - const inputKey = core.getInput("key"); - if (inputKey) { - key += `${inputKey}-`; - } - const job = process.env.GITHUB_JOB; - if (job) { - key += `${job}-`; - } - } - key += await getRustKey(); - return { - paths: [ - external_path_default().join(cargoHome, "bin"), - external_path_default().join(cargoHome, ".crates2.json"), - external_path_default().join(cargoHome, ".crates.toml"), - paths.git, - paths.cache, - paths.index, - paths.target, - ], - key: `${key}-${lockHash}`, - restoreKeys: [key], - }; -} -async function getCargoBins() { - try { - const { installs } = JSON.parse(await external_fs_default().promises.readFile(external_path_default().join(paths.cargoHome, ".crates2.json"), "utf8")); - const bins = new Set(); - for (const pkg of Object.values(installs)) { - for (const bin of pkg.bins) { - bins.add(bin); - } - } - return bins; - } - catch { - return new Set(); - } -} -async function getRustKey() { - const rustc = await getRustVersion(); - return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`; -} -async function getRustVersion() { - const stdout = await getCmdOutput("rustc", ["-vV"]); - let splits = stdout - .split(/[\n\r]+/) - .filter(Boolean) - .map((s) => s.split(":").map((s) => s.trim())) - .filter((s) => s.length === 2); - return Object.fromEntries(splits); -} -async function getCmdOutput(cmd, args = [], options = {}) { - let stdout = ""; - await exec.exec(cmd, args, { - silent: true, - listeners: { - stdout(data) { - stdout += data.toString(); - }, - }, - ...options, - }); - return stdout; -} -async function getLockfileHash() { - const globber = await glob.create("**/Cargo.toml\n**/Cargo.lock\nrust-toolchain\nrust-toolchain.toml", { - followSymbolicLinks: false, - }); - const files = await globber.glob(); - files.sort((a, b) => a.localeCompare(b)); - const hasher = external_crypto_default().createHash("sha1"); - for (const file of files) { - for await (const chunk of external_fs_default().createReadStream(file)) { - hasher.update(chunk); - } - } - return hasher.digest("hex").slice(0, 20); -} -async function getPackages() { - const cwd = process.cwd(); - const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"])); - return meta.packages - .filter((p) => !p.manifest_path.startsWith(cwd)) - .map((p) => { - const targets = p.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name); - return { name: p.name, version: p.version, targets, path: external_path_default().dirname(p.manifest_path) }; - }); -} -async function cleanTarget(packages) { - await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json")); - await cleanProfileTarget(packages, "debug"); - await cleanProfileTarget(packages, "release"); -} -async function cleanProfileTarget(packages, profile) { - try { - await external_fs_default().promises.access(external_path_default().join(targetDir, profile)); - } - catch { - return; - } - await io.rmRF(external_path_default().join(targetDir, profile, "./examples")); - await io.rmRF(external_path_default().join(targetDir, profile, "./incremental")); - let dir; - // remove all *files* from the profile directory - dir = await external_fs_default().promises.opendir(external_path_default().join(targetDir, profile)); - for await (const dirent of dir) { - if (dirent.isFile()) { - await rm(dir.path, dirent); - } - } - const keepPkg = new Set(packages.map((p) => p.name)); - await rmExcept(external_path_default().join(targetDir, profile, "./build"), keepPkg); - await rmExcept(external_path_default().join(targetDir, profile, "./.fingerprint"), keepPkg); - const keepDeps = new Set(packages.flatMap((p) => { - const names = []; - for (const n of [p.name, ...p.targets]) { - const name = n.replace(/-/g, "_"); - names.push(name, `lib${name}`); - } - return names; - })); - await rmExcept(external_path_default().join(targetDir, profile, "./deps"), keepDeps); -} -const oneWeek = 7 * 24 * 3600 * 1000; -async function rmExcept(dirName, keepPrefix) { - const dir = await external_fs_default().promises.opendir(dirName); - for await (const dirent of dir) { - let name = dirent.name; - const idx = name.lastIndexOf("-"); - if (idx !== -1) { - name = name.slice(0, idx); - } - const fileName = external_path_default().join(dir.path, dirent.name); - const { mtime } = await external_fs_default().promises.stat(fileName); - // we don’t really know - if (!keepPrefix.has(name) || Date.now() - mtime.getTime() > oneWeek) { - await rm(dir.path, dirent); - } - } -} -async function rm(parent, dirent) { - try { - const fileName = external_path_default().join(parent, dirent.name); - core.debug(`deleting "${fileName}"`); - if (dirent.isFile()) { - await external_fs_default().promises.unlink(fileName); - } - else if (dirent.isDirectory()) { - await io.rmRF(fileName); - } - } - catch { } -} - -;// CONCATENATED MODULE: ./src/restore.ts - - - -async function run() { - if (!cache.isFeatureAvailable()) { - setCacheHitOutput(false); - return; - } - try { - var cacheOnFailure = core.getInput("cache-on-failure").toLowerCase(); - if (cacheOnFailure !== "true") { - cacheOnFailure = "false"; - } - core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure); - core.exportVariable("CARGO_INCREMENTAL", 0); - const { paths, key, restoreKeys } = await getCacheConfig(); - const bins = await getCargoBins(); - core.saveState(stateBins, JSON.stringify([...bins])); - core.info(`Restoring paths:\n ${paths.join("\n ")}`); - core.info(`In directory:\n ${process.cwd()}`); - core.info(`Using keys:\n ${[key, ...restoreKeys].join("\n ")}`); - const restoreKey = await cache.restoreCache(paths, key, restoreKeys); - if (restoreKey) { - core.info(`Restored from cache key "${restoreKey}".`); - core.saveState(stateKey, restoreKey); - if (restoreKey !== key) { - // pre-clean the target directory on cache mismatch - const packages = await getPackages(); - await cleanTarget(packages); - } - setCacheHitOutput(restoreKey === key); - } - else { - core.info("No cache found."); - setCacheHitOutput(false); - } - } - catch (e) { - setCacheHitOutput(false); - core.info(`[warning] ${e.stack}`); - } -} -function setCacheHitOutput(cacheHit) { - core.setOutput("cache-hit", cacheHit.toString()); -} -run(); -======= @@ -61871,11 +61619,10 @@ process.on("uncaughtException", (e) => { } }); const cwd = core.getInput("working-directory"); -// Read each line of target-dir as a unique target directory +// Read each line of workspace-paths as a unique path // TODO: this could be read from .cargo config file directly -const targetDirInput = core.getInput("target-dir") || "./target"; -const targetDirs = targetDirInput.trim().split("\n"); -core.info("Using target dirs: " + JSON.stringify(targetDirs)); +const workspacePathsInput = core.getInput("workspace-paths") || "./"; +const workspacePaths = workspacePathsInput.trim().split("\n"); if (cwd) { process.chdir(cwd); } @@ -61889,7 +61636,7 @@ const paths = { index: external_path_default().join(cargoHome, "registry/index"), cache: external_path_default().join(cargoHome, "registry/cache"), git: external_path_default().join(cargoHome, "git"), - targets: targetDirs, + workspaces: workspacePaths, }; const RefKey = "GITHUB_REF"; function isValidEvent() { @@ -61928,7 +61675,7 @@ async function getCacheConfig() { ], key: `${key}-${lockHash}`, restoreKeys: [key], - targets: paths.targets, + workspaces: paths.workspaces, }; } async function getCargoBins() { @@ -61977,7 +61724,7 @@ async function getLockfileHash() { followSymbolicLinks: false, }); const files = await globber.glob(); - core.info("Lockfile Hash includes: " + JSON.stringify(files)); + core.debug("Lockfile Hash includes: " + JSON.stringify(files)); files.sort((a, b) => a.localeCompare(b)); const hasher = external_crypto_default().createHash("sha1"); for (const file of files) { @@ -61999,19 +61746,29 @@ async function getPackages() { } async function cleanTarget(targetDir, packages) { await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json")); - await io.rmRF(external_path_default().join(targetDir, "./debug/examples")); - await io.rmRF(external_path_default().join(targetDir, "./debug/incremental")); + await cleanProfileTarget(targetDir, packages, "debug"); + await cleanProfileTarget(targetDir, packages, "release"); +} +async function cleanProfileTarget(targetDir, packages, profile) { + try { + await external_fs_default().promises.access(external_path_default().join(targetDir, profile)); + } + catch { + return; + } + await io.rmRF(external_path_default().join(targetDir, profile, "./examples")); + await io.rmRF(external_path_default().join(targetDir, profile, "./incremental")); let dir; - // remove all *files* from debug - dir = await external_fs_default().promises.opendir(external_path_default().join(targetDir, "./debug")); + // remove all *files* from the profile directory + dir = await external_fs_default().promises.opendir(external_path_default().join(targetDir, profile)); for await (const dirent of dir) { if (dirent.isFile()) { await rm(dir.path, dirent); } } const keepPkg = new Set(packages.map((p) => p.name)); - await rmExcept(external_path_default().join(targetDir, "./debug/build"), keepPkg); - await rmExcept(external_path_default().join(targetDir, "./debug/.fingerprint"), keepPkg); + await rmExcept(external_path_default().join(targetDir, profile, "./build"), keepPkg); + await rmExcept(external_path_default().join(targetDir, profile, "./.fingerprint"), keepPkg); const keepDeps = new Set(packages.flatMap((p) => { const names = []; for (const n of [p.name, ...p.targets]) { @@ -62020,7 +61777,7 @@ async function cleanTarget(targetDir, packages) { } return names; })); - await rmExcept(external_path_default().join(targetDir, "./debug/deps"), keepDeps); + await rmExcept(external_path_default().join(targetDir, profile, "./deps"), keepDeps); } const oneWeek = 7 * 24 * 3600 * 1000; async function rmExcept(dirName, keepPrefix) { @@ -62057,7 +61814,12 @@ async function rm(parent, dirent) { + async function run() { + if (!cache.isFeatureAvailable()) { + setCacheHitOutput(false); + return; + } try { var cacheOnFailure = core.getInput("cache-on-failure").toLowerCase(); if (cacheOnFailure !== "true") { @@ -62065,8 +61827,8 @@ async function run() { } core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure); core.exportVariable("CARGO_INCREMENTAL", 0); - const { paths, key, restoreKeys, targets } = await getCacheConfig(); - const restorePaths = paths.concat(targets); + const { paths, key, restoreKeys, workspaces } = await getCacheConfig(); + const restorePaths = paths.concat(workspaces); const bins = await getCargoBins(); core.saveState(stateBins, JSON.stringify([...bins])); core.info(`Restoring paths:\n ${restorePaths.join("\n ")}`); @@ -62079,7 +61841,8 @@ async function run() { if (restoreKey !== key) { // pre-clean the target directory on cache mismatch const packages = await getPackages(); - for (const target of targets) { + for (const workspace of workspaces) { + const target = external_path_default().join(workspace, "target"); await cleanTarget(target, packages); } } @@ -62092,14 +61855,13 @@ async function run() { } catch (e) { setCacheHitOutput(false); - core.info(`[warning] ${e.message}`); + core.info(`[warning] ${e.stack}`); } } function setCacheHitOutput(cacheHit) { core.setOutput("cache-hit", cacheHit.toString()); } run(); ->>>>>>> 16da4ac (Cache multiple target directories from 'target-dir') })(); diff --git a/dist/save/index.js b/dist/save/index.js index a361db6..0fbf3f5 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -61604,359 +61604,6 @@ var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto var external_os_ = __nccwpck_require__(2037); var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_); ;// CONCATENATED MODULE: ./src/common.ts -<<<<<<< HEAD - - - - - - - - -process.on("uncaughtException", (e) => { - core.info(`[warning] ${e.message}`); - if (e.stack) { - core.info(e.stack); - } -}); -const cwd = core.getInput("working-directory"); -// TODO: this could be read from .cargo config file directly -const targetDir = core.getInput("target-dir") || "./target"; -if (cwd) { - process.chdir(cwd); -} -const stateBins = "RUST_CACHE_BINS"; -const stateKey = "RUST_CACHE_KEY"; -const stateHash = "RUST_CACHE_HASH"; -const home = external_os_default().homedir(); -const cargoHome = process.env.CARGO_HOME || external_path_default().join(home, ".cargo"); -const paths = { - cargoHome, - index: external_path_default().join(cargoHome, "registry/index"), - cache: external_path_default().join(cargoHome, "registry/cache"), - git: external_path_default().join(cargoHome, "git"), - target: targetDir, -}; -const RefKey = "GITHUB_REF"; -function isValidEvent() { - return RefKey in process.env && Boolean(process.env[RefKey]); -} -async function getCacheConfig() { - let lockHash = core.getState(stateHash); - if (!lockHash) { - lockHash = await getLockfileHash(); - core.saveState(stateHash, lockHash); - } - let key = `v0-rust-`; - const sharedKey = core.getInput("sharedKey"); - if (sharedKey) { - key += `${sharedKey}-`; - } - else { - const inputKey = core.getInput("key"); - if (inputKey) { - key += `${inputKey}-`; - } - const job = process.env.GITHUB_JOB; - if (job) { - key += `${job}-`; - } - } - key += await getRustKey(); - return { - paths: [ - external_path_default().join(cargoHome, "bin"), - external_path_default().join(cargoHome, ".crates2.json"), - external_path_default().join(cargoHome, ".crates.toml"), - paths.git, - paths.cache, - paths.index, - paths.target, - ], - key: `${key}-${lockHash}`, - restoreKeys: [key], - }; -} -async function getCargoBins() { - try { - const { installs } = JSON.parse(await external_fs_default().promises.readFile(external_path_default().join(paths.cargoHome, ".crates2.json"), "utf8")); - const bins = new Set(); - for (const pkg of Object.values(installs)) { - for (const bin of pkg.bins) { - bins.add(bin); - } - } - return bins; - } - catch { - return new Set(); - } -} -async function getRustKey() { - const rustc = await getRustVersion(); - return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`; -} -async function getRustVersion() { - const stdout = await getCmdOutput("rustc", ["-vV"]); - let splits = stdout - .split(/[\n\r]+/) - .filter(Boolean) - .map((s) => s.split(":").map((s) => s.trim())) - .filter((s) => s.length === 2); - return Object.fromEntries(splits); -} -async function getCmdOutput(cmd, args = [], options = {}) { - let stdout = ""; - await exec.exec(cmd, args, { - silent: true, - listeners: { - stdout(data) { - stdout += data.toString(); - }, - }, - ...options, - }); - return stdout; -} -async function getLockfileHash() { - const globber = await glob.create("**/Cargo.toml\n**/Cargo.lock\nrust-toolchain\nrust-toolchain.toml", { - followSymbolicLinks: false, - }); - const files = await globber.glob(); - files.sort((a, b) => a.localeCompare(b)); - const hasher = external_crypto_default().createHash("sha1"); - for (const file of files) { - for await (const chunk of external_fs_default().createReadStream(file)) { - hasher.update(chunk); - } - } - return hasher.digest("hex").slice(0, 20); -} -async function getPackages() { - const cwd = process.cwd(); - const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"])); - return meta.packages - .filter((p) => !p.manifest_path.startsWith(cwd)) - .map((p) => { - const targets = p.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name); - return { name: p.name, version: p.version, targets, path: external_path_default().dirname(p.manifest_path) }; - }); -} -async function cleanTarget(packages) { - await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json")); - await cleanProfileTarget(packages, "debug"); - await cleanProfileTarget(packages, "release"); -} -async function cleanProfileTarget(packages, profile) { - try { - await external_fs_default().promises.access(external_path_default().join(targetDir, profile)); - } - catch { - return; - } - await io.rmRF(external_path_default().join(targetDir, profile, "./examples")); - await io.rmRF(external_path_default().join(targetDir, profile, "./incremental")); - let dir; - // remove all *files* from the profile directory - dir = await external_fs_default().promises.opendir(external_path_default().join(targetDir, profile)); - for await (const dirent of dir) { - if (dirent.isFile()) { - await rm(dir.path, dirent); - } - } - const keepPkg = new Set(packages.map((p) => p.name)); - await rmExcept(external_path_default().join(targetDir, profile, "./build"), keepPkg); - await rmExcept(external_path_default().join(targetDir, profile, "./.fingerprint"), keepPkg); - const keepDeps = new Set(packages.flatMap((p) => { - const names = []; - for (const n of [p.name, ...p.targets]) { - const name = n.replace(/-/g, "_"); - names.push(name, `lib${name}`); - } - return names; - })); - await rmExcept(external_path_default().join(targetDir, profile, "./deps"), keepDeps); -} -const oneWeek = 7 * 24 * 3600 * 1000; -async function rmExcept(dirName, keepPrefix) { - const dir = await external_fs_default().promises.opendir(dirName); - for await (const dirent of dir) { - let name = dirent.name; - const idx = name.lastIndexOf("-"); - if (idx !== -1) { - name = name.slice(0, idx); - } - const fileName = external_path_default().join(dir.path, dirent.name); - const { mtime } = await external_fs_default().promises.stat(fileName); - // we don’t really know - if (!keepPrefix.has(name) || Date.now() - mtime.getTime() > oneWeek) { - await rm(dir.path, dirent); - } - } -} -async function rm(parent, dirent) { - try { - const fileName = external_path_default().join(parent, dirent.name); - core.debug(`deleting "${fileName}"`); - if (dirent.isFile()) { - await external_fs_default().promises.unlink(fileName); - } - else if (dirent.isDirectory()) { - await io.rmRF(fileName); - } - } - catch { } -} - -;// CONCATENATED MODULE: ./src/save.ts - - - - - - - - -async function run() { - if (!cache.isFeatureAvailable()) { - return; - } - try { - const { paths: savePaths, key } = await getCacheConfig(); - if (core.getState(stateKey) === key) { - core.info(`Cache up-to-date.`); - return; - } - // TODO: remove this once https://github.com/actions/toolkit/pull/553 lands - await macOsWorkaround(); - const registryName = await getRegistryName(); - const packages = await getPackages(); - if (registryName) { - try { - await cleanRegistry(registryName, packages); - } - catch (e) { - core.info(`[warning] ${e.stack}`); - } - } - try { - await cleanBin(); - } - catch (e) { - core.info(`[warning] ${e.stack}`); - } - try { - await cleanGit(packages); - } - catch (e) { - core.info(`[warning] ${e.stack}`); - } - try { - await cleanTarget(packages); - } - catch (e) { - core.info(`[warning] ${e.stack}`); - } - core.info(`Saving paths:\n ${savePaths.join("\n ")}`); - core.info(`In directory:\n ${process.cwd()}`); - core.info(`Using key:\n ${key}`); - await cache.saveCache(savePaths, key); - } - catch (e) { - core.info(`[warning] ${e.stack}`); - } -} -run(); -async function getRegistryName() { - const globber = await glob.create(`${paths.index}/**/.last-updated`, { followSymbolicLinks: false }); - const files = await globber.glob(); - if (files.length > 1) { - core.warning(`got multiple registries: "${files.join('", "')}"`); - } - const first = files.shift(); - if (!first) { - return null; - } - return external_path_default().basename(external_path_default().dirname(first)); -} -async function cleanBin() { - const bins = await getCargoBins(); - const oldBins = JSON.parse(core.getState(stateBins)); - for (const bin of oldBins) { - bins.delete(bin); - } - const dir = await external_fs_default().promises.opendir(external_path_default().join(paths.cargoHome, "bin")); - for await (const dirent of dir) { - if (dirent.isFile() && !bins.has(dirent.name)) { - await rm(dir.path, dirent); - } - } -} -async function cleanRegistry(registryName, packages) { - await io.rmRF(external_path_default().join(paths.index, registryName, ".cache")); - const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`)); - const dir = await external_fs_default().promises.opendir(external_path_default().join(paths.cache, registryName)); - for await (const dirent of dir) { - if (dirent.isFile() && !pkgSet.has(dirent.name)) { - await rm(dir.path, dirent); - } - } -} -async function cleanGit(packages) { - const coPath = external_path_default().join(paths.git, "checkouts"); - const dbPath = external_path_default().join(paths.git, "db"); - const repos = new Map(); - for (const p of packages) { - if (!p.path.startsWith(coPath)) { - continue; - } - const [repo, ref] = p.path.slice(coPath.length + 1).split((external_path_default()).sep); - const refs = repos.get(repo); - if (refs) { - refs.add(ref); - } - else { - repos.set(repo, new Set([ref])); - } - } - // we have to keep both the clone, and the checkout, removing either will - // trigger a rebuild - let dir; - // clean the db - dir = await external_fs_default().promises.opendir(dbPath); - for await (const dirent of dir) { - if (!repos.has(dirent.name)) { - await rm(dir.path, dirent); - } - } - // clean the checkouts - dir = await external_fs_default().promises.opendir(coPath); - for await (const dirent of dir) { - const refs = repos.get(dirent.name); - if (!refs) { - await rm(dir.path, dirent); - continue; - } - if (!dirent.isDirectory()) { - continue; - } - const refsDir = await external_fs_default().promises.opendir(external_path_default().join(dir.path, dirent.name)); - for await (const dirent of refsDir) { - if (!refs.has(dirent.name)) { - await rm(refsDir.path, dirent); - } - } - } -} -async function macOsWorkaround() { - try { - // Workaround for https://github.com/actions/cache/issues/403 - // Also see https://github.com/rust-lang/cargo/issues/8603 - await exec.exec("sudo", ["/usr/sbin/purge"], { silent: true }); - } - catch { } -} -======= @@ -61972,11 +61619,10 @@ process.on("uncaughtException", (e) => { } }); const cwd = core.getInput("working-directory"); -// Read each line of target-dir as a unique target directory +// Read each line of workspace-paths as a unique path // TODO: this could be read from .cargo config file directly -const targetDirInput = core.getInput("target-dir") || "./target"; -const targetDirs = targetDirInput.trim().split("\n"); -core.info("Using target dirs: " + JSON.stringify(targetDirs)); +const workspacePathsInput = core.getInput("workspace-paths") || "./"; +const workspacePaths = workspacePathsInput.trim().split("\n"); if (cwd) { process.chdir(cwd); } @@ -61990,7 +61636,7 @@ const paths = { index: external_path_default().join(cargoHome, "registry/index"), cache: external_path_default().join(cargoHome, "registry/cache"), git: external_path_default().join(cargoHome, "git"), - targets: targetDirs, + workspaces: workspacePaths, }; const RefKey = "GITHUB_REF"; function isValidEvent() { @@ -62029,7 +61675,7 @@ async function getCacheConfig() { ], key: `${key}-${lockHash}`, restoreKeys: [key], - targets: paths.targets, + workspaces: paths.workspaces, }; } async function getCargoBins() { @@ -62078,7 +61724,7 @@ async function getLockfileHash() { followSymbolicLinks: false, }); const files = await globber.glob(); - core.info("Lockfile Hash includes: " + JSON.stringify(files)); + core.debug("Lockfile Hash includes: " + JSON.stringify(files)); files.sort((a, b) => a.localeCompare(b)); const hasher = external_crypto_default().createHash("sha1"); for (const file of files) { @@ -62100,19 +61746,29 @@ async function getPackages() { } async function cleanTarget(targetDir, packages) { await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json")); - await io.rmRF(external_path_default().join(targetDir, "./debug/examples")); - await io.rmRF(external_path_default().join(targetDir, "./debug/incremental")); + await cleanProfileTarget(targetDir, packages, "debug"); + await cleanProfileTarget(targetDir, packages, "release"); +} +async function cleanProfileTarget(targetDir, packages, profile) { + try { + await external_fs_default().promises.access(external_path_default().join(targetDir, profile)); + } + catch { + return; + } + await io.rmRF(external_path_default().join(targetDir, profile, "./examples")); + await io.rmRF(external_path_default().join(targetDir, profile, "./incremental")); let dir; - // remove all *files* from debug - dir = await external_fs_default().promises.opendir(external_path_default().join(targetDir, "./debug")); + // remove all *files* from the profile directory + dir = await external_fs_default().promises.opendir(external_path_default().join(targetDir, profile)); for await (const dirent of dir) { if (dirent.isFile()) { await rm(dir.path, dirent); } } const keepPkg = new Set(packages.map((p) => p.name)); - await rmExcept(external_path_default().join(targetDir, "./debug/build"), keepPkg); - await rmExcept(external_path_default().join(targetDir, "./debug/.fingerprint"), keepPkg); + await rmExcept(external_path_default().join(targetDir, profile, "./build"), keepPkg); + await rmExcept(external_path_default().join(targetDir, profile, "./.fingerprint"), keepPkg); const keepDeps = new Set(packages.flatMap((p) => { const names = []; for (const n of [p.name, ...p.targets]) { @@ -62121,7 +61777,7 @@ async function cleanTarget(targetDir, packages) { } return names; })); - await rmExcept(external_path_default().join(targetDir, "./debug/deps"), keepDeps); + await rmExcept(external_path_default().join(targetDir, profile, "./deps"), keepDeps); } const oneWeek = 7 * 24 * 3600 * 1000; async function rmExcept(dirName, keepPrefix) { @@ -62164,9 +61820,12 @@ async function rm(parent, dirent) { async function run() { + if (!cache.isFeatureAvailable()) { + return; + } try { - const { paths, targets, key } = await getCacheConfig(); - const savePaths = paths.concat(targets); + const { paths, workspaces, key } = await getCacheConfig(); + const savePaths = paths.concat(workspaces); if (core.getState(stateKey) === key) { core.info(`Cache up-to-date.`); return; @@ -62175,31 +61834,42 @@ async function run() { await macOsWorkaround(); const registryName = await getRegistryName(); const packages = await getPackages(); - try { - await cleanRegistry(registryName, packages); + if (registryName) { + try { + await cleanRegistry(registryName, packages); + } + catch (e) { + core.info(`[warning] ${e.stack}`); + } } - catch { } try { await cleanBin(); } - catch { } + catch (e) { + core.info(`[warning] ${e.stack}`); + } try { await cleanGit(packages); } - catch { } - try { - for (const target of targets) { + catch (e) { + core.info(`[warning] ${e.stack}`); + } + for (const workspace of workspaces) { + const target = external_path_default().join(workspace, "target"); + try { await cleanTarget(target, packages); } + catch (e) { + core.info(`[warning] ${e.stack}`); + } } - catch { } core.info(`Saving paths:\n ${savePaths.join("\n ")}`); core.info(`In directory:\n ${process.cwd()}`); core.info(`Using key:\n ${key}`); await cache.saveCache(savePaths, key); } catch (e) { - core.info(`[warning] ${e.message}`); + core.info(`[warning] ${e.stack}`); } } run(); @@ -62210,6 +61880,9 @@ async function getRegistryName() { core.warning(`got multiple registries: "${files.join('", "')}"`); } const first = files.shift(); + if (!first) { + return null; + } return external_path_default().basename(external_path_default().dirname(first)); } async function cleanBin() { @@ -62289,7 +61962,6 @@ async function macOsWorkaround() { } catch { } } ->>>>>>> 16da4ac (Cache multiple target directories from 'target-dir') })(); diff --git a/package-lock.json b/package-lock.json index 3a25f14..ef92f5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,623 +1,8 @@ { "name": "rust-cache", "version": "1.4.0", - "lockfileVersion": 2, + "lockfileVersion": 1, "requires": true, - "packages": { - "": { - "version": "1.4.0", - "license": "LGPL-3.0", - "dependencies": { - "@actions/cache": "^3.0.0", - "@actions/core": "^1.6.0", - "@actions/exec": "^1.1.1", - "@actions/glob": "^0.3.0", - "@actions/io": "^1.1.2" - }, - "devDependencies": { - "@vercel/ncc": "^0.34.0", - "typescript": "4.7.4" - }, - "funding": { - "url": "https://github.com/sponsors/Swatinem" - } - }, - "node_modules/@actions/cache": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@actions/cache/-/cache-3.0.0.tgz", - "integrity": "sha512-GL9CT1Fnu+pqs8TTB621q8Xa8Cilw2n9MwvbgMedetH7L1q2n6jY61gzbwGbKgtVbp3gVJ12aNMi4osSGXx3KQ==", - "dependencies": { - "@actions/core": "^1.2.6", - "@actions/exec": "^1.0.1", - "@actions/glob": "^0.1.0", - "@actions/http-client": "^2.0.1", - "@actions/io": "^1.0.1", - "@azure/ms-rest-js": "^2.6.0", - "@azure/storage-blob": "^12.8.0", - "semver": "^6.1.0", - "uuid": "^3.3.3" - } - }, - "node_modules/@actions/cache/node_modules/@actions/glob": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.1.2.tgz", - "integrity": "sha512-SclLR7Ia5sEqjkJTPs7Sd86maMDw43p769YxBOxvPvEWuPEhpAnBsQfENOpXjFYMmhCqd127bmf+YdvJqVqR4A==", - "dependencies": { - "@actions/core": "^1.2.6", - "minimatch": "^3.0.4" - } - }, - "node_modules/@actions/core": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.0.tgz", - "integrity": "sha512-5pbM693Ih59ZdUhgk+fts+bUWTnIdHV3kwOSr+QIoFHMLg7Gzhwm0cifDY/AG68ekEJAkHnQVpcy4f6GjmzBCA==", - "dependencies": { - "@actions/http-client": "^2.0.1" - } - }, - "node_modules/@actions/exec": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz", - "integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==", - "dependencies": { - "@actions/io": "^1.0.1" - } - }, - "node_modules/@actions/glob": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.3.0.tgz", - "integrity": "sha512-tJP1ZhF87fd6LBnaXWlahkyvdgvsLl7WnreW1EZaC8JWjpMXmzqWzQVe/IEYslrkT9ymibVrKyJN4UMD7uQM2w==", - "dependencies": { - "@actions/core": "^1.2.6", - "minimatch": "^3.0.4" - } - }, - "node_modules/@actions/http-client": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz", - "integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==", - "dependencies": { - "tunnel": "^0.0.6" - } - }, - "node_modules/@actions/io": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.2.tgz", - "integrity": "sha512-d+RwPlMp+2qmBfeLYPLXuSRykDIFEwdTA0MMxzS9kh4kvP1ftrc/9fzy6pX6qAjthdXruHQ6/6kjT/DNo5ALuw==" - }, - "node_modules/@azure/abort-controller": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.1.0.tgz", - "integrity": "sha512-TrRLIoSQVzfAJX9H1JeFjzAoDGcoK1IYX1UImfceTZpsyYfWr09Ss1aHW1y5TrrR3iq6RZLBwJ3E24uwPhwahw==", - "dependencies": { - "tslib": "^2.2.0" - }, - "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/@azure/abort-controller/node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" - }, - "node_modules/@azure/core-auth": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@azure/core-auth/-/core-auth-1.3.2.tgz", - "integrity": "sha512-7CU6DmCHIZp5ZPiZ9r3J17lTKMmYsm/zGvNkjArQwPkrLlZ1TZ+EUYfGgh2X31OLMVAQCTJZW4cXHJi02EbJnA==", - "dependencies": { - "@azure/abort-controller": "^1.0.0", - "tslib": "^2.2.0" - }, - "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/@azure/core-auth/node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" - }, - "node_modules/@azure/core-http": { - "version": "2.2.5", - "resolved": "https://registry.npmjs.org/@azure/core-http/-/core-http-2.2.5.tgz", - "integrity": "sha512-kctMqSQ6zfnlFpuYzfUKadeTyOQYbIQ+3Rj7dzVC3Dk1dOnHroTwR9hLYKX8/n85iJpkyaksaXpuh5L7GJRYuQ==", - "dependencies": { - "@azure/abort-controller": "^1.0.0", - "@azure/core-auth": "^1.3.0", - "@azure/core-tracing": "1.0.0-preview.13", - "@azure/logger": "^1.0.0", - "@types/node-fetch": "^2.5.0", - "@types/tunnel": "^0.0.3", - "form-data": "^4.0.0", - "node-fetch": "^2.6.7", - "process": "^0.11.10", - "tough-cookie": "^4.0.0", - "tslib": "^2.2.0", - "tunnel": "^0.0.6", - "uuid": "^8.3.0", - "xml2js": "^0.4.19" - }, - "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/@azure/core-http/node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/@azure/core-http/node_modules/tough-cookie": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz", - "integrity": "sha512-tHdtEpQCMrc1YLrMaqXXcj6AxhYi/xgit6mZu1+EDWUn+qhUf8wMQoFIy9NXuq23zAwtcB0t/MjACGR18pcRbg==", - "dependencies": { - "psl": "^1.1.33", - "punycode": "^2.1.1", - "universalify": "^0.1.2" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/@azure/core-http/node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" - }, - "node_modules/@azure/core-http/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "bin": { - "uuid": "dist/bin/uuid" - } - }, - "node_modules/@azure/core-lro": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/@azure/core-lro/-/core-lro-2.2.4.tgz", - "integrity": "sha512-e1I2v2CZM0mQo8+RSix0x091Av493e4bnT22ds2fcQGslTHzM2oTbswkB65nP4iEpCxBrFxOSDPKExmTmjCVtQ==", - "dependencies": { - "@azure/abort-controller": "^1.0.0", - "@azure/core-tracing": "1.0.0-preview.13", - "@azure/logger": "^1.0.0", - "tslib": "^2.2.0" - }, - "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/@azure/core-lro/node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" - }, - "node_modules/@azure/core-paging": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@azure/core-paging/-/core-paging-1.3.0.tgz", - "integrity": "sha512-H6Tg9eBm0brHqLy0OSAGzxIh1t4UL8eZVrSUMJ60Ra9cwq2pOskFqVpz2pYoHDsBY1jZ4V/P8LRGb5D5pmC6rg==", - "dependencies": { - "tslib": "^2.2.0" - }, - "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/@azure/core-paging/node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" - }, - "node_modules/@azure/core-tracing": { - "version": "1.0.0-preview.13", - "resolved": "https://registry.npmjs.org/@azure/core-tracing/-/core-tracing-1.0.0-preview.13.tgz", - "integrity": "sha512-KxDlhXyMlh2Jhj2ykX6vNEU0Vou4nHr025KoSEiz7cS3BNiHNaZcdECk/DmLkEB0as5T7b/TpRcehJ5yV6NeXQ==", - "dependencies": { - "@opentelemetry/api": "^1.0.1", - "tslib": "^2.2.0" - }, - "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/@azure/core-tracing/node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" - }, - "node_modules/@azure/logger": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@azure/logger/-/logger-1.0.3.tgz", - "integrity": "sha512-aK4s3Xxjrx3daZr3VylxejK3vG5ExXck5WOHDJ8in/k9AqlfIyFMMT1uG7u8mNjX+QRILTIn0/Xgschfh/dQ9g==", - "dependencies": { - "tslib": "^2.2.0" - }, - "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/@azure/logger/node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" - }, - "node_modules/@azure/ms-rest-js": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/@azure/ms-rest-js/-/ms-rest-js-2.6.1.tgz", - "integrity": "sha512-LLi4jRe/qy5IM8U2CkoDgSZp2OH+MgDe2wePmhz8uY84Svc53EhHaamVyoU6BjjHBxvCRh1vcD1urJDccrxqIw==", - "dependencies": { - "@azure/core-auth": "^1.1.4", - "abort-controller": "^3.0.0", - "form-data": "^2.5.0", - "node-fetch": "^2.6.7", - "tough-cookie": "^3.0.1", - "tslib": "^1.10.0", - "tunnel": "0.0.6", - "uuid": "^8.3.2", - "xml2js": "^0.4.19" - } - }, - "node_modules/@azure/ms-rest-js/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "bin": { - "uuid": "dist/bin/uuid" - } - }, - "node_modules/@azure/storage-blob": { - "version": "12.10.0", - "resolved": "https://registry.npmjs.org/@azure/storage-blob/-/storage-blob-12.10.0.tgz", - "integrity": "sha512-FBEPKGnvtQJS8V8Tg1P9obgmVD9AodrIfwtwhBpsjenClhFyugMp3HPJY0tF7rInUB/CivKBCbnQKrUnKxqxzw==", - "dependencies": { - "@azure/abort-controller": "^1.0.0", - "@azure/core-http": "^2.0.0", - "@azure/core-lro": "^2.2.0", - "@azure/core-paging": "^1.1.1", - "@azure/core-tracing": "1.0.0-preview.13", - "@azure/logger": "^1.0.0", - "events": "^3.0.0", - "tslib": "^2.2.0" - }, - "engines": { - "node": ">=12.0.0" - } - }, - "node_modules/@azure/storage-blob/node_modules/tslib": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", - "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" - }, - "node_modules/@opentelemetry/api": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.1.0.tgz", - "integrity": "sha512-hf+3bwuBwtXsugA2ULBc95qxrOqP2pOekLz34BJhcAKawt94vfeNyUKpYc0lZQ/3sCP6LqRa7UAdHA7i5UODzQ==", - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/@types/node": { - "version": "18.0.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.0.tgz", - "integrity": "sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA==" - }, - "node_modules/@types/node-fetch": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.2.tgz", - "integrity": "sha512-DHqhlq5jeESLy19TYhLakJ07kNumXWjcDdxXsLUMJZ6ue8VZJj4kLPQVE/2mdHh3xZziNF1xppu5lwmS53HR+A==", - "dependencies": { - "@types/node": "*", - "form-data": "^3.0.0" - } - }, - "node_modules/@types/node-fetch/node_modules/form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/@types/tunnel": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/@types/tunnel/-/tunnel-0.0.3.tgz", - "integrity": "sha512-sOUTGn6h1SfQ+gbgqC364jLFBw2lnFqkgF3q0WovEHRLMrVD1sd5aufqi/aJObLekJO+Aq5z646U4Oxy6shXMA==", - "dependencies": { - "@types/node": "*" - } - }, - "node_modules/@vercel/ncc": { - "version": "0.34.0", - "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.34.0.tgz", - "integrity": "sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A==", - "dev": true, - "bin": { - "ncc": "dist/ncc/cli.js" - } - }, - "node_modules/abort-controller": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", - "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", - "dependencies": { - "event-target-shim": "^5.0.0" - }, - "engines": { - "node": ">=6.5" - } - }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" - }, - "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" - }, - "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" - }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/event-target-shim": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", - "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", - "engines": { - "node": ">=6" - } - }, - "node_modules/events": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", - "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", - "engines": { - "node": ">=0.8.x" - } - }, - "node_modules/form-data": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", - "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 0.12" - } - }, - "node_modules/ip-regex": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz", - "integrity": "sha512-58yWmlHpp7VYfcdTwMTvwMmqx/Elfxjd9RXTDyMsbL7lLWmhMylLEqiYVLKuLzOZqVgiWXD9MfR62Vv89VRxkw==", - "engines": { - "node": ">=4" - } - }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, - "node_modules/process": { - "version": "0.11.10", - "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", - "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", - "engines": { - "node": ">= 0.6.0" - } - }, - "node_modules/psl": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", - "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==" - }, - "node_modules/punycode": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", - "engines": { - "node": ">=6" - } - }, - "node_modules/sax": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" - }, - "node_modules/semver": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", - "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", - "bin": { - "semver": "bin/semver.js" - } - }, - "node_modules/tough-cookie": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-3.0.1.tgz", - "integrity": "sha512-yQyJ0u4pZsv9D4clxO69OEjLWYw+jbgspjTue4lTQZLfV0c5l1VmK2y1JK8E9ahdpltPOaAThPcp5nKPUgSnsg==", - "dependencies": { - "ip-regex": "^2.1.0", - "psl": "^1.1.28", - "punycode": "^2.1.1" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" - }, - "node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" - }, - "node_modules/tunnel": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", - "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", - "engines": { - "node": ">=0.6.11 <=0.7.0 || >=0.7.3" - } - }, - "node_modules/typescript": { - "version": "4.7.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", - "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", - "dev": true, - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=4.2.0" - } - }, - "node_modules/universalify": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "engines": { - "node": ">= 4.0.0" - } - }, - "node_modules/uuid": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", - "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", - "deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.", - "bin": { - "uuid": "bin/uuid" - } - }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" - }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, - "node_modules/xml2js": { - "version": "0.4.23", - "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", - "integrity": "sha512-ySPiMjM0+pLDftHgXY4By0uswI3SPKLDw/i3UXbnO8M/p28zqexCUoPmQFrYD+/1BzhGJSs2i1ERWKJAtiLrug==", - "dependencies": { - "sax": ">=0.6.0", - "xmlbuilder": "~11.0.0" - }, - "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/xmlbuilder": { - "version": "11.0.1", - "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", - "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", - "engines": { - "node": ">=4.0" - } - } - }, "dependencies": { "@actions/cache": { "version": "3.0.0", diff --git a/src/common.ts b/src/common.ts index 7be3421..b8f6187 100644 --- a/src/common.ts +++ b/src/common.ts @@ -16,10 +16,10 @@ process.on("uncaughtException", (e) => { const cwd = core.getInput("working-directory"); -// Read each line of target-dir as a unique target directory +// Read each line of workspace-paths as a unique path // TODO: this could be read from .cargo config file directly -const targetDirInput = core.getInput("target-dir") || "./target"; -const targetDirs = targetDirInput.trim().split("\n"); +const workspacePathsInput = core.getInput("workspace-paths") || "./"; +const workspacePaths = workspacePathsInput.trim().split("\n"); if (cwd) { process.chdir(cwd); @@ -36,7 +36,7 @@ export const paths = { index: path.join(cargoHome, "registry/index"), cache: path.join(cargoHome, "registry/cache"), git: path.join(cargoHome, "git"), - targets: targetDirs, + workspaces: workspacePaths, }; interface CacheConfig { @@ -44,8 +44,8 @@ interface CacheConfig { paths: Array; key: string; restoreKeys: Array; - // A list of one or more target directories to cache - targets: Array; + // A list of one or more workspace directories + workspaces: Array; } const RefKey = "GITHUB_REF"; @@ -91,7 +91,7 @@ export async function getCacheConfig(): Promise { ], key: `${key}-${lockHash}`, restoreKeys: [key], - targets: paths.targets, + workspaces: paths.workspaces, }; } @@ -201,11 +201,11 @@ export async function getPackages(): Promise { export async function cleanTarget(targetDir: string, packages: Packages) { await fs.promises.unlink(path.join(targetDir, "./.rustc_info.json")); - await cleanProfileTarget(packages, "debug"); - await cleanProfileTarget(packages, "release"); + await cleanProfileTarget(targetDir, packages, "debug"); + await cleanProfileTarget(targetDir, packages, "release"); } -async function cleanProfileTarget(packages: Packages, profile: string) { +async function cleanProfileTarget(targetDir: string, packages: Packages, profile: string) { try { await fs.promises.access(path.join(targetDir, profile)); } catch { @@ -269,5 +269,5 @@ export async function rm(parent: string, dirent: fs.Dirent) { } else if (dirent.isDirectory()) { await io.rmRF(fileName); } - } catch {} + } catch { } } diff --git a/src/restore.ts b/src/restore.ts index 2e46aa7..b769791 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -1,5 +1,6 @@ import * as cache from "@actions/cache"; import * as core from "@actions/core"; +import path from "path"; import { cleanTarget, getCacheConfig, getCargoBins, getPackages, stateBins, stateKey } from "./common"; async function run() { @@ -16,8 +17,8 @@ async function run() { core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure); core.exportVariable("CARGO_INCREMENTAL", 0); - const { paths, key, restoreKeys, targets } = await getCacheConfig(); - const restorePaths = paths.concat(targets); + const { paths, key, restoreKeys, workspaces } = await getCacheConfig(); + const restorePaths = paths.concat(workspaces); const bins = await getCargoBins(); core.saveState(stateBins, JSON.stringify([...bins])); @@ -34,7 +35,8 @@ async function run() { // pre-clean the target directory on cache mismatch const packages = await getPackages(); - for (const target of targets) { + for (const workspace of workspaces) { + const target = path.join(workspace, "target"); await cleanTarget(target, packages); } } diff --git a/src/save.ts b/src/save.ts index 2ea05d6..27bdbe3 100644 --- a/src/save.ts +++ b/src/save.ts @@ -23,8 +23,8 @@ async function run() { } try { - const { paths, targets, key } = await getCacheConfig(); - const savePaths = paths.concat(targets); + const { paths, workspaces, key } = await getCacheConfig(); + const savePaths = paths.concat(workspaces); if (core.getState(stateKey) === key) { core.info(`Cache up-to-date.`); @@ -57,7 +57,8 @@ async function run() { core.info(`[warning] ${(e as any).stack}`); } - for (const target of targets) { + for (const workspace of workspaces) { + const target = path.join(workspace, "target"); try { await cleanTarget(target, packages); }