3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-07-02 04:58:49 +00:00

Reset dist files

This commit is contained in:
Tom Parker-Shemilt 2021-06-28 22:12:44 +01:00
parent a5df05bb52
commit ee6bad3219
2 changed files with 546 additions and 557 deletions

460
dist/restore/index.js vendored
View file

@ -59794,242 +59794,234 @@ var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_);
var external_path_ = __nccwpck_require__(5622); var external_path_ = __nccwpck_require__(5622);
var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_); var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_);
;// CONCATENATED MODULE: ./src/common.ts ;// CONCATENATED MODULE: ./src/common.ts
process.on("uncaughtException", (e) => { process.on("uncaughtException", (e) => {
core.info(`[warning] ${e.message}`); 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";
const cwd = core.getInput("working-directory"); if (cwd) {
// TODO: this could be read from .cargo config file directly process.chdir(cwd);
const targetDir = core.getInput("target-dir") || "./target"; }
if (cwd) { const stateBins = "RUST_CACHE_BINS";
process.chdir(cwd); const stateKey = "RUST_CACHE_KEY";
} const stateHash = "RUST_CACHE_HASH";
const stateBins = "RUST_CACHE_BINS"; const home = external_os_default().homedir();
const stateKey = "RUST_CACHE_KEY"; const cargoHome = process.env.CARGO_HOME || external_path_default().join(home, ".cargo");
const stateHash = "RUST_CACHE_HASH"; const paths = {
const home = external_os_default().homedir(); cargoHome,
const cargoHome = process.env.CARGO_HOME || external_path_default().join(home, ".cargo"); index: external_path_default().join(cargoHome, "registry/index"),
const paths = { cache: external_path_default().join(cargoHome, "registry/cache"),
cargoHome, git: external_path_default().join(cargoHome, "git"),
index: external_path_default().join(cargoHome, "registry/index"), target: targetDir,
cache: external_path_default().join(cargoHome, "registry/cache"), };
git: external_path_default().join(cargoHome, "git"), const RefKey = "GITHUB_REF";
target: targetDir, function isValidEvent() {
}; return RefKey in process.env && Boolean(process.env[RefKey]);
const RefKey = "GITHUB_REF"; }
function isValidEvent() { async function getCacheConfig() {
return RefKey in process.env && Boolean(process.env[RefKey]); let lockHash = core.getState(stateHash);
} if (!lockHash) {
async function getCacheConfig() { lockHash = await getLockfileHash();
let lockHash = core.getState(stateHash); core.saveState(stateHash, lockHash);
if (!lockHash) { }
lockHash = await getLockfileHash(); let key = `v0-rust-`;
core.saveState(stateHash, lockHash); const sharedKey = core.getInput("sharedKey");
} if (sharedKey) {
let key = `v0-rust-`; key += `${sharedKey}-`;
const sharedKey = core.getInput("sharedKey"); }
if (sharedKey) { else {
key += `${sharedKey}-`; const inputKey = core.getInput("key");
} if (inputKey) {
else { key += `${inputKey}-`;
const inputKey = core.getInput("key"); }
if (inputKey) { const job = process.env.GITHUB_JOB;
key += `${inputKey}-`; if (job) {
} key += `${job}-`;
const job = process.env.GITHUB_JOB; }
if (job) { }
key += `${job}-`; key += await getRustKey();
} return {
} paths: [
key += await getRustKey(); external_path_default().join(cargoHome, "bin"),
return { external_path_default().join(cargoHome, ".crates2.json"),
paths: [ external_path_default().join(cargoHome, ".crates.toml"),
external_path_default().join(cargoHome, "bin"), paths.git,
external_path_default().join(cargoHome, ".crates2.json"), paths.cache,
external_path_default().join(cargoHome, ".crates.toml"), paths.index,
paths.git, paths.target,
paths.cache, ],
paths.index, key: `${key}-${lockHash}`,
paths.target, restoreKeys: [key],
], };
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"));
async function getCargoBins() { const bins = new Set();
try { for (const pkg of Object.values(installs)) {
const { installs } = JSON.parse(await external_fs_default().promises.readFile(external_path_default().join(paths.cargoHome, ".crates2.json"), "utf8")); for (const bin of pkg.bins) {
const bins = new Set(); bins.add(bin);
for (const pkg of Object.values(installs)) { }
for (const bin of pkg.bins) { }
bins.add(bin); return bins;
} }
} catch {
return bins; return new Set();
} }
catch { }
return new Set(); async function getRustKey() {
} const rustc = await getRustVersion();
} return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`;
async function getRustKey() { }
const rustc = await getRustVersion(); async function getRustVersion() {
return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`; const stdout = await getCmdOutput("rustc", ["-vV"]);
} let splits = stdout
async function getRustVersion() { .split(/[\n\r]+/)
const stdout = await getCmdOutput("rustc", ["-vV"]); .filter(Boolean)
let splits = stdout .map((s) => s.split(":").map((s) => s.trim()))
.split(/[\n\r]+/) .filter((s) => s.length === 2);
.filter(Boolean) return Object.fromEntries(splits);
.map((s) => s.split(":").map((s) => s.trim())) }
.filter((s) => s.length === 2); async function getCmdOutput(cmd, args = [], options = {}) {
return Object.fromEntries(splits); let stdout = "";
} await exec.exec(cmd, args, {
async function getCmdOutput(cmd, args = [], options = {}) { silent: true,
let stdout = ""; listeners: {
await exec.exec(cmd, args, { stdout(data) {
silent: true, stdout += data.toString();
listeners: { },
stdout(data) { },
stdout += data.toString(); ...options,
}, });
}, return stdout;
...options, }
}); async function getLockfileHash() {
return stdout; const globber = await glob.create("**/Cargo.toml\n**/Cargo.lock\nrust-toolchain\nrust-toolchain.toml", {
} followSymbolicLinks: false,
async function getLockfileHash() { });
const globber = await glob.create("**/Cargo.toml\n**/Cargo.lock\nrust-toolchain\nrust-toolchain.toml", { const files = await globber.glob();
followSymbolicLinks: false, files.sort((a, b) => a.localeCompare(b));
}); const hasher = external_crypto_default().createHash("sha1");
const files = await globber.glob(); for (const file of files) {
files.sort((a, b) => a.localeCompare(b)); for await (const chunk of external_fs_default().createReadStream(file)) {
const hasher = external_crypto_default().createHash("sha1"); hasher.update(chunk);
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() {
return hasher.digest("hex").slice(0, 20); const cwd = process.cwd();
} const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"]));
async function getPackages() { return meta.packages
const cwd = process.cwd(); .filter((p) => !p.manifest_path.startsWith(cwd))
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"])); .map((p) => {
return meta.packages const targets = p.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name);
.filter((p) => !p.manifest_path.startsWith(cwd)) return { name: p.name, version: p.version, targets, path: external_path_default().dirname(p.manifest_path) };
.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 io.rmRF(external_path_default().join(targetDir, "./debug/examples"));
async function cleanTarget(packages) { await io.rmRF(external_path_default().join(targetDir, "./debug/incremental"));
await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json")); let dir;
await io.rmRF(external_path_default().join(targetDir, "./debug/examples")); // remove all *files* from debug
await io.rmRF(external_path_default().join(targetDir, "./debug/incremental")); dir = await external_fs_default().promises.opendir(external_path_default().join(targetDir, "./debug"));
let dir; for await (const dirent of dir) {
// remove all *files* from debug if (dirent.isFile()) {
dir = await external_fs_default().promises.opendir(external_path_default().join(targetDir, "./debug")); await rm(dir.path, dirent);
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);
const keepPkg = new Set(packages.map((p) => p.name)); const keepDeps = new Set(packages.flatMap((p) => {
await rmExcept(external_path_default().join(targetDir, "./debug/build"), keepPkg); const names = [];
await rmExcept(external_path_default().join(targetDir, "./debug/.fingerprint"), keepPkg); for (const n of [p.name, ...p.targets]) {
const keepDeps = new Set(packages.flatMap((p) => { const name = n.replace(/-/g, "_");
const names = []; names.push(name, `lib${name}`);
for (const n of [p.name, ...p.targets]) { }
const name = n.replace(/-/g, "_"); return names;
names.push(name, `lib${name}`); }));
} await rmExcept(external_path_default().join(targetDir, "./debug/deps"), keepDeps);
return names; }
})); const oneWeek = 7 * 24 * 3600 * 1000;
await rmExcept(external_path_default().join(targetDir, "./debug/deps"), keepDeps); async function rmExcept(dirName, keepPrefix) {
} const dir = await external_fs_default().promises.opendir(dirName);
const oneWeek = 7 * 24 * 3600 * 1000; for await (const dirent of dir) {
async function rmExcept(dirName, keepPrefix) { let name = dirent.name;
const dir = await external_fs_default().promises.opendir(dirName); const idx = name.lastIndexOf("-");
for await (const dirent of dir) { if (idx !== -1) {
let name = dirent.name; name = name.slice(0, idx);
const idx = name.lastIndexOf("-"); }
if (idx !== -1) { const fileName = external_path_default().join(dir.path, dirent.name);
name = name.slice(0, idx); const { mtime } = await external_fs_default().promises.stat(fileName);
} // we dont really know
const fileName = external_path_default().join(dir.path, dirent.name); if (!keepPrefix.has(name) || Date.now() - mtime.getTime() > oneWeek) {
const { mtime } = await external_fs_default().promises.stat(fileName); await rm(dir.path, dirent);
// we dont 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);
async function rm(parent, dirent) { core.debug(`deleting "${fileName}"`);
try { if (dirent.isFile()) {
const fileName = external_path_default().join(parent, dirent.name); await external_fs_default().promises.unlink(fileName);
core.debug(`deleting "${fileName}"`); }
if (dirent.isFile()) { else if (dirent.isDirectory()) {
await external_fs_default().promises.unlink(fileName); await io.rmRF(fileName);
} }
else if (dirent.isDirectory()) { }
await io.rmRF(fileName); catch { }
} }
}
catch { }
}
;// CONCATENATED MODULE: ./src/restore.ts ;// CONCATENATED MODULE: ./src/restore.ts
async function run() { async function run() {
try { try {
var cacheOnFailure = core.getInput("cache-on-failure").toLowerCase(); core.exportVariable("CARGO_INCREMENTAL", 0);
if (cacheOnFailure !== "true") { const { paths, key, restoreKeys } = await getCacheConfig();
cacheOnFailure = "false"; const bins = await getCargoBins();
} core.saveState(stateBins, JSON.stringify([...bins]));
core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure); core.info(`Restoring paths:\n ${paths.join("\n ")}`);
core.exportVariable("CARGO_INCREMENTAL", 0); core.info(`In directory:\n ${process.cwd()}`);
const { paths, key, restoreKeys } = await getCacheConfig(); core.info(`Using keys:\n ${[key, ...restoreKeys].join("\n ")}`);
const bins = await getCargoBins(); const restoreKey = await cache.restoreCache(paths, key, restoreKeys);
core.saveState(stateBins, JSON.stringify([...bins])); if (restoreKey) {
core.info(`Restoring paths:\n ${paths.join("\n ")}`); core.info(`Restored from cache key "${restoreKey}".`);
core.info(`In directory:\n ${process.cwd()}`); core.saveState(stateKey, restoreKey);
core.info(`Using keys:\n ${[key, ...restoreKeys].join("\n ")}`); if (restoreKey !== key) {
const restoreKey = await cache.restoreCache(paths, key, restoreKeys); // pre-clean the target directory on cache mismatch
if (restoreKey) { const packages = await getPackages();
core.info(`Restored from cache key "${restoreKey}".`); await cleanTarget(packages);
core.saveState(stateKey, restoreKey); }
if (restoreKey !== key) { setCacheHitOutput(restoreKey === key);
// pre-clean the target directory on cache mismatch }
const packages = await getPackages(); else {
await cleanTarget(packages); core.info("No cache found.");
} setCacheHitOutput(false);
setCacheHitOutput(restoreKey === key); }
} }
else { catch (e) {
core.info("No cache found."); setCacheHitOutput(false);
setCacheHitOutput(false); core.info(`[warning] ${e.message}`);
} }
} }
catch (e) { function setCacheHitOutput(cacheHit) {
setCacheHitOutput(false); core.setOutput("cache-hit", cacheHit.toString());
core.info(`[warning] ${e.message}`); }
} run();
}
function setCacheHitOutput(cacheHit) {
core.setOutput("cache-hit", cacheHit.toString());
}
run();
})(); })();

643
dist/save/index.js vendored
View file

@ -59794,331 +59794,328 @@ var external_crypto_default = /*#__PURE__*/__nccwpck_require__.n(external_crypto
var external_os_ = __nccwpck_require__(2087); var external_os_ = __nccwpck_require__(2087);
var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_); var external_os_default = /*#__PURE__*/__nccwpck_require__.n(external_os_);
;// CONCATENATED MODULE: ./src/common.ts ;// CONCATENATED MODULE: ./src/common.ts
process.on("uncaughtException", (e) => { process.on("uncaughtException", (e) => {
core.info(`[warning] ${e.message}`); 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";
const cwd = core.getInput("working-directory"); if (cwd) {
// TODO: this could be read from .cargo config file directly process.chdir(cwd);
const targetDir = core.getInput("target-dir") || "./target"; }
if (cwd) { const stateBins = "RUST_CACHE_BINS";
process.chdir(cwd); const stateKey = "RUST_CACHE_KEY";
} const stateHash = "RUST_CACHE_HASH";
const stateBins = "RUST_CACHE_BINS"; const home = external_os_default().homedir();
const stateKey = "RUST_CACHE_KEY"; const cargoHome = process.env.CARGO_HOME || external_path_default().join(home, ".cargo");
const stateHash = "RUST_CACHE_HASH"; const paths = {
const home = external_os_default().homedir(); cargoHome,
const cargoHome = process.env.CARGO_HOME || external_path_default().join(home, ".cargo"); index: external_path_default().join(cargoHome, "registry/index"),
const paths = { cache: external_path_default().join(cargoHome, "registry/cache"),
cargoHome, git: external_path_default().join(cargoHome, "git"),
index: external_path_default().join(cargoHome, "registry/index"), target: targetDir,
cache: external_path_default().join(cargoHome, "registry/cache"), };
git: external_path_default().join(cargoHome, "git"), const RefKey = "GITHUB_REF";
target: targetDir, function isValidEvent() {
}; return RefKey in process.env && Boolean(process.env[RefKey]);
const RefKey = "GITHUB_REF"; }
function isValidEvent() { async function getCacheConfig() {
return RefKey in process.env && Boolean(process.env[RefKey]); let lockHash = core.getState(stateHash);
} if (!lockHash) {
async function getCacheConfig() { lockHash = await getLockfileHash();
let lockHash = core.getState(stateHash); core.saveState(stateHash, lockHash);
if (!lockHash) { }
lockHash = await getLockfileHash(); let key = `v0-rust-`;
core.saveState(stateHash, lockHash); const sharedKey = core.getInput("sharedKey");
} if (sharedKey) {
let key = `v0-rust-`; key += `${sharedKey}-`;
const sharedKey = core.getInput("sharedKey"); }
if (sharedKey) { else {
key += `${sharedKey}-`; const inputKey = core.getInput("key");
} if (inputKey) {
else { key += `${inputKey}-`;
const inputKey = core.getInput("key"); }
if (inputKey) { const job = process.env.GITHUB_JOB;
key += `${inputKey}-`; if (job) {
} key += `${job}-`;
const job = process.env.GITHUB_JOB; }
if (job) { }
key += `${job}-`; key += await getRustKey();
} return {
} paths: [
key += await getRustKey(); external_path_default().join(cargoHome, "bin"),
return { external_path_default().join(cargoHome, ".crates2.json"),
paths: [ external_path_default().join(cargoHome, ".crates.toml"),
external_path_default().join(cargoHome, "bin"), paths.git,
external_path_default().join(cargoHome, ".crates2.json"), paths.cache,
external_path_default().join(cargoHome, ".crates.toml"), paths.index,
paths.git, paths.target,
paths.cache, ],
paths.index, key: `${key}-${lockHash}`,
paths.target, restoreKeys: [key],
], };
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"));
async function getCargoBins() { const bins = new Set();
try { for (const pkg of Object.values(installs)) {
const { installs } = JSON.parse(await external_fs_default().promises.readFile(external_path_default().join(paths.cargoHome, ".crates2.json"), "utf8")); for (const bin of pkg.bins) {
const bins = new Set(); bins.add(bin);
for (const pkg of Object.values(installs)) { }
for (const bin of pkg.bins) { }
bins.add(bin); return bins;
} }
} catch {
return bins; return new Set();
} }
catch { }
return new Set(); async function getRustKey() {
} const rustc = await getRustVersion();
} return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`;
async function getRustKey() { }
const rustc = await getRustVersion(); async function getRustVersion() {
return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`; const stdout = await getCmdOutput("rustc", ["-vV"]);
} let splits = stdout
async function getRustVersion() { .split(/[\n\r]+/)
const stdout = await getCmdOutput("rustc", ["-vV"]); .filter(Boolean)
let splits = stdout .map((s) => s.split(":").map((s) => s.trim()))
.split(/[\n\r]+/) .filter((s) => s.length === 2);
.filter(Boolean) return Object.fromEntries(splits);
.map((s) => s.split(":").map((s) => s.trim())) }
.filter((s) => s.length === 2); async function getCmdOutput(cmd, args = [], options = {}) {
return Object.fromEntries(splits); let stdout = "";
} await exec.exec(cmd, args, {
async function getCmdOutput(cmd, args = [], options = {}) { silent: true,
let stdout = ""; listeners: {
await exec.exec(cmd, args, { stdout(data) {
silent: true, stdout += data.toString();
listeners: { },
stdout(data) { },
stdout += data.toString(); ...options,
}, });
}, return stdout;
...options, }
}); async function getLockfileHash() {
return stdout; const globber = await glob.create("**/Cargo.toml\n**/Cargo.lock\nrust-toolchain\nrust-toolchain.toml", {
} followSymbolicLinks: false,
async function getLockfileHash() { });
const globber = await glob.create("**/Cargo.toml\n**/Cargo.lock\nrust-toolchain\nrust-toolchain.toml", { const files = await globber.glob();
followSymbolicLinks: false, files.sort((a, b) => a.localeCompare(b));
}); const hasher = external_crypto_default().createHash("sha1");
const files = await globber.glob(); for (const file of files) {
files.sort((a, b) => a.localeCompare(b)); for await (const chunk of external_fs_default().createReadStream(file)) {
const hasher = external_crypto_default().createHash("sha1"); hasher.update(chunk);
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() {
return hasher.digest("hex").slice(0, 20); const cwd = process.cwd();
} const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"]));
async function getPackages() { return meta.packages
const cwd = process.cwd(); .filter((p) => !p.manifest_path.startsWith(cwd))
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"])); .map((p) => {
return meta.packages const targets = p.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name);
.filter((p) => !p.manifest_path.startsWith(cwd)) return { name: p.name, version: p.version, targets, path: external_path_default().dirname(p.manifest_path) };
.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 io.rmRF(external_path_default().join(targetDir, "./debug/examples"));
async function cleanTarget(packages) { await io.rmRF(external_path_default().join(targetDir, "./debug/incremental"));
await external_fs_default().promises.unlink(external_path_default().join(targetDir, "./.rustc_info.json")); let dir;
await io.rmRF(external_path_default().join(targetDir, "./debug/examples")); // remove all *files* from debug
await io.rmRF(external_path_default().join(targetDir, "./debug/incremental")); dir = await external_fs_default().promises.opendir(external_path_default().join(targetDir, "./debug"));
let dir; for await (const dirent of dir) {
// remove all *files* from debug if (dirent.isFile()) {
dir = await external_fs_default().promises.opendir(external_path_default().join(targetDir, "./debug")); await rm(dir.path, dirent);
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);
const keepPkg = new Set(packages.map((p) => p.name)); const keepDeps = new Set(packages.flatMap((p) => {
await rmExcept(external_path_default().join(targetDir, "./debug/build"), keepPkg); const names = [];
await rmExcept(external_path_default().join(targetDir, "./debug/.fingerprint"), keepPkg); for (const n of [p.name, ...p.targets]) {
const keepDeps = new Set(packages.flatMap((p) => { const name = n.replace(/-/g, "_");
const names = []; names.push(name, `lib${name}`);
for (const n of [p.name, ...p.targets]) { }
const name = n.replace(/-/g, "_"); return names;
names.push(name, `lib${name}`); }));
} await rmExcept(external_path_default().join(targetDir, "./debug/deps"), keepDeps);
return names; }
})); const oneWeek = 7 * 24 * 3600 * 1000;
await rmExcept(external_path_default().join(targetDir, "./debug/deps"), keepDeps); async function rmExcept(dirName, keepPrefix) {
} const dir = await external_fs_default().promises.opendir(dirName);
const oneWeek = 7 * 24 * 3600 * 1000; for await (const dirent of dir) {
async function rmExcept(dirName, keepPrefix) { let name = dirent.name;
const dir = await external_fs_default().promises.opendir(dirName); const idx = name.lastIndexOf("-");
for await (const dirent of dir) { if (idx !== -1) {
let name = dirent.name; name = name.slice(0, idx);
const idx = name.lastIndexOf("-"); }
if (idx !== -1) { const fileName = external_path_default().join(dir.path, dirent.name);
name = name.slice(0, idx); const { mtime } = await external_fs_default().promises.stat(fileName);
} // we dont really know
const fileName = external_path_default().join(dir.path, dirent.name); if (!keepPrefix.has(name) || Date.now() - mtime.getTime() > oneWeek) {
const { mtime } = await external_fs_default().promises.stat(fileName); await rm(dir.path, dirent);
// we dont 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);
async function rm(parent, dirent) { core.debug(`deleting "${fileName}"`);
try { if (dirent.isFile()) {
const fileName = external_path_default().join(parent, dirent.name); await external_fs_default().promises.unlink(fileName);
core.debug(`deleting "${fileName}"`); }
if (dirent.isFile()) { else if (dirent.isDirectory()) {
await external_fs_default().promises.unlink(fileName); await io.rmRF(fileName);
} }
else if (dirent.isDirectory()) { }
await io.rmRF(fileName); catch { }
} }
}
catch { }
}
;// CONCATENATED MODULE: ./src/save.ts ;// CONCATENATED MODULE: ./src/save.ts
async function run() { async function run() {
try { try {
const { paths: savePaths, key } = await getCacheConfig(); const { paths: savePaths, key } = await getCacheConfig();
if (core.getState(stateKey) === key) { if (core.getState(stateKey) === key) {
core.info(`Cache up-to-date.`); core.info(`Cache up-to-date.`);
return; return;
} }
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands // TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
await macOsWorkaround(); await macOsWorkaround();
const registryName = await getRegistryName(); const registryName = await getRegistryName();
const packages = await getPackages(); const packages = await getPackages();
try { try {
await cleanRegistry(registryName, packages); await cleanRegistry(registryName, packages);
} }
catch { } catch { }
try { try {
await cleanBin(); await cleanBin();
} }
catch { } catch { }
try { try {
await cleanGit(packages); await cleanGit(packages);
} }
catch { } catch { }
try { try {
await cleanTarget(packages); await cleanTarget(packages);
} }
catch { } catch { }
core.info(`Saving paths:\n ${savePaths.join("\n ")}`); core.info(`Saving paths:\n ${savePaths.join("\n ")}`);
core.info(`In directory:\n ${process.cwd()}`); core.info(`In directory:\n ${process.cwd()}`);
core.info(`Using key:\n ${key}`); core.info(`Using key:\n ${key}`);
await cache.saveCache(savePaths, key); await cache.saveCache(savePaths, key);
} }
catch (e) { catch (e) {
core.info(`[warning] ${e.message}`); core.info(`[warning] ${e.message}`);
} }
} }
run(); run();
async function getRegistryName() { async function getRegistryName() {
const globber = await glob.create(`${paths.index}/**/.last-updated`, { followSymbolicLinks: false }); const globber = await glob.create(`${paths.index}/**/.last-updated`, { followSymbolicLinks: false });
const files = await globber.glob(); const files = await globber.glob();
if (files.length > 1) { if (files.length > 1) {
core.warning(`got multiple registries: "${files.join('", "')}"`); core.warning(`got multiple registries: "${files.join('", "')}"`);
} }
const first = files.shift(); const first = files.shift();
return external_path_default().basename(external_path_default().dirname(first)); return external_path_default().basename(external_path_default().dirname(first));
} }
async function cleanBin() { async function cleanBin() {
const bins = await getCargoBins(); const bins = await getCargoBins();
const oldBins = JSON.parse(core.getState(stateBins)); const oldBins = JSON.parse(core.getState(stateBins));
for (const bin of oldBins) { for (const bin of oldBins) {
bins.delete(bin); bins.delete(bin);
} }
const dir = await external_fs_default().promises.opendir(external_path_default().join(paths.cargoHome, "bin")); const dir = await external_fs_default().promises.opendir(external_path_default().join(paths.cargoHome, "bin"));
for await (const dirent of dir) { for await (const dirent of dir) {
if (dirent.isFile() && !bins.has(dirent.name)) { if (dirent.isFile() && !bins.has(dirent.name)) {
await rm(dir.path, dirent); await rm(dir.path, dirent);
} }
} }
} }
async function cleanRegistry(registryName, packages) { async function cleanRegistry(registryName, packages) {
await io.rmRF(external_path_default().join(paths.index, registryName, ".cache")); await io.rmRF(external_path_default().join(paths.index, registryName, ".cache"));
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`)); 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)); const dir = await external_fs_default().promises.opendir(external_path_default().join(paths.cache, registryName));
for await (const dirent of dir) { for await (const dirent of dir) {
if (dirent.isFile() && !pkgSet.has(dirent.name)) { if (dirent.isFile() && !pkgSet.has(dirent.name)) {
await rm(dir.path, dirent); await rm(dir.path, dirent);
} }
} }
} }
async function cleanGit(packages) { async function cleanGit(packages) {
const coPath = external_path_default().join(paths.git, "checkouts"); const coPath = external_path_default().join(paths.git, "checkouts");
const dbPath = external_path_default().join(paths.git, "db"); const dbPath = external_path_default().join(paths.git, "db");
const repos = new Map(); const repos = new Map();
for (const p of packages) { for (const p of packages) {
if (!p.path.startsWith(coPath)) { if (!p.path.startsWith(coPath)) {
continue; continue;
} }
const [repo, ref] = p.path.slice(coPath.length + 1).split((external_path_default()).sep); const [repo, ref] = p.path.slice(coPath.length + 1).split((external_path_default()).sep);
const refs = repos.get(repo); const refs = repos.get(repo);
if (refs) { if (refs) {
refs.add(ref); refs.add(ref);
} }
else { else {
repos.set(repo, new Set([ref])); repos.set(repo, new Set([ref]));
} }
} }
// we have to keep both the clone, and the checkout, removing either will // we have to keep both the clone, and the checkout, removing either will
// trigger a rebuild // trigger a rebuild
let dir; let dir;
// clean the db // clean the db
dir = await external_fs_default().promises.opendir(dbPath); dir = await external_fs_default().promises.opendir(dbPath);
for await (const dirent of dir) { for await (const dirent of dir) {
if (!repos.has(dirent.name)) { if (!repos.has(dirent.name)) {
await rm(dir.path, dirent); await rm(dir.path, dirent);
} }
} }
// clean the checkouts // clean the checkouts
dir = await external_fs_default().promises.opendir(coPath); dir = await external_fs_default().promises.opendir(coPath);
for await (const dirent of dir) { for await (const dirent of dir) {
const refs = repos.get(dirent.name); const refs = repos.get(dirent.name);
if (!refs) { if (!refs) {
await rm(dir.path, dirent); await rm(dir.path, dirent);
continue; continue;
} }
if (!dirent.isDirectory()) { if (!dirent.isDirectory()) {
continue; continue;
} }
const refsDir = await external_fs_default().promises.opendir(external_path_default().join(dir.path, dirent.name)); const refsDir = await external_fs_default().promises.opendir(external_path_default().join(dir.path, dirent.name));
for await (const dirent of refsDir) { for await (const dirent of refsDir) {
if (!refs.has(dirent.name)) { if (!refs.has(dirent.name)) {
await rm(refsDir.path, dirent); await rm(refsDir.path, dirent);
} }
} }
} }
} }
async function macOsWorkaround() { async function macOsWorkaround() {
try { try {
// Workaround for https://github.com/actions/cache/issues/403 // Workaround for https://github.com/actions/cache/issues/403
// Also see https://github.com/rust-lang/cargo/issues/8603 // Also see https://github.com/rust-lang/cargo/issues/8603
await exec.exec("sudo", ["/usr/sbin/purge"], { silent: true }); await exec.exec("sudo", ["/usr/sbin/purge"], { silent: true });
} }
catch { } catch { }
} }
})(); })();