MCPcopy
hub / github.com/Swatinem/rust-cache / run

Function run

src/restore.ts:14–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12});
13
14async function run() {
15 const cacheProvider = getCacheProvider();
16
17 if (!cacheProvider.cache.isFeatureAvailable()) {
18 setCacheHitOutput(false);
19 return;
20 }
21
22 try {
23 var cacheOnFailure = core.getInput("cache-on-failure").toLowerCase();
24 if (cacheOnFailure !== "true") {
25 cacheOnFailure = "false";
26 }
27 var lookupOnly = core.getInput("lookup-only").toLowerCase() === "true";
28
29 core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
30 core.exportVariable("CARGO_INCREMENTAL", 0);
31
32 const config = await CacheConfig.new();
33 config.printInfo(cacheProvider);
34 core.info("");
35
36 core.info(`... ${lookupOnly ? "Checking" : "Restoring"} cache ...`);
37 const key = config.cacheKey;
38 // Pass a copy of cachePaths to avoid mutating the original array as reported by:
39 // https://github.com/actions/toolkit/pull/1378
40 // TODO: remove this once the underlying bug is fixed.
41 const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], {
42 lookupOnly,
43 });
44 if (restoreKey) {
45 const match = restoreKey.localeCompare(key, undefined, {
46 sensitivity: "accent"
47 }) === 0;
48 core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
49 if (!match) {
50 // pre-clean the target directory on cache mismatch
51 for (const workspace of config.workspaces) {
52 try {
53 await cleanTargetDir(workspace.target, [], true);
54 } catch {}
55 }
56
57 // We restored the cache but it is not a full match.
58 config.saveState();
59 }
60
61 setCacheHitOutput(match);
62 } else {
63 core.info("No cache found.");
64 config.saveState();
65
66 setCacheHitOutput(false);
67 }
68 } catch (e) {
69 setCacheHitOutput(false);
70
71 reportError(e);

Callers 1

restore.tsFile · 0.70

Calls 7

getCacheProviderFunction · 0.90
cleanTargetDirFunction · 0.90
reportErrorFunction · 0.90
setCacheHitOutputFunction · 0.85
newMethod · 0.80
printInfoMethod · 0.80
saveStateMethod · 0.80

Tested by

no test coverage detected