mirror of
https://github.com/Swatinem/rust-cache
synced 2025-04-27 05:35:53 +00:00
Add a selftest and support for .cargo/bin
This commit is contained in:
parent
83aad8d470
commit
b495963495
12 changed files with 1897 additions and 69 deletions
39
dist/save/index.js
vendored
39
dist/save/index.js
vendored
|
@ -55710,11 +55710,13 @@ const cwd = core.getInput("working-directory");
|
|||
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"),
|
||||
|
@ -55747,11 +55749,29 @@ async function getCacheConfig() {
|
|||
}
|
||||
key += await getRustKey();
|
||||
return {
|
||||
paths: [paths.index, paths.cache, paths.git, paths.target],
|
||||
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() {
|
||||
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;
|
||||
}
|
||||
async function getRustKey() {
|
||||
const rustc = await getRustVersion();
|
||||
return `${rustc.release}-${rustc.host}-${rustc["commit-hash"].slice(0, 12)}`;
|
||||
|
@ -55880,6 +55900,10 @@ async function run() {
|
|||
await cleanRegistry(registryName, packages);
|
||||
}
|
||||
catch { }
|
||||
try {
|
||||
await cleanBin();
|
||||
}
|
||||
catch { }
|
||||
try {
|
||||
await cleanGit(packages);
|
||||
}
|
||||
|
@ -55907,6 +55931,19 @@ async function getRegistryName() {
|
|||
const first = files.shift();
|
||||
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`));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue