diff --git a/action.yml b/action.yml index d20981c..b7d4e21 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,9 @@ inputs: target-dir: description: "The target dir that should be cleaned and persisted, defaults to `./target`" required: false + workspace-paths: + description: "Paths to multiple Cargo workspaces, separated by newlines" + required: false cache-on-failure: description: "Cache even if the build fails. Defaults to false" required: false diff --git a/src/common.ts b/src/common.ts index b8f6187..b74ed83 100644 --- a/src/common.ts +++ b/src/common.ts @@ -186,16 +186,24 @@ interface Meta { }>; } -export async function getPackages(): Promise { +export async function getPackages(workspacePaths: Array): Promise { const cwd = process.cwd(); - const meta: Meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"])); - return meta.packages - .filter((p) => !p.manifest_path.startsWith(cwd)) - .map((p) => { - const targets = p.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name); - return { name: p.name, version: p.version, targets, path: path.dirname(p.manifest_path) }; - }); + let allPackages: Packages = []; + for (const workspacePath of workspacePaths) { + process.chdir(workspacePath); + const meta: Meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"])); + const workspacePackages = meta.packages + .filter((p) => !p.manifest_path.startsWith(cwd)) + .map((p) => { + const targets = p.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name); + return { name: p.name, version: p.version, targets, path: path.dirname(p.manifest_path) }; + }); + allPackages = allPackages.concat(workspacePackages); + } + + process.chdir(cwd); + return allPackages; } export async function cleanTarget(targetDir: string, packages: Packages) { diff --git a/src/restore.ts b/src/restore.ts index b769791..7918aa2 100644 --- a/src/restore.ts +++ b/src/restore.ts @@ -33,7 +33,7 @@ async function run() { if (restoreKey !== key) { // pre-clean the target directory on cache mismatch - const packages = await getPackages(); + const packages = await getPackages(workspaces); for (const workspace of workspaces) { const target = path.join(workspace, "target"); diff --git a/src/save.ts b/src/save.ts index 27bdbe3..c28dec5 100644 --- a/src/save.ts +++ b/src/save.ts @@ -35,7 +35,7 @@ async function run() { await macOsWorkaround(); const registryName = await getRegistryName(); - const packages = await getPackages(); + const packages = await getPackages(workspaces); if (registryName) { try {