Skip to content

Commit 008623f

Browse files
committed
also cache cargo install metadata
1 parent 720f7e4 commit 008623f

File tree

6 files changed

+56
-49
lines changed

6 files changed

+56
-49
lines changed

dist/restore/index.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -86684,10 +86684,10 @@ class Workspace {
8668486684
return packages;
8668586685
}
8668686686
async getPackagesOutsideWorkspaceRoot() {
86687-
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root));
86687+
return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
8668886688
}
8668986689
async getWorkspaceMembers() {
86690-
return await this.getPackages(_ => true, "--no-deps");
86690+
return await this.getPackages((_) => true, "--no-deps");
8669186691
}
8669286692
}
8669386693

@@ -86811,7 +86811,7 @@ class CacheConfig {
8681186811
const root = workspace.root;
8681286812
keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`)));
8681386813
const workspaceMembers = await workspace.getWorkspaceMembers();
86814-
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => external_path_default().join(member.path, "Cargo.toml")));
86814+
const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => external_path_default().join(member.path, "Cargo.toml")));
8681586815
for (const cargo_manifest of cargo_manifests) {
8681686816
try {
8681786817
const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" });
@@ -86847,7 +86847,8 @@ class CacheConfig {
8684786847
hasher.update(JSON.stringify(parsed));
8684886848
parsedKeyFiles.push(cargo_manifest);
8684986849
}
86850-
catch (e) { // Fallback to caching them as regular file
86850+
catch (e) {
86851+
// Fallback to caching them as regular file
8685186852
lib_core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
8685286853
keyFiles.push(cargo_manifest);
8685386854
}
@@ -86860,7 +86861,7 @@ class CacheConfig {
8686086861
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
8686186862
// Fallback to caching them as regular file since this action
8686286863
// can only handle Cargo.lock format version 3
86863-
lib_core.warning('Unsupported Cargo.lock format, fallback to caching entire file');
86864+
lib_core.warning("Unsupported Cargo.lock format, fallback to caching entire file");
8686486865
keyFiles.push(cargo_lock);
8686586866
continue;
8686686867
}
@@ -86870,7 +86871,8 @@ class CacheConfig {
8687086871
hasher.update(JSON.stringify(packages));
8687186872
parsedKeyFiles.push(cargo_lock);
8687286873
}
86873-
catch (e) { // Fallback to caching them as regular file
86874+
catch (e) {
86875+
// Fallback to caching them as regular file
8687486876
lib_core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
8687586877
keyFiles.push(cargo_lock);
8687686878
}
@@ -86887,12 +86889,14 @@ class CacheConfig {
8688786889
self.keyFiles = sort_and_uniq(keyFiles);
8688886890
key += `-${lockHash}`;
8688986891
self.cacheKey = key;
86890-
self.cachePaths = [
86891-
external_path_default().join(config_CARGO_HOME, "registry"),
86892-
external_path_default().join(config_CARGO_HOME, "git"),
86893-
];
86892+
self.cachePaths = [external_path_default().join(config_CARGO_HOME, "registry"), external_path_default().join(config_CARGO_HOME, "git")];
8689486893
if (self.cacheBin) {
86895-
self.cachePaths = [external_path_default().join(config_CARGO_HOME, "bin"), ...self.cachePaths];
86894+
self.cachePaths = [
86895+
external_path_default().join(config_CARGO_HOME, "bin"),
86896+
external_path_default().join(config_CARGO_HOME, ".crates.toml"),
86897+
external_path_default().join(config_CARGO_HOME, ".crates2.json"),
86898+
...self.cachePaths,
86899+
];
8689686900
}
8689786901
const cacheTargets = lib_core.getInput("cache-targets").toLowerCase() || "true";
8689886902
if (cacheTargets === "true") {
@@ -87338,7 +87342,9 @@ async function run() {
8733887342
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
8733987343
// https://github.com/actions/toolkit/pull/1378
8734087344
// TODO: remove this once the underlying bug is fixed.
87341-
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], { lookupOnly });
87345+
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], {
87346+
lookupOnly,
87347+
});
8734287348
if (restoreKey) {
8734387349
const match = restoreKey === key;
8734487350
lib_core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);

dist/save/index.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -86684,10 +86684,10 @@ class Workspace {
8668486684
return packages;
8668586685
}
8668686686
async getPackagesOutsideWorkspaceRoot() {
86687-
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root));
86687+
return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
8668886688
}
8668986689
async getWorkspaceMembers() {
86690-
return await this.getPackages(_ => true, "--no-deps");
86690+
return await this.getPackages((_) => true, "--no-deps");
8669186691
}
8669286692
}
8669386693

@@ -86811,7 +86811,7 @@ class CacheConfig {
8681186811
const root = workspace.root;
8681286812
keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`)));
8681386813
const workspaceMembers = await workspace.getWorkspaceMembers();
86814-
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => external_path_default().join(member.path, "Cargo.toml")));
86814+
const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => external_path_default().join(member.path, "Cargo.toml")));
8681586815
for (const cargo_manifest of cargo_manifests) {
8681686816
try {
8681786817
const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" });
@@ -86847,7 +86847,8 @@ class CacheConfig {
8684786847
hasher.update(JSON.stringify(parsed));
8684886848
parsedKeyFiles.push(cargo_manifest);
8684986849
}
86850-
catch (e) { // Fallback to caching them as regular file
86850+
catch (e) {
86851+
// Fallback to caching them as regular file
8685186852
core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
8685286853
keyFiles.push(cargo_manifest);
8685386854
}
@@ -86860,7 +86861,7 @@ class CacheConfig {
8686086861
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
8686186862
// Fallback to caching them as regular file since this action
8686286863
// can only handle Cargo.lock format version 3
86863-
core.warning('Unsupported Cargo.lock format, fallback to caching entire file');
86864+
core.warning("Unsupported Cargo.lock format, fallback to caching entire file");
8686486865
keyFiles.push(cargo_lock);
8686586866
continue;
8686686867
}
@@ -86870,7 +86871,8 @@ class CacheConfig {
8687086871
hasher.update(JSON.stringify(packages));
8687186872
parsedKeyFiles.push(cargo_lock);
8687286873
}
86873-
catch (e) { // Fallback to caching them as regular file
86874+
catch (e) {
86875+
// Fallback to caching them as regular file
8687486876
core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
8687586877
keyFiles.push(cargo_lock);
8687686878
}
@@ -86887,12 +86889,14 @@ class CacheConfig {
8688786889
self.keyFiles = sort_and_uniq(keyFiles);
8688886890
key += `-${lockHash}`;
8688986891
self.cacheKey = key;
86890-
self.cachePaths = [
86891-
external_path_default().join(CARGO_HOME, "registry"),
86892-
external_path_default().join(CARGO_HOME, "git"),
86893-
];
86892+
self.cachePaths = [external_path_default().join(CARGO_HOME, "registry"), external_path_default().join(CARGO_HOME, "git")];
8689486893
if (self.cacheBin) {
86895-
self.cachePaths = [external_path_default().join(CARGO_HOME, "bin"), ...self.cachePaths];
86894+
self.cachePaths = [
86895+
external_path_default().join(CARGO_HOME, "bin"),
86896+
external_path_default().join(CARGO_HOME, ".crates.toml"),
86897+
external_path_default().join(CARGO_HOME, ".crates2.json"),
86898+
...self.cachePaths,
86899+
];
8689686900
}
8689786901
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
8689886902
if (cacheTargets === "true") {

src/cleanup.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT
4343
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
4444
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
4545
cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);
46-
} catch { }
46+
} catch {}
4747
try {
4848
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
4949
cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp);
50-
} catch { }
50+
} catch {}
5151

5252
// Delete everything else.
5353
await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp);
5454

55-
return
55+
return;
5656
}
5757

5858
let keepProfile = new Set(["build", ".fingerprint", "deps"]);

src/config.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class CacheConfig {
153153

154154
const workspaceMembers = await workspace.getWorkspaceMembers();
155155

156-
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => path.join(member.path, "Cargo.toml")));
156+
const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => path.join(member.path, "Cargo.toml")));
157157

158158
for (const cargo_manifest of cargo_manifests) {
159159
try {
@@ -194,7 +194,8 @@ export class CacheConfig {
194194
hasher.update(JSON.stringify(parsed));
195195

196196
parsedKeyFiles.push(cargo_manifest);
197-
} catch (e) { // Fallback to caching them as regular file
197+
} catch (e) {
198+
// Fallback to caching them as regular file
198199
core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
199200
keyFiles.push(cargo_manifest);
200201
}
@@ -209,7 +210,7 @@ export class CacheConfig {
209210
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
210211
// Fallback to caching them as regular file since this action
211212
// can only handle Cargo.lock format version 3
212-
core.warning('Unsupported Cargo.lock format, fallback to caching entire file');
213+
core.warning("Unsupported Cargo.lock format, fallback to caching entire file");
213214
keyFiles.push(cargo_lock);
214215
continue;
215216
}
@@ -221,7 +222,8 @@ export class CacheConfig {
221222
hasher.update(JSON.stringify(packages));
222223

223224
parsedKeyFiles.push(cargo_lock);
224-
} catch (e) { // Fallback to caching them as regular file
225+
} catch (e) {
226+
// Fallback to caching them as regular file
225227
core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
226228
keyFiles.push(cargo_lock);
227229
}
@@ -243,12 +245,14 @@ export class CacheConfig {
243245
key += `-${lockHash}`;
244246
self.cacheKey = key;
245247

246-
self.cachePaths = [
247-
path.join(CARGO_HOME, "registry"),
248-
path.join(CARGO_HOME, "git"),
249-
];
248+
self.cachePaths = [path.join(CARGO_HOME, "registry"), path.join(CARGO_HOME, "git")];
250249
if (self.cacheBin) {
251-
self.cachePaths = [path.join(CARGO_HOME, "bin"), ...self.cachePaths];
250+
self.cachePaths = [
251+
path.join(CARGO_HOME, "bin"),
252+
path.join(CARGO_HOME, ".crates.toml"),
253+
path.join(CARGO_HOME, ".crates2.json"),
254+
...self.cachePaths,
255+
];
252256
}
253257
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
254258
if (cacheTargets === "true") {

src/restore.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,12 @@ async function run() {
3838
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
3939
// https://github.com/actions/toolkit/pull/1378
4040
// TODO: remove this once the underlying bug is fixed.
41-
const restoreKey = await cacheProvider.cache.restoreCache(
42-
config.cachePaths.slice(),
43-
key,
44-
[config.restoreKey],
45-
{ lookupOnly }
46-
);
41+
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], {
42+
lookupOnly,
43+
});
4744
if (restoreKey) {
4845
const match = restoreKey === key;
49-
core.info(
50-
`${
51-
lookupOnly ? "Found" : "Restored from"
52-
} cache key "${restoreKey}" full match: ${match}.`
53-
);
46+
core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
5447
if (!match) {
5548
// pre-clean the target directory on cache mismatch
5649
for (const workspace of config.workspaces) {

src/workspace.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
88
export class Workspace {
99
constructor(public root: string, public target: string) {}
1010

11-
async getPackages(filter: ((p: Meta['packages'][0]) => boolean), ...extraArgs: string[]): Promise<Packages> {
11+
async getPackages(filter: (p: Meta["packages"][0]) => boolean, ...extraArgs: string[]): Promise<Packages> {
1212
let packages: Packages = [];
1313
try {
1414
core.debug(`collecting metadata for "${this.root}"`);
@@ -29,11 +29,11 @@ export class Workspace {
2929
}
3030

3131
public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> {
32-
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root));
32+
return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
3333
}
3434

3535
public async getWorkspaceMembers(): Promise<Packages> {
36-
return await this.getPackages(_ => true, "--no-deps");
36+
return await this.getPackages((_) => true, "--no-deps");
3737
}
3838
}
3939

0 commit comments

Comments
 (0)