mirror of
https://github.com/Swatinem/rust-cache
synced 2025-04-29 06:35:53 +00:00
feat: add option to cache all crates (#137)
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:
parent
827c240e23
commit
def0926359
6 changed files with 42 additions and 17 deletions
|
@ -85,7 +85,7 @@ export async function cleanBin() {
|
|||
}
|
||||
}
|
||||
|
||||
export async function cleanRegistry(packages: Packages) {
|
||||
export async function cleanRegistry(packages: 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"));
|
||||
|
@ -106,6 +106,11 @@ export async function cleanRegistry(packages: Packages) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!crates) {
|
||||
core.debug(`skipping crate cleanup`);
|
||||
return;
|
||||
}
|
||||
|
||||
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
|
||||
|
||||
// `.cargo/registry/cache`
|
||||
|
|
15
src/save.ts
15
src/save.ts
|
@ -40,29 +40,30 @@ async function run() {
|
|||
core.info(`... Cleaning ${workspace.target} ...`);
|
||||
await cleanTargetDir(workspace.target, packages);
|
||||
} catch (e) {
|
||||
core.info(`[warning] ${(e as any).stack}`);
|
||||
core.error(`${(e as any).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 as any).stack}`);
|
||||
core.error(`${(e as any).stack}`);
|
||||
}
|
||||
|
||||
try {
|
||||
core.info(`... Cleaning cargo/bin ...`);
|
||||
await cleanBin();
|
||||
} catch (e) {
|
||||
core.info(`[warning] ${(e as any).stack}`);
|
||||
core.error(`${(e as any).stack}`);
|
||||
}
|
||||
|
||||
try {
|
||||
core.info(`... Cleaning cargo git cache ...`);
|
||||
await cleanGit(allPackages);
|
||||
} catch (e) {
|
||||
core.info(`[warning] ${(e as any).stack}`);
|
||||
core.error(`${(e as any).stack}`);
|
||||
}
|
||||
|
||||
core.info(`... Saving cache ...`);
|
||||
|
@ -71,7 +72,7 @@ async function run() {
|
|||
// TODO: remove this once the underlying bug is fixed.
|
||||
await cache.saveCache(config.cachePaths.slice(), config.cacheKey);
|
||||
} catch (e) {
|
||||
core.info(`[warning] ${(e as any).stack}`);
|
||||
core.error(`${(e as any).stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue