mirror of
https://github.com/Swatinem/rust-cache.git
synced 2025-08-15 05:05:09 +00:00
Update getPackages
This commit is contained in:
parent
b6a2848a50
commit
971fd2148b
@ -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
|
||||||
|
@ -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 = [];
|
||||||
|
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))
|
.filter((p) => !p.manifest_path.startsWith(cwd))
|
||||||
.map((p) => {
|
.map((p) => {
|
||||||
const targets = p.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name);
|
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) };
|
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) {
|
||||||
|
@ -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");
|
||||||
|
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user