generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new `release-notes` output to the action containing the release notes for the newly released versions, allowing consumers to leverage it in their workflows (e.g. by passing it down to the GitHub Release API).
- Loading branch information
1 parent
64c61ea
commit 92915a2
Showing
11 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Added | ||
|
||
- Everything since the beginning! |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Changed | ||
|
||
- Our main theme is now blue instead of red. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Changed | ||
|
||
- Our main theme is now blue instead of red. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Changed | ||
|
||
- Our main theme is now blue instead of red. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import getReleaseNotes from "../src/getReleaseNotes"; | ||
import { read } from "to-vfile"; | ||
|
||
interface Fixture { | ||
tag: string; | ||
version: string; | ||
date: string; | ||
genesisHash: string; | ||
owner: string; | ||
repo: string; | ||
} | ||
|
||
it.each(["empty_release", "standard", "first_release", "lowercase_link_reference", "tag_release", "tag_on_tag"])( | ||
`should extract %s release-notes output`, | ||
async function(testcase) { | ||
const expectedChangelog = await read( | ||
`./__tests__/fixtures/${testcase}/CHANGELOG.expected.md`, | ||
{ | ||
encoding: "utf-8" | ||
} | ||
); | ||
const release: Fixture = await import( | ||
`./fixtures/${testcase}/fixture` | ||
).then(module => module.default); | ||
|
||
const expectedReleaseNotes = await read( | ||
`./__tests__/fixtures/${testcase}/release-notes.expected.md`, | ||
{ | ||
encoding: "utf-8" | ||
} | ||
).then(expected => expected.toString("utf-8")); | ||
const actualReleaseNotes = getReleaseNotes(expectedChangelog, release.version); | ||
expect(actualReleaseNotes).toEqual(expectedReleaseNotes); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import unified, { Transformer } from "unified"; | ||
import markdown from "remark-parse"; | ||
import stringify from "remark-stringify"; | ||
import { VFile } from "vfile"; | ||
import { Node } from "unist"; | ||
import { MarkdownRootNode } from "markdown-nodes"; | ||
|
||
function releaseNotesExtraction(version: string) { | ||
return transformer as unknown as Transformer; | ||
|
||
function transformer(tree: MarkdownRootNode, _file: VFile) { | ||
const children = tree.children; | ||
|
||
const firstNodeIndex = children.findIndex( | ||
node => node.type === "heading" && node.depth === 2 && | ||
node.children.length > 1 && node.children[0].type === "linkReference" && | ||
node.children[0].identifier === version | ||
) + 1; | ||
const firstNode = children.slice(firstNodeIndex); | ||
|
||
let lastNodeIndex = firstNode.findIndex( | ||
node => node.type === "heading" && node.depth === 2 | ||
); | ||
// special case: release notes for first release will not end with another | ||
// section, instead they end with the compare URLs | ||
if (lastNodeIndex === -1) { | ||
lastNodeIndex = firstNode.findIndex( | ||
node => node.type === "definition" && node.identifier === "unreleased" | ||
); | ||
} | ||
|
||
const releaseNotesNodes = firstNode.slice(0, lastNodeIndex); | ||
tree.children = releaseNotesNodes; | ||
return tree as Node; | ||
} | ||
} | ||
|
||
export default function getReleaseNotes( | ||
file: VFile, | ||
version: string | ||
): string { | ||
// @ts-ignore | ||
return unified() | ||
.use(markdown) | ||
.use(releaseNotesExtraction, version) | ||
.data("settings", { | ||
listItemIndent: "1", | ||
tightDefinitions: true, | ||
bullet: "-" | ||
}) | ||
.use(stringify) | ||
.processSync(file) | ||
.toString("utf-8") | ||
.trim(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters