mirror of
https://github.com/Swatinem/rust-cache
synced 2025-04-27 13:45:52 +00:00
avoid error when saving without git dependencies
This commit is contained in:
parent
5f6034beb8
commit
292ef23e77
5 changed files with 302 additions and 183 deletions
93
dist/restore/index.js
vendored
93
dist/restore/index.js
vendored
|
@ -54581,6 +54581,9 @@ var exec = __webpack_require__(1514);
|
|||
// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js
|
||||
var glob = __webpack_require__(8090);
|
||||
|
||||
// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js
|
||||
var io = __webpack_require__(7436);
|
||||
|
||||
// EXTERNAL MODULE: external "crypto"
|
||||
var external_crypto_ = __webpack_require__(6417);
|
||||
var external_crypto_default = /*#__PURE__*/__webpack_require__.n(external_crypto_);
|
||||
|
@ -54612,6 +54615,7 @@ var __asyncValues = (undefined && undefined.__asyncValues) || function (o) {
|
|||
|
||||
|
||||
|
||||
|
||||
const stateKey = "RUST_CACHE_KEY";
|
||||
const stateHash = "RUST_CACHE_HASH";
|
||||
const home = external_os_default().homedir();
|
||||
|
@ -54692,6 +54696,90 @@ async function getLockfileHash() {
|
|||
}
|
||||
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) {
|
||||
var e_2, _a;
|
||||
await external_fs_default().promises.unlink("./target/.rustc_info.json");
|
||||
await io.rmRF("./target/debug/examples");
|
||||
await io.rmRF("./target/debug/incremental");
|
||||
let dir;
|
||||
// remove all *files* from debug
|
||||
dir = await external_fs_default().promises.opendir("./target/debug");
|
||||
try {
|
||||
for (var dir_1 = __asyncValues(dir), dir_1_1; dir_1_1 = await dir_1.next(), !dir_1_1.done;) {
|
||||
const dirent = dir_1_1.value;
|
||||
if (dirent.isFile()) {
|
||||
await rm(dir.path, dirent);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (dir_1_1 && !dir_1_1.done && (_a = dir_1.return)) await _a.call(dir_1);
|
||||
}
|
||||
finally { if (e_2) throw e_2.error; }
|
||||
}
|
||||
const keepPkg = new Set(packages.map((p) => p.name));
|
||||
await rmExcept("./target/debug/build", keepPkg);
|
||||
await rmExcept("./target/debug/.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("./target/debug/deps", keepDeps);
|
||||
}
|
||||
const oneWeek = 7 * 24 * 3600 * 1000;
|
||||
async function rmExcept(dirName, keepPrefix) {
|
||||
var e_3, _a;
|
||||
const dir = await external_fs_default().promises.opendir(dirName);
|
||||
try {
|
||||
for (var dir_2 = __asyncValues(dir), dir_2_1; dir_2_1 = await dir_2.next(), !dir_2_1.done;) {
|
||||
const dirent = dir_2_1.value;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
||||
finally {
|
||||
try {
|
||||
if (dir_2_1 && !dir_2_1.done && (_a = dir_2.return)) await _a.call(dir_2);
|
||||
}
|
||||
finally { if (e_3) throw e_3.error; }
|
||||
}
|
||||
}
|
||||
async function rm(parent, dirent) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// CONCATENATED MODULE: ./src/restore.ts
|
||||
|
||||
|
@ -54716,6 +54804,11 @@ async function run() {
|
|||
else {
|
||||
core.info("No cache found.");
|
||||
}
|
||||
if (restoreKey !== key) {
|
||||
// pre-clean the target directory on cache mismatch
|
||||
const packages = await getPackages();
|
||||
await cleanTarget(packages);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
core.info(`[warning] ${e.message}`);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue