3 Commits

Author SHA1 Message Date
Arpad Borsos
a226033982 2.7.2
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-01-10 19:34:14 +01:00
Max Heller
d30f1144e8 Only key by Cargo.toml and Cargo.lock files of workspace members (#180) 2023-12-03 11:57:51 +01:00
Linda_pp
b1db5f9d5f Update action runtime to node20 (#175) 2023-10-25 20:36:38 +02:00
12 changed files with 98 additions and 68 deletions

View File

@@ -17,10 +17,10 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup Node.js 16.x - name: Setup Node.js 20.x
uses: actions/setup-node@v3 uses: actions/setup-node@v3
with: with:
node-version: 16.x node-version: 20.x
cache: npm cache: npm
- name: Install dependencies - name: Install dependencies

View File

@@ -1,5 +1,9 @@
# Changelog # Changelog
## 2.7.2
- Only key by `Cargo.toml` and `Cargo.lock` files of workspace members.
## 2.7.1 ## 2.7.1
- Update toml parser to fix parsing errors. - Update toml parser to fix parsing errors.

View File

@@ -44,7 +44,7 @@ outputs:
cache-hit: cache-hit:
description: "A boolean value that indicates an exact match was found." description: "A boolean value that indicates an exact match was found."
runs: runs:
using: "node16" using: "node20"
main: "dist/restore/index.js" main: "dist/restore/index.js"
post: "dist/save/index.js" post: "dist/save/index.js"
post-if: "success() || env.CACHE_ON_FAILURE == 'true'" post-if: "success() || env.CACHE_ON_FAILURE == 'true'"

48
dist/restore/index.js vendored
View File

@@ -86960,6 +86960,7 @@ var cache_lib_cache = __nccwpck_require__(7799);
function reportError(e) { function reportError(e) {
const { commandFailed } = e; const { commandFailed } = e;
if (commandFailed) { if (commandFailed) {
@@ -87007,6 +87008,15 @@ function getCacheProvider() {
cache: cache, cache: cache,
}; };
} }
async function utils_exists(path) {
try {
await external_fs_default().promises.access(path);
return true;
}
catch {
return false;
}
}
;// CONCATENATED MODULE: ./src/workspace.ts ;// CONCATENATED MODULE: ./src/workspace.ts
@@ -87018,25 +87028,30 @@ class Workspace {
this.root = root; this.root = root;
this.target = target; this.target = target;
} }
async getPackages() { async getPackages(filter, ...extraArgs) {
let packages = []; let packages = [];
try { try {
lib_core.debug(`collecting metadata for "${this.root}"`); lib_core.debug(`collecting metadata for "${this.root}"`);
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"], { const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], {
cwd: this.root, cwd: this.root,
})); }));
lib_core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`); lib_core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
for (const pkg of meta.packages) { for (const pkg of meta.packages.filter(filter)) {
if (pkg.manifest_path.startsWith(this.root)) {
continue;
}
const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name); const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name);
packages.push({ name: pkg.name, version: pkg.version, targets, path: external_path_default().dirname(pkg.manifest_path) }); packages.push({ name: pkg.name, version: pkg.version, targets, path: external_path_default().dirname(pkg.manifest_path) });
} }
} }
catch { } catch (err) {
console.error(err);
}
return packages; return packages;
} }
async getPackagesOutsideWorkspaceRoot() {
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root));
}
async getWorkspaceMembers() {
return await this.getPackages(_ => true, "--no-deps");
}
} }
;// CONCATENATED MODULE: ./src/config.ts ;// CONCATENATED MODULE: ./src/config.ts
@@ -87152,7 +87167,8 @@ class CacheConfig {
for (const workspace of workspaces) { for (const workspace of workspaces) {
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 cargo_manifests = sort_and_uniq(await globFiles(`${root}/**/Cargo.toml`)); const workspaceMembers = await workspace.getWorkspaceMembers();
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" });
@@ -87193,8 +87209,8 @@ class CacheConfig {
keyFiles.push(cargo_manifest); keyFiles.push(cargo_manifest);
} }
} }
const cargo_locks = sort_and_uniq(await globFiles(`${root}/**/Cargo.lock`)); const cargo_lock = external_path_default().join(workspace.root, "Cargo.lock");
for (const cargo_lock of cargo_locks) { if (await utils_exists(cargo_lock)) {
try { try {
const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" }); const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" });
const parsed = parse(content); const parsed = parse(content);
@@ -87357,6 +87373,7 @@ function sort_and_uniq(a) {
async function cleanTargetDir(targetDir, packages, checkTimestamp = false) { async function cleanTargetDir(targetDir, packages, checkTimestamp = false) {
lib_core.debug(`cleaning target directory "${targetDir}"`); lib_core.debug(`cleaning target directory "${targetDir}"`);
// remove all *files* from the profile directory // remove all *files* from the profile directory
@@ -87365,7 +87382,7 @@ async function cleanTargetDir(targetDir, packages, checkTimestamp = false) {
if (dirent.isDirectory()) { if (dirent.isDirectory()) {
let dirName = external_path_default().join(dir.path, dirent.name); let dirName = external_path_default().join(dir.path, dirent.name);
// is it a profile dir, or a nested target dir? // is it a profile dir, or a nested target dir?
let isNestedTarget = (await exists(external_path_default().join(dirName, "CACHEDIR.TAG"))) || (await exists(external_path_default().join(dirName, ".rustc_info.json"))); let isNestedTarget = (await utils_exists(external_path_default().join(dirName, "CACHEDIR.TAG"))) || (await utils_exists(external_path_default().join(dirName, ".rustc_info.json")));
try { try {
if (isNestedTarget) { if (isNestedTarget) {
await cleanTargetDir(dirName, packages, checkTimestamp); await cleanTargetDir(dirName, packages, checkTimestamp);
@@ -87638,15 +87655,6 @@ async function rmRF(dirName) {
core.debug(`deleting "${dirName}"`); core.debug(`deleting "${dirName}"`);
await io.rmRF(dirName); await io.rmRF(dirName);
} }
async function exists(path) {
try {
await external_fs_default().promises.access(path);
return true;
}
catch {
return false;
}
}
;// CONCATENATED MODULE: ./src/restore.ts ;// CONCATENATED MODULE: ./src/restore.ts

48
dist/save/index.js vendored
View File

@@ -86960,6 +86960,7 @@ var cache_lib_cache = __nccwpck_require__(7799);
function reportError(e) { function reportError(e) {
const { commandFailed } = e; const { commandFailed } = e;
if (commandFailed) { if (commandFailed) {
@@ -87007,6 +87008,15 @@ function getCacheProvider() {
cache: cache, cache: cache,
}; };
} }
async function exists(path) {
try {
await external_fs_default().promises.access(path);
return true;
}
catch {
return false;
}
}
;// CONCATENATED MODULE: ./src/workspace.ts ;// CONCATENATED MODULE: ./src/workspace.ts
@@ -87018,25 +87028,30 @@ class Workspace {
this.root = root; this.root = root;
this.target = target; this.target = target;
} }
async getPackages() { async getPackages(filter, ...extraArgs) {
let packages = []; let packages = [];
try { try {
core.debug(`collecting metadata for "${this.root}"`); core.debug(`collecting metadata for "${this.root}"`);
const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"], { const meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], {
cwd: this.root, cwd: this.root,
})); }));
core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`); core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
for (const pkg of meta.packages) { for (const pkg of meta.packages.filter(filter)) {
if (pkg.manifest_path.startsWith(this.root)) {
continue;
}
const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name); const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name);
packages.push({ name: pkg.name, version: pkg.version, targets, path: external_path_default().dirname(pkg.manifest_path) }); packages.push({ name: pkg.name, version: pkg.version, targets, path: external_path_default().dirname(pkg.manifest_path) });
} }
} }
catch { } catch (err) {
console.error(err);
}
return packages; return packages;
} }
async getPackagesOutsideWorkspaceRoot() {
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root));
}
async getWorkspaceMembers() {
return await this.getPackages(_ => true, "--no-deps");
}
} }
;// CONCATENATED MODULE: ./src/config.ts ;// CONCATENATED MODULE: ./src/config.ts
@@ -87152,7 +87167,8 @@ class CacheConfig {
for (const workspace of workspaces) { for (const workspace of workspaces) {
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 cargo_manifests = sort_and_uniq(await globFiles(`${root}/**/Cargo.toml`)); const workspaceMembers = await workspace.getWorkspaceMembers();
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" });
@@ -87193,8 +87209,8 @@ class CacheConfig {
keyFiles.push(cargo_manifest); keyFiles.push(cargo_manifest);
} }
} }
const cargo_locks = sort_and_uniq(await globFiles(`${root}/**/Cargo.lock`)); const cargo_lock = external_path_default().join(workspace.root, "Cargo.lock");
for (const cargo_lock of cargo_locks) { if (await exists(cargo_lock)) {
try { try {
const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" }); const content = await promises_default().readFile(cargo_lock, { encoding: "utf8" });
const parsed = parse(content); const parsed = parse(content);
@@ -87357,6 +87373,7 @@ function sort_and_uniq(a) {
async function cleanTargetDir(targetDir, packages, checkTimestamp = false) { async function cleanTargetDir(targetDir, packages, checkTimestamp = false) {
core.debug(`cleaning target directory "${targetDir}"`); core.debug(`cleaning target directory "${targetDir}"`);
// remove all *files* from the profile directory // remove all *files* from the profile directory
@@ -87638,15 +87655,6 @@ async function rmRF(dirName) {
core.debug(`deleting "${dirName}"`); core.debug(`deleting "${dirName}"`);
await io.rmRF(dirName); await io.rmRF(dirName);
} }
async function exists(path) {
try {
await external_fs_default().promises.access(path);
return true;
}
catch {
return false;
}
}
;// CONCATENATED MODULE: ./src/save.ts ;// CONCATENATED MODULE: ./src/save.ts
@@ -87678,7 +87686,7 @@ async function run() {
await macOsWorkaround(); await macOsWorkaround();
const allPackages = []; const allPackages = [];
for (const workspace of config.workspaces) { for (const workspace of config.workspaces) {
const packages = await workspace.getPackages(); const packages = await workspace.getPackagesOutsideWorkspaceRoot();
allPackages.push(...packages); allPackages.push(...packages);
try { try {
core.info(`... Cleaning ${workspace.target} ...`); core.info(`... Cleaning ${workspace.target} ...`);

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "rust-cache", "name": "rust-cache",
"version": "2.7.1", "version": "2.7.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "rust-cache", "name": "rust-cache",
"version": "2.7.1", "version": "2.7.2",
"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.1", "version": "2.7.2",
"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

@@ -4,6 +4,7 @@ import fs from "fs";
import path from "path"; import path from "path";
import { CARGO_HOME } from "./config"; import { CARGO_HOME } from "./config";
import { exists } from "./utils";
import { Packages } from "./workspace"; import { Packages } from "./workspace";
export async function cleanTargetDir(targetDir: string, packages: Packages, checkTimestamp = false) { export async function cleanTargetDir(targetDir: string, packages: Packages, checkTimestamp = false) {
@@ -308,12 +309,3 @@ async function rmRF(dirName: string) {
core.debug(`deleting "${dirName}"`); core.debug(`deleting "${dirName}"`);
await io.rmRF(dirName); await io.rmRF(dirName);
} }
async function exists(path: string) {
try {
await fs.promises.access(path);
return true;
} catch {
return false;
}
}

View File

@@ -8,7 +8,7 @@ import path from "path";
import * as toml from "smol-toml"; import * as toml from "smol-toml";
import { getCargoBins } from "./cleanup"; import { getCargoBins } from "./cleanup";
import { CacheProvider, getCmdOutput } from "./utils"; import { CacheProvider, exists, getCmdOutput } from "./utils";
import { Workspace } from "./workspace"; import { Workspace } from "./workspace";
const HOME = os.homedir(); const HOME = os.homedir();
@@ -142,7 +142,9 @@ export class CacheConfig {
)), )),
); );
const cargo_manifests = sort_and_uniq(await globFiles(`${root}/**/Cargo.toml`)); const workspaceMembers = await workspace.getWorkspaceMembers();
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 {
@@ -189,9 +191,8 @@ export class CacheConfig {
} }
} }
const cargo_locks = sort_and_uniq(await globFiles(`${root}/**/Cargo.lock`)); const cargo_lock = path.join(workspace.root, "Cargo.lock");
if (await exists(cargo_lock)) {
for (const cargo_lock of cargo_locks) {
try { try {
const content = await fs_promises.readFile(cargo_lock, { encoding: "utf8" }); const content = await fs_promises.readFile(cargo_lock, { encoding: "utf8" });
const parsed = toml.parse(content); const parsed = toml.parse(content);

View File

@@ -36,7 +36,7 @@ async function run() {
const allPackages = []; const allPackages = [];
for (const workspace of config.workspaces) { for (const workspace of config.workspaces) {
const packages = await workspace.getPackages(); const packages = await workspace.getPackagesOutsideWorkspaceRoot();
allPackages.push(...packages); allPackages.push(...packages);
try { try {
core.info(`... Cleaning ${workspace.target} ...`); core.info(`... Cleaning ${workspace.target} ...`);

View File

@@ -2,6 +2,7 @@ import * as core from "@actions/core";
import * as exec from "@actions/exec"; import * as exec from "@actions/exec";
import * as buildjetCache from "@actions/buildjet-cache"; import * as buildjetCache from "@actions/buildjet-cache";
import * as ghCache from "@actions/cache"; import * as ghCache from "@actions/cache";
import fs from "fs";
export function reportError(e: any) { export function reportError(e: any) {
const { commandFailed } = e; const { commandFailed } = e;
@@ -61,3 +62,12 @@ export function getCacheProvider(): CacheProvider {
cache: cache, cache: cache,
}; };
} }
export async function exists(path: string) {
try {
await fs.promises.access(path);
return true;
} catch {
return false;
}
}

View File

@@ -8,26 +8,33 @@ 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) {}
public async getPackages(): 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}"`);
const meta: Meta = JSON.parse( const meta: Meta = JSON.parse(
await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"], { await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], {
cwd: this.root, cwd: this.root,
}), }),
); );
core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`); core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
for (const pkg of meta.packages) { for (const pkg of meta.packages.filter(filter)) {
if (pkg.manifest_path.startsWith(this.root)) {
continue;
}
const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name); const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name);
packages.push({ name: pkg.name, version: pkg.version, targets, path: path.dirname(pkg.manifest_path) }); packages.push({ name: pkg.name, version: pkg.version, targets, path: path.dirname(pkg.manifest_path) });
} }
} catch {} } catch (err) {
console.error(err);
}
return packages; return packages;
} }
public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> {
return await this.getPackages(pkg => !pkg.manifest_path.startsWith(this.root));
}
public async getWorkspaceMembers(): Promise<Packages> {
return await this.getPackages(_ => true, "--no-deps");
}
} }
export interface PackageDefinition { export interface PackageDefinition {