2 Commits

Author SHA1 Message Date
Arpad Borsos
f0deed1e0e 2.7.7
Some checks failed
buildjet / Test buildjet provider on ubuntu-latest (push) Failing after 0s
coverage / Test `cargo-llvm-cov` on ubuntu-latest (push) Failing after 0s
git-registry / Test cargo "git" registry on ubuntu-latest (push) Failing after 0s
install / Test `cargo install` on ubuntu-latest (push) Failing after 0s
simple / Test `cargo check/test/build` on ubuntu-latest (push) Failing after 0s
target-dir / Test custom target-dir on ubuntu-latest (push) Failing after 0s
workspaces / Test multiple workspaces on ubuntu-latest (push) Failing after 0s
buildjet / Test buildjet provider on macos-latest (push) Has been cancelled
buildjet / Test buildjet provider on windows-latest (push) Has been cancelled
coverage / Test `cargo-llvm-cov` on macos-latest (push) Has been cancelled
coverage / Test `cargo-llvm-cov` on windows-latest (push) Has been cancelled
git-registry / Test cargo "git" registry on macos-latest (push) Has been cancelled
git-registry / Test cargo "git" registry on windows-latest (push) Has been cancelled
install / Test `cargo install` on macos-latest (push) Has been cancelled
install / Test `cargo install` on windows-latest (push) Has been cancelled
simple / Test `cargo check/test/build` on macos-latest (push) Has been cancelled
simple / Test `cargo check/test/build` on windows-latest (push) Has been cancelled
target-dir / Test custom target-dir on macos-latest (push) Has been cancelled
target-dir / Test custom target-dir on windows-latest (push) Has been cancelled
workspaces / Test multiple workspaces on macos-latest (push) Has been cancelled
workspaces / Test multiple workspaces on windows-latest (push) Has been cancelled
2024-12-29 08:48:10 +01:00
Arpad Borsos
008623fb83 also cache cargo install metadata 2024-12-29 08:47:45 +01:00
8 changed files with 59 additions and 52 deletions

30
dist/restore/index.js vendored
View File

@@ -86684,10 +86684,10 @@ class Workspace {
return packages; return packages;
} }
async getPackagesOutsideWorkspaceRoot() { async getPackagesOutsideWorkspaceRoot() {
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root)); return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
} }
async getWorkspaceMembers() { async getWorkspaceMembers() {
return await this.getPackages(_ => true, "--no-deps"); return await this.getPackages((_) => true, "--no-deps");
} }
} }
@@ -86811,7 +86811,7 @@ class CacheConfig {
const root = workspace.root; const root = workspace.root;
keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`))); keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`)));
const workspaceMembers = await workspace.getWorkspaceMembers(); const workspaceMembers = await workspace.getWorkspaceMembers();
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => external_path_default().join(member.path, "Cargo.toml"))); const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => external_path_default().join(member.path, "Cargo.toml")));
for (const cargo_manifest of cargo_manifests) { for (const cargo_manifest of cargo_manifests) {
try { try {
const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" }); const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" });
@@ -86847,7 +86847,8 @@ class CacheConfig {
hasher.update(JSON.stringify(parsed)); hasher.update(JSON.stringify(parsed));
parsedKeyFiles.push(cargo_manifest); parsedKeyFiles.push(cargo_manifest);
} }
catch (e) { // Fallback to caching them as regular file catch (e) {
// Fallback to caching them as regular file
lib_core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`); lib_core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
keyFiles.push(cargo_manifest); keyFiles.push(cargo_manifest);
} }
@@ -86860,7 +86861,7 @@ class CacheConfig {
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) { if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
// Fallback to caching them as regular file since this action // Fallback to caching them as regular file since this action
// can only handle Cargo.lock format version 3 // can only handle Cargo.lock format version 3
lib_core.warning('Unsupported Cargo.lock format, fallback to caching entire file'); lib_core.warning("Unsupported Cargo.lock format, fallback to caching entire file");
keyFiles.push(cargo_lock); keyFiles.push(cargo_lock);
continue; continue;
} }
@@ -86870,7 +86871,8 @@ class CacheConfig {
hasher.update(JSON.stringify(packages)); hasher.update(JSON.stringify(packages));
parsedKeyFiles.push(cargo_lock); parsedKeyFiles.push(cargo_lock);
} }
catch (e) { // Fallback to caching them as regular file catch (e) {
// Fallback to caching them as regular file
lib_core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`); lib_core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
keyFiles.push(cargo_lock); keyFiles.push(cargo_lock);
} }
@@ -86887,12 +86889,14 @@ class CacheConfig {
self.keyFiles = sort_and_uniq(keyFiles); self.keyFiles = sort_and_uniq(keyFiles);
key += `-${lockHash}`; key += `-${lockHash}`;
self.cacheKey = key; self.cacheKey = key;
self.cachePaths = [ self.cachePaths = [external_path_default().join(config_CARGO_HOME, "registry"), external_path_default().join(config_CARGO_HOME, "git")];
external_path_default().join(config_CARGO_HOME, "registry"),
external_path_default().join(config_CARGO_HOME, "git"),
];
if (self.cacheBin) { if (self.cacheBin) {
self.cachePaths = [external_path_default().join(config_CARGO_HOME, "bin"), ...self.cachePaths]; self.cachePaths = [
external_path_default().join(config_CARGO_HOME, "bin"),
external_path_default().join(config_CARGO_HOME, ".crates.toml"),
external_path_default().join(config_CARGO_HOME, ".crates2.json"),
...self.cachePaths,
];
} }
const cacheTargets = lib_core.getInput("cache-targets").toLowerCase() || "true"; const cacheTargets = lib_core.getInput("cache-targets").toLowerCase() || "true";
if (cacheTargets === "true") { if (cacheTargets === "true") {
@@ -87338,7 +87342,9 @@ async function run() {
// Pass a copy of cachePaths to avoid mutating the original array as reported by: // Pass a copy of cachePaths to avoid mutating the original array as reported by:
// https://github.com/actions/toolkit/pull/1378 // https://github.com/actions/toolkit/pull/1378
// TODO: remove this once the underlying bug is fixed. // TODO: remove this once the underlying bug is fixed.
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], { lookupOnly }); const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], {
lookupOnly,
});
if (restoreKey) { if (restoreKey) {
const match = restoreKey === key; const match = restoreKey === key;
lib_core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`); lib_core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);

26
dist/save/index.js vendored
View File

@@ -86684,10 +86684,10 @@ class Workspace {
return packages; return packages;
} }
async getPackagesOutsideWorkspaceRoot() { async getPackagesOutsideWorkspaceRoot() {
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root)); return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
} }
async getWorkspaceMembers() { async getWorkspaceMembers() {
return await this.getPackages(_ => true, "--no-deps"); return await this.getPackages((_) => true, "--no-deps");
} }
} }
@@ -86811,7 +86811,7 @@ class CacheConfig {
const root = workspace.root; const root = workspace.root;
keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`))); keyFiles.push(...(await globFiles(`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`)));
const workspaceMembers = await workspace.getWorkspaceMembers(); const workspaceMembers = await workspace.getWorkspaceMembers();
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => external_path_default().join(member.path, "Cargo.toml"))); const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => external_path_default().join(member.path, "Cargo.toml")));
for (const cargo_manifest of cargo_manifests) { for (const cargo_manifest of cargo_manifests) {
try { try {
const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" }); const content = await promises_default().readFile(cargo_manifest, { encoding: "utf8" });
@@ -86847,7 +86847,8 @@ class CacheConfig {
hasher.update(JSON.stringify(parsed)); hasher.update(JSON.stringify(parsed));
parsedKeyFiles.push(cargo_manifest); parsedKeyFiles.push(cargo_manifest);
} }
catch (e) { // Fallback to caching them as regular file catch (e) {
// Fallback to caching them as regular file
core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`); core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
keyFiles.push(cargo_manifest); keyFiles.push(cargo_manifest);
} }
@@ -86860,7 +86861,7 @@ class CacheConfig {
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) { if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
// Fallback to caching them as regular file since this action // Fallback to caching them as regular file since this action
// can only handle Cargo.lock format version 3 // can only handle Cargo.lock format version 3
core.warning('Unsupported Cargo.lock format, fallback to caching entire file'); core.warning("Unsupported Cargo.lock format, fallback to caching entire file");
keyFiles.push(cargo_lock); keyFiles.push(cargo_lock);
continue; continue;
} }
@@ -86870,7 +86871,8 @@ class CacheConfig {
hasher.update(JSON.stringify(packages)); hasher.update(JSON.stringify(packages));
parsedKeyFiles.push(cargo_lock); parsedKeyFiles.push(cargo_lock);
} }
catch (e) { // Fallback to caching them as regular file catch (e) {
// Fallback to caching them as regular file
core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`); core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
keyFiles.push(cargo_lock); keyFiles.push(cargo_lock);
} }
@@ -86887,12 +86889,14 @@ class CacheConfig {
self.keyFiles = sort_and_uniq(keyFiles); self.keyFiles = sort_and_uniq(keyFiles);
key += `-${lockHash}`; key += `-${lockHash}`;
self.cacheKey = key; self.cacheKey = key;
self.cachePaths = [ self.cachePaths = [external_path_default().join(CARGO_HOME, "registry"), external_path_default().join(CARGO_HOME, "git")];
external_path_default().join(CARGO_HOME, "registry"),
external_path_default().join(CARGO_HOME, "git"),
];
if (self.cacheBin) { if (self.cacheBin) {
self.cachePaths = [external_path_default().join(CARGO_HOME, "bin"), ...self.cachePaths]; self.cachePaths = [
external_path_default().join(CARGO_HOME, "bin"),
external_path_default().join(CARGO_HOME, ".crates.toml"),
external_path_default().join(CARGO_HOME, ".crates2.json"),
...self.cachePaths,
];
} }
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true"; const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
if (cacheTargets === "true") { if (cacheTargets === "true") {

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "rust-cache", "name": "rust-cache",
"version": "2.7.6", "version": "2.7.7",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "rust-cache", "name": "rust-cache",
"version": "2.7.6", "version": "2.7.7",
"license": "LGPL-3.0", "license": "LGPL-3.0",
"dependencies": { "dependencies": {
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0", "@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0",

View File

@@ -1,7 +1,7 @@
{ {
"private": true, "private": true,
"name": "rust-cache", "name": "rust-cache",
"version": "2.7.6", "version": "2.7.7",
"description": "A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults.", "description": "A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults.",
"keywords": [ "keywords": [
"actions", "actions",

View File

@@ -43,16 +43,16 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25 // https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27 // https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp); cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);
} catch { } } catch {}
try { try {
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50 // https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp); cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp);
} catch { } } catch {}
// Delete everything else. // Delete everything else.
await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp); await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp);
return return;
} }
let keepProfile = new Set(["build", ".fingerprint", "deps"]); let keepProfile = new Set(["build", ".fingerprint", "deps"]);

View File

@@ -153,7 +153,7 @@ export class CacheConfig {
const workspaceMembers = await workspace.getWorkspaceMembers(); const workspaceMembers = await workspace.getWorkspaceMembers();
const cargo_manifests = sort_and_uniq(workspaceMembers.map(member => path.join(member.path, "Cargo.toml"))); const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => path.join(member.path, "Cargo.toml")));
for (const cargo_manifest of cargo_manifests) { for (const cargo_manifest of cargo_manifests) {
try { try {
@@ -194,7 +194,8 @@ export class CacheConfig {
hasher.update(JSON.stringify(parsed)); hasher.update(JSON.stringify(parsed));
parsedKeyFiles.push(cargo_manifest); parsedKeyFiles.push(cargo_manifest);
} catch (e) { // Fallback to caching them as regular file } catch (e) {
// Fallback to caching them as regular file
core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`); core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
keyFiles.push(cargo_manifest); keyFiles.push(cargo_manifest);
} }
@@ -209,7 +210,7 @@ export class CacheConfig {
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) { if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
// Fallback to caching them as regular file since this action // Fallback to caching them as regular file since this action
// can only handle Cargo.lock format version 3 // can only handle Cargo.lock format version 3
core.warning('Unsupported Cargo.lock format, fallback to caching entire file'); core.warning("Unsupported Cargo.lock format, fallback to caching entire file");
keyFiles.push(cargo_lock); keyFiles.push(cargo_lock);
continue; continue;
} }
@@ -221,7 +222,8 @@ export class CacheConfig {
hasher.update(JSON.stringify(packages)); hasher.update(JSON.stringify(packages));
parsedKeyFiles.push(cargo_lock); parsedKeyFiles.push(cargo_lock);
} catch (e) { // Fallback to caching them as regular file } catch (e) {
// Fallback to caching them as regular file
core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`); core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
keyFiles.push(cargo_lock); keyFiles.push(cargo_lock);
} }
@@ -243,12 +245,14 @@ export class CacheConfig {
key += `-${lockHash}`; key += `-${lockHash}`;
self.cacheKey = key; self.cacheKey = key;
self.cachePaths = [ self.cachePaths = [path.join(CARGO_HOME, "registry"), path.join(CARGO_HOME, "git")];
path.join(CARGO_HOME, "registry"),
path.join(CARGO_HOME, "git"),
];
if (self.cacheBin) { if (self.cacheBin) {
self.cachePaths = [path.join(CARGO_HOME, "bin"), ...self.cachePaths]; self.cachePaths = [
path.join(CARGO_HOME, "bin"),
path.join(CARGO_HOME, ".crates.toml"),
path.join(CARGO_HOME, ".crates2.json"),
...self.cachePaths,
];
} }
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true"; const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
if (cacheTargets === "true") { if (cacheTargets === "true") {

View File

@@ -38,19 +38,12 @@ async function run() {
// Pass a copy of cachePaths to avoid mutating the original array as reported by: // Pass a copy of cachePaths to avoid mutating the original array as reported by:
// https://github.com/actions/toolkit/pull/1378 // https://github.com/actions/toolkit/pull/1378
// TODO: remove this once the underlying bug is fixed. // TODO: remove this once the underlying bug is fixed.
const restoreKey = await cacheProvider.cache.restoreCache( const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], {
config.cachePaths.slice(), lookupOnly,
key, });
[config.restoreKey],
{ lookupOnly }
);
if (restoreKey) { if (restoreKey) {
const match = restoreKey === key; const match = restoreKey === key;
core.info( core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
`${
lookupOnly ? "Found" : "Restored from"
} cache key "${restoreKey}" full match: ${match}.`
);
if (!match) { if (!match) {
// pre-clean the target directory on cache mismatch // pre-clean the target directory on cache mismatch
for (const workspace of config.workspaces) { for (const workspace of config.workspaces) {

View File

@@ -8,7 +8,7 @@ const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
export class Workspace { export class Workspace {
constructor(public root: string, public target: string) {} constructor(public root: string, public target: string) {}
async getPackages(filter: ((p: Meta['packages'][0]) => boolean), ...extraArgs: string[]): Promise<Packages> { async getPackages(filter: (p: Meta["packages"][0]) => boolean, ...extraArgs: string[]): Promise<Packages> {
let packages: Packages = []; let packages: Packages = [];
try { try {
core.debug(`collecting metadata for "${this.root}"`); core.debug(`collecting metadata for "${this.root}"`);
@@ -29,11 +29,11 @@ export class Workspace {
} }
public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> { public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> {
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root)); return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
} }
public async getWorkspaceMembers(): Promise<Packages> { public async getWorkspaceMembers(): Promise<Packages> {
return await this.getPackages(_ => true, "--no-deps"); return await this.getPackages((_) => true, "--no-deps");
} }
} }