mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
'initial commit'
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user