Migrate away from deprecated get-workspaces (#34)

This commit is contained in:
Mateusz Burzyński
2020-06-22 08:17:36 +10:00
committed by GitHub
parent 6f5135b203
commit 6035d31341
5 changed files with 873 additions and 501 deletions
+7 -17
View File
@@ -4,8 +4,7 @@ import remarkStringify from "remark-stringify";
// @ts-ignore
import mdastToString from "mdast-util-to-string";
import { exec } from "@actions/exec";
import * as core from "@actions/core";
import getWorkspaces, { Workspace } from "get-workspaces";
import { getPackages, Package } from "@manypkg/get-packages";
import path from "path";
export const BumpLevels = {
@@ -16,31 +15,22 @@ export const BumpLevels = {
} as const;
export async function getChangedPackages(cwd: string) {
let workspaces = await getWorkspaces({
cwd,
tools: ["yarn", "bolt", "pnpm", "root"]
});
if (!workspaces) {
core.setFailed("Could not find workspaces");
return process.exit(1);
}
let workspacesByDirectory = new Map(workspaces.map(x => [x.dir, x]));
let { packages } = await getPackages(cwd);
let packagesByDirectory = new Map(packages.map(x => [x.dir, x]));
let output = await execWithOutput("git", ["diff", "--name-only"], { cwd });
let names = output.stdout.split("\n");
let changedWorkspaces = new Set<Workspace>();
let changedPackages = new Set<Package>();
for (let name of names) {
if (name === "") continue;
let dirname = path.resolve(cwd, path.dirname(name));
let workspace = workspacesByDirectory.get(dirname);
let workspace = packagesByDirectory.get(dirname);
if (workspace !== undefined) {
changedWorkspaces.add(workspace);
changedPackages.add(workspace);
}
}
return [...changedWorkspaces];
return [...changedPackages];
}
export function getChangelogEntry(changelog: string, version: string) {