Update getPackages

This commit is contained in:
Nick Mosher 2022-07-08 21:26:12 -04:00
parent b6a2848a50
commit 971fd2148b
4 changed files with 21 additions and 10 deletions

View File

@ -14,6 +14,9 @@ inputs:
target-dir: target-dir:
description: "The target dir that should be cleaned and persisted, defaults to `./target`" description: "The target dir that should be cleaned and persisted, defaults to `./target`"
required: false required: false
workspace-paths:
description: "Paths to multiple Cargo workspaces, separated by newlines"
required: false
cache-on-failure: cache-on-failure:
description: "Cache even if the build fails. Defaults to false" description: "Cache even if the build fails. Defaults to false"
required: false required: false

View File

@ -186,16 +186,24 @@ interface Meta {
}>; }>;
} }
export async function getPackages(): Promise<Packages> { export async function getPackages(workspacePaths: Array<string>): Promise<Packages> {
const cwd = process.cwd(); const cwd = process.cwd();
const meta: Meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"]));
return meta.packages let allPackages: Packages = [];
.filter((p) => !p.manifest_path.startsWith(cwd)) for (const workspacePath of workspacePaths) {
.map((p) => { process.chdir(workspacePath);
const targets = p.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name); const meta: Meta = JSON.parse(await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"]));
return { name: p.name, version: p.version, targets, path: path.dirname(p.manifest_path) }; 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) { export async function cleanTarget(targetDir: string, packages: Packages) {

View File

@ -33,7 +33,7 @@ async function run() {
if (restoreKey !== key) { if (restoreKey !== key) {
// pre-clean the target directory on cache mismatch // pre-clean the target directory on cache mismatch
const packages = await getPackages(); const packages = await getPackages(workspaces);
for (const workspace of workspaces) { for (const workspace of workspaces) {
const target = path.join(workspace, "target"); const target = path.join(workspace, "target");

View File

@ -35,7 +35,7 @@ async function run() {
await macOsWorkaround(); await macOsWorkaround();
const registryName = await getRegistryName(); const registryName = await getRegistryName();
const packages = await getPackages(); const packages = await getPackages(workspaces);
if (registryName) { if (registryName) {
try { try {