mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Fix a bug with getting the highest bump type
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"presets": ["@babel/preset-env", "@babel/preset-typescript"]
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`it works 1`] = `
|
||||||
|
"### Major Changes
|
||||||
|
|
||||||
|
- [2164a779](https://github.com/keystonejs/keystone-5/commit/2164a779):
|
||||||
|
|
||||||
|
- Replace jade with pug because Jade was renamed to Pug, and \`jade\` package is outdated
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [81dc0be5](https://github.com/keystonejs/keystone-5/commit/81dc0be5):
|
||||||
|
|
||||||
|
- Update dependencies
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`it works 2`] = `
|
||||||
|
"### Patch Changes
|
||||||
|
|
||||||
|
- [19fe6c1b](https://github.com/keystonejs/keystone-5/commit/19fe6c1b):
|
||||||
|
|
||||||
|
Move frontmatter in docs into comments
|
||||||
|
"
|
||||||
|
`;
|
||||||
Vendored
+444
-434
File diff suppressed because one or more lines are too long
@@ -2,13 +2,9 @@ import * as core from "@actions/core";
|
|||||||
import { exec } from "@actions/exec";
|
import { exec } from "@actions/exec";
|
||||||
import * as github from "@actions/github";
|
import * as github from "@actions/github";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import unified from "unified";
|
|
||||||
import remarkParse from "remark-parse";
|
|
||||||
import remarkStringify from "remark-stringify";
|
|
||||||
// @ts-ignore
|
|
||||||
import mdastToString from "mdast-util-to-string";
|
|
||||||
import getWorkspaces, { Workspace } from "get-workspaces";
|
import getWorkspaces, { Workspace } from "get-workspaces";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { getChangelogEntry } from "./utils";
|
||||||
|
|
||||||
async function execWithOutput(
|
async function execWithOutput(
|
||||||
command: string,
|
command: string,
|
||||||
@@ -293,67 +289,3 @@ async function execWithOutput(
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
core.setFailed(err.message);
|
core.setFailed(err.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
enum BumpLevels {
|
|
||||||
dep = 0,
|
|
||||||
patch = 1,
|
|
||||||
minor = 2,
|
|
||||||
major = 3
|
|
||||||
}
|
|
||||||
|
|
||||||
function getChangelogEntry(changelog: string, version: string) {
|
|
||||||
let ast = unified()
|
|
||||||
.use(remarkParse)
|
|
||||||
.parse(changelog);
|
|
||||||
|
|
||||||
let highestLevel = BumpLevels.dep;
|
|
||||||
|
|
||||||
let nodes = ast.children as Array<any>;
|
|
||||||
let headingStartInfo:
|
|
||||||
| {
|
|
||||||
index: number;
|
|
||||||
depth: number;
|
|
||||||
}
|
|
||||||
| undefined;
|
|
||||||
let endIndex: number | undefined;
|
|
||||||
|
|
||||||
for (let i = 0; i < nodes.length; i++) {
|
|
||||||
let node = nodes[i];
|
|
||||||
if (node.type === "heading") {
|
|
||||||
let stringified: string = mdastToString(node);
|
|
||||||
let match = stringified.toLowerCase().match(/(major|minor|patch)/);
|
|
||||||
if (match !== null) {
|
|
||||||
let level = BumpLevels[match[0] as "major" | "minor" | "patch"];
|
|
||||||
highestLevel = Math.max(level, highestLevel);
|
|
||||||
}
|
|
||||||
if (headingStartInfo === undefined && stringified === version) {
|
|
||||||
headingStartInfo = {
|
|
||||||
index: i,
|
|
||||||
depth: node.depth
|
|
||||||
};
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
endIndex === undefined &&
|
|
||||||
headingStartInfo !== undefined &&
|
|
||||||
node.type === "heading" &&
|
|
||||||
headingStartInfo.depth === node.depth
|
|
||||||
) {
|
|
||||||
endIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (headingStartInfo) {
|
|
||||||
ast.children = (ast.children as any).slice(
|
|
||||||
headingStartInfo.index + 1,
|
|
||||||
endIndex
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
content: unified()
|
|
||||||
.use(remarkStringify)
|
|
||||||
.stringify(ast),
|
|
||||||
highestLevel: highestLevel
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -16,11 +16,17 @@
|
|||||||
"@actions/github": "^1.0.0",
|
"@actions/github": "^1.0.0",
|
||||||
"@actions/io": "^1.0.0",
|
"@actions/io": "^1.0.0",
|
||||||
"@actions/tool-cache": "^1.0.0",
|
"@actions/tool-cache": "^1.0.0",
|
||||||
|
"@babel/core": "^7.6.0",
|
||||||
|
"@babel/preset-env": "^7.6.0",
|
||||||
|
"@babel/preset-typescript": "^7.6.0",
|
||||||
"@types/fs-extra": "^8.0.0",
|
"@types/fs-extra": "^8.0.0",
|
||||||
|
"@types/jest": "^24.0.18",
|
||||||
"@types/node": "^12.7.1",
|
"@types/node": "^12.7.1",
|
||||||
|
"babel-jest": "^24.9.0",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
"get-workspaces": "^0.4.0",
|
"get-workspaces": "^0.4.0",
|
||||||
"husky": "^3.0.3",
|
"husky": "^3.0.3",
|
||||||
|
"jest": "^24.9.0",
|
||||||
"mdast-util-to-string": "^1.0.6",
|
"mdast-util-to-string": "^1.0.6",
|
||||||
"remark-parse": "^7.0.1",
|
"remark-parse": "^7.0.1",
|
||||||
"remark-stringify": "^7.0.3",
|
"remark-stringify": "^7.0.3",
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import { getChangelogEntry, BumpLevels } from "./utils";
|
||||||
|
|
||||||
|
let changelog = `# @keystone-alpha/email
|
||||||
|
|
||||||
|
## 3.0.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [19fe6c1b](https://github.com/keystonejs/keystone-5/commit/19fe6c1b):
|
||||||
|
|
||||||
|
Move frontmatter in docs into comments
|
||||||
|
|
||||||
|
## 3.0.0
|
||||||
|
|
||||||
|
### Major Changes
|
||||||
|
|
||||||
|
- [2164a779](https://github.com/keystonejs/keystone-5/commit/2164a779):
|
||||||
|
|
||||||
|
- Replace jade with pug because Jade was renamed to Pug, and \`jade\` package is outdated
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [81dc0be5](https://github.com/keystonejs/keystone-5/commit/81dc0be5):
|
||||||
|
|
||||||
|
- Update dependencies
|
||||||
|
|
||||||
|
## 2.0.0
|
||||||
|
|
||||||
|
- [patch][b69fb9b7](https://github.com/keystonejs/keystone-5/commit/b69fb9b7):
|
||||||
|
|
||||||
|
- Update dev devependencies
|
||||||
|
|
||||||
|
- [major][f97e4ecf](https://github.com/keystonejs/keystone-5/commit/f97e4ecf):
|
||||||
|
|
||||||
|
- Export { emailSender } as the API, rather than a default export
|
||||||
|
|
||||||
|
## 1.0.2
|
||||||
|
|
||||||
|
- [patch][7417ea3a](https://github.com/keystonejs/keystone-5/commit/7417ea3a):
|
||||||
|
|
||||||
|
- Update patch-level dependencies
|
||||||
|
|
||||||
|
## 1.0.1
|
||||||
|
|
||||||
|
- [patch][1f0bc236](https://github.com/keystonejs/keystone-5/commit/1f0bc236):
|
||||||
|
|
||||||
|
- Update the package.json author field to "The Keystone Development Team"
|
||||||
|
|
||||||
|
## 1.0.0
|
||||||
|
|
||||||
|
- [major] 8b6734ae:
|
||||||
|
|
||||||
|
- This is the first release of keystone-alpha (previously voussoir).
|
||||||
|
All packages in the \`@voussoir\` namespace are now available in the \`@keystone-alpha\` namespace, starting at version \`1.0.0\`.
|
||||||
|
To upgrade your project you must update any \`@voussoir/<foo>\` dependencies in \`package.json\` to point to \`@keystone-alpha/<foo>: "^1.0.0"\` and update any \`require\`/\`import\` statements in your code.
|
||||||
|
|
||||||
|
# @voussoir/email
|
||||||
|
|
||||||
|
## 0.0.2
|
||||||
|
|
||||||
|
- [patch] 113e16d4:
|
||||||
|
|
||||||
|
- Remove unused dependencies
|
||||||
|
|
||||||
|
- [patch] 625c1a6d:
|
||||||
|
|
||||||
|
- Update mjml-dependency
|
||||||
|
`;
|
||||||
|
|
||||||
|
test("it works", () => {
|
||||||
|
let entry = getChangelogEntry(changelog, "3.0.0");
|
||||||
|
expect(entry.content).toMatchSnapshot();
|
||||||
|
expect(entry.highestLevel).toBe(BumpLevels.major);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("it works", () => {
|
||||||
|
let entry = getChangelogEntry(changelog, "3.0.1");
|
||||||
|
expect(entry.content).toMatchSnapshot();
|
||||||
|
expect(entry.highestLevel).toBe(BumpLevels.patch);
|
||||||
|
});
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import unified from "unified";
|
||||||
|
import remarkParse from "remark-parse";
|
||||||
|
import remarkStringify from "remark-stringify";
|
||||||
|
// @ts-ignore
|
||||||
|
import mdastToString from "mdast-util-to-string";
|
||||||
|
|
||||||
|
export const BumpLevels = {
|
||||||
|
dep: 0,
|
||||||
|
patch: 1,
|
||||||
|
minor: 2,
|
||||||
|
major: 3
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export function getChangelogEntry(changelog: string, version: string) {
|
||||||
|
let ast = unified()
|
||||||
|
.use(remarkParse)
|
||||||
|
.parse(changelog);
|
||||||
|
|
||||||
|
let highestLevel: number = BumpLevels.dep;
|
||||||
|
|
||||||
|
let nodes = ast.children as Array<any>;
|
||||||
|
let headingStartInfo:
|
||||||
|
| {
|
||||||
|
index: number;
|
||||||
|
depth: number;
|
||||||
|
}
|
||||||
|
| undefined;
|
||||||
|
let endIndex: number | undefined;
|
||||||
|
|
||||||
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
|
let node = nodes[i];
|
||||||
|
if (node.type === "heading") {
|
||||||
|
let stringified: string = mdastToString(node);
|
||||||
|
let match = stringified.toLowerCase().match(/(major|minor|patch)/);
|
||||||
|
if (match !== null) {
|
||||||
|
let level = BumpLevels[match[0] as "major" | "minor" | "patch"];
|
||||||
|
highestLevel = Math.max(level, highestLevel);
|
||||||
|
}
|
||||||
|
if (headingStartInfo === undefined && stringified === version) {
|
||||||
|
headingStartInfo = {
|
||||||
|
index: i,
|
||||||
|
depth: node.depth
|
||||||
|
};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
endIndex === undefined &&
|
||||||
|
headingStartInfo !== undefined &&
|
||||||
|
headingStartInfo.depth === node.depth
|
||||||
|
) {
|
||||||
|
endIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (headingStartInfo) {
|
||||||
|
ast.children = (ast.children as any).slice(
|
||||||
|
headingStartInfo.index + 1,
|
||||||
|
endIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
content: unified()
|
||||||
|
.use(remarkStringify)
|
||||||
|
.stringify(ast),
|
||||||
|
highestLevel: highestLevel
|
||||||
|
};
|
||||||
|
}
|
||||||
+7552
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user