diff --git a/README.md b/README.md index 046e3f1..2b95ff6 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,12 @@ sensible defaults. # default: "false" cache-on-failure: "" + # Determines which crates are cached. + # If `true` all crates will be cached, otherwise only dependent crates will be cached. + # Useful if additional crates are used for CI tooling. + # default: "false" + cache-all-crates: "" + # Determiners whether the cache should be saved. # If `false`, the cache is only restored. # Useful for jobs where the matrix is additive e.g. additional Cargo features. diff --git a/action.yml b/action.yml index 7469b80..1f3fe37 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,10 @@ inputs: cache-on-failure: description: "Cache even if the build fails. Defaults to false." required: false + cache-all-crates: + description: "Determines which crates are cached. If `true` all crates will be cached, otherwise only dependent crates will be cached." + required: false + default: "false" save-if: description: "Determiners whether the cache should be saved. If `false`, the cache is only restored." required: false diff --git a/dist/restore/index.js b/dist/restore/index.js index 8f78914..2337e53 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -60234,7 +60234,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")); @@ -60252,6 +60252,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")); diff --git a/dist/save/index.js b/dist/save/index.js index 4abea7f..7ab9fde 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -60234,7 +60234,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")); @@ -60252,6 +60252,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")); @@ -60417,29 +60421,30 @@ 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 ...`); // Pass a copy of cachePaths to avoid mutating the original array as reported by: @@ -60448,7 +60453,7 @@ async function run() { await cache.saveCache(config.cachePaths.slice(), config.cacheKey); } catch (e) { - core.info(`[warning] ${e.stack}`); + core.error(`${e.stack}`); } } run(); diff --git a/src/cleanup.ts b/src/cleanup.ts index 626b715..6787d83 100644 --- a/src/cleanup.ts +++ b/src/cleanup.ts @@ -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` diff --git a/src/save.ts b/src/save.ts index 7882120..f043f47 100644 --- a/src/save.ts +++ b/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}`); } }