3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2025-11-08 00:15:06 +00:00

fix: cache key stability (#142)

Ensure consistency of main and post configuration by storing and
restoring it from state, which in turn ensures cache key stability.

Also:
* Fixed some typos.
* Use core.error for logging errors.
* Fix inverted condition on cache-all-crates.

Reverts: #138
Fixes #140
This commit is contained in:
Steven Hartland 2023-05-18 21:48:40 +01:00 committed by GitHub
parent 060bda31e0
commit ad97570a01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 260 additions and 175 deletions

View file

@ -3,12 +3,12 @@ import * as core from "@actions/core";
import * as exec from "@actions/exec";
import { cleanBin, cleanGit, cleanRegistry, cleanTargetDir } from "./cleanup";
import { CacheConfig, STATE_KEY } from "./config";
import { CacheConfig, isCacheUpToDate } from "./config";
process.on("uncaughtException", (e) => {
core.info(`[warning] ${e.message}`);
core.error(e.message);
if (e.stack) {
core.info(e.stack);
core.error(e.stack);
}
});
@ -20,15 +20,15 @@ async function run() {
}
try {
const config = await CacheConfig.new();
config.printInfo();
core.info("");
if (core.getState(STATE_KEY) === config.cacheKey) {
if (isCacheUpToDate()) {
core.info(`Cache up-to-date.`);
return;
}
const config = CacheConfig.fromState();
config.printInfo();
core.info("");
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
await macOsWorkaround();
@ -45,16 +45,16 @@ async function run() {
}
try {
const creates = core.getInput("cache-all-crates").toLowerCase() || "false";
core.info(`... Cleaning cargo registry cache-all-crates: ${creates} ...`);
await cleanRegistry(allPackages, creates === "true");
const crates = core.getInput("cache-all-crates").toLowerCase() || "false"
core.info(`... Cleaning cargo registry cache-all-crates: ${crates} ...`);
await cleanRegistry(allPackages, crates !== "true");
} catch (e) {
core.error(`${(e as any).stack}`);
}
try {
core.info(`... Cleaning cargo/bin ...`);
await cleanBin();
await cleanBin(config.cargoBins);
} catch (e) {
core.error(`${(e as any).stack}`);
}