'initial commit'

This commit is contained in:
mitchellhamilton
2019-09-16 17:18:53 +10:00
parent 8db2bfe48d
commit 2a6d43cef5
7 changed files with 154 additions and 52 deletions
+57
View File
@@ -3,6 +3,10 @@ import remarkParse from "remark-parse";
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 path from "path";
export const BumpLevels = {
dep: 0,
@@ -11,6 +15,33 @@ export const BumpLevels = {
major: 3
} as const;
export async function getChangedPackages(cwd: string) {
let workspaces = await getWorkspaces({
cwd,
tools: ["bolt", "yarn", "root"]
});
if (!workspaces) {
core.setFailed("Could not find workspaces");
return process.exit(1);
}
let workspacesByDirectory = new Map(workspaces.map(x => [x.dir, x]));
let output = await execWithOutput("git", ["diff", "--only-names"], { cwd });
let names = output.stdout.split("\n");
let changedWorkspaces: Workspace[] = [];
for (let name of names) {
let dirname = path.dirname(name);
let workspace = workspacesByDirectory.get(dirname);
if (workspace !== undefined) {
changedWorkspaces.push(workspace);
}
}
return changedWorkspaces;
}
export function getChangelogEntry(changelog: string, version: string) {
let ast = unified()
.use(remarkParse)
@@ -66,3 +97,29 @@ export function getChangelogEntry(changelog: string, version: string) {
highestLevel: highestLevel
};
}
export async function execWithOutput(
command: string,
args?: string[],
options?: { ignoreReturnCode?: boolean; cwd?: string }
) {
let myOutput = "";
let myError = "";
return {
code: await exec(command, args, {
listeners: {
stdout: (data: Buffer) => {
myOutput += data.toString();
},
stderr: (data: Buffer) => {
myError += data.toString();
}
},
...options
}),
stdout: myOutput,
stderr: myError
};
}