3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2026-02-07 03:22:15 +00:00

feat: add option to cache all crates

Add cache-all-crates option which allows all crates to be cached instead
of just the dependency crates. This is useful when additional crates are
required for CI tooling.
This commit is contained in:
Steven Hartland 2023-05-11 10:43:25 +01:00
parent 127a0e9568
commit 028a3ac2df
6 changed files with 42 additions and 17 deletions

View file

@ -60226,7 +60226,7 @@ async function cleanBin() {
}
}
}
async function cleanRegistry(packages) {
async function cleanRegistry(packages, crates = true) {
// `.cargo/registry/src`
// we can remove this completely, as cargo will recreate this from `cache`
await rmRF(path.join(CARGO_HOME, "registry", "src"));
@ -60244,6 +60244,10 @@ async function cleanRegistry(packages) {
// TODO: else, clean `.cache` based on the `packages`
}
}
if (!crates) {
core.debug(`skipping crate cleanup`);
return;
}
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
// `.cargo/registry/cache`
const cacheDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "cache"));

21
dist/save/index.js vendored
View file

@ -60226,7 +60226,7 @@ async function cleanBin() {
}
}
}
async function cleanRegistry(packages) {
async function cleanRegistry(packages, crates = true) {
// `.cargo/registry/src`
// we can remove this completely, as cargo will recreate this from `cache`
await rmRF(external_path_default().join(CARGO_HOME, "registry", "src"));
@ -60244,6 +60244,10 @@ async function cleanRegistry(packages) {
// TODO: else, clean `.cache` based on the `packages`
}
}
if (!crates) {
core.debug(`skipping crate cleanup`);
return;
}
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
// `.cargo/registry/cache`
const cacheDir = await external_fs_default().promises.opendir(external_path_default().join(CARGO_HOME, "registry", "cache"));
@ -60409,35 +60413,36 @@ async function run() {
await cleanTargetDir(workspace.target, packages);
}
catch (e) {
core.info(`[warning] ${e.stack}`);
core.error(`${e.stack}`);
}
}
try {
core.info(`... Cleaning cargo registry ...`);
await cleanRegistry(allPackages);
const creates = core.getInput("cache-all-crates").toLowerCase() || "false";
core.info(`... Cleaning cargo registry cache-all-crates: ${creates} ...`);
await cleanRegistry(allPackages, creates === "true");
}
catch (e) {
core.info(`[warning] ${e.stack}`);
core.error(`${e.stack}`);
}
try {
core.info(`... Cleaning cargo/bin ...`);
await cleanBin();
}
catch (e) {
core.info(`[warning] ${e.stack}`);
core.error(`${e.stack}`);
}
try {
core.info(`... Cleaning cargo git cache ...`);
await cleanGit(allPackages);
}
catch (e) {
core.info(`[warning] ${e.stack}`);
core.error(`${e.stack}`);
}
core.info(`... Saving cache ...`);
await cache.saveCache(config.cachePaths, config.cacheKey);
}
catch (e) {
core.info(`[warning] ${e.stack}`);
core.error(`${e.stack}`);
}
}
run();