Skip to content

Commit 2e5b150

Browse files
Merge pull request #4 from thomaseizinger/configurable-changelog-path
2 parents 67553fa + ed61da0 commit 2e5b150

File tree

7 files changed

+33
-9
lines changed

7 files changed

+33
-9
lines changed

__tests__/getGenesisHash.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ it("should return a hash", async function() {
44
const hash = await getGenesisHash();
55

66
expect(hash).toHaveLength(40);
7-
expect(hash).toMatch(/[a-f0-9]+/) // must be valid hex
7+
expect(hash).toMatch(/[a-f0-9]+/); // must be valid hex
88
});

__tests__/getInputs.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,22 @@ test("can handle ISO8601 date", function() {
4242

4343
expect(inputs).toHaveProperty("date", "2019-12-09");
4444
});
45+
46+
test("changelog path is optional but has a default", function() {
47+
const inputs = morph(getInputs, {
48+
INPUT_VERSION: "0.6.0",
49+
GITHUB_REPOSITORY: "foo/bar"
50+
});
51+
52+
expect(inputs).toHaveProperty("changelogPath", "./CHANGELOG.md");
53+
});
54+
55+
test("parse changelog path from input", function() {
56+
const inputs = morph(getInputs, {
57+
INPUT_VERSION: "0.6.0",
58+
GITHUB_REPOSITORY: "foo/bar",
59+
INPUT_CHANGELOGPATH: "./foo/bar/CHANGELOG.md"
60+
});
61+
62+
expect(inputs).toHaveProperty("changelogPath", "./foo/bar/CHANGELOG.md");
63+
});

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
date:
1212
description: 'The date of the release. Defaults to today at the execution time. Accepts any format that Date.parse will accept.'
1313
required: false
14+
changelogPath:
15+
description: 'The path to the changelog file. Defaults to `./CHANGELOG.md`'
16+
required: false
1417
runs:
1518
using: 'node12'
1619
main: 'dist/index.js'

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/getGenesisHash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default async function getGenesisHash(): Promise<string> {
1818
throw new Error("unable to parse genesis hash from git");
1919
}
2020

21-
const lines = genesisHash.split("\n")
21+
const lines = genesisHash.split("\n");
2222

2323
return lines[1];
2424
}

src/getInputs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface Inputs {
66
date: string;
77
owner: string;
88
repo: string;
9+
changelogPath: string;
910
}
1011

1112
export default function getInputs(): Inputs {
@@ -14,6 +15,7 @@ export default function getInputs(): Inputs {
1415
const date = formatDate(
1516
dateInput ? new Date(Date.parse(dateInput)) : new Date()
1617
);
18+
const changelogPath = getInput("changelogPath") || "./CHANGELOG.md";
1719
const githubRepository = process.env.GITHUB_REPOSITORY;
1820

1921
if (!githubRepository) {
@@ -26,6 +28,7 @@ export default function getInputs(): Inputs {
2628
version,
2729
date,
2830
owner,
29-
repo
31+
repo,
32+
changelogPath
3033
};
3134
}

src/updateChangelog.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import unified, { Transformer } from "unified";
22
import markdown from "remark-parse";
33
import stringify from "remark-stringify";
4-
import vFile, { VFile } from "vfile";
4+
import { VFile } from "vfile";
55
import { Node, Position } from "unist";
6-
import { version } from "punycode";
76

87
type MarkdownRootNode = {
98
type: "root";
@@ -81,7 +80,7 @@ function releaseTransformation({
8180
}: Options) {
8281
return transformer as Transformer;
8382

84-
function transformer(tree: MarkdownRootNode, file: VFile) {
83+
function transformer(tree: MarkdownRootNode, _file: VFile) {
8584
const previousVersion = determinePreviousVersion(tree);
8685
convertUnreleasedSectionToNewRelease(tree, version, releaseDate);
8786
addEmptyUnreleasedSection(tree);
@@ -98,7 +97,7 @@ function determinePreviousVersion(tree: MarkdownRootNode): string | null {
9897
node => node.type === "heading" && node.depth === 2
9998
);
10099

101-
let previousRelease = versions[1] as HeadingNode | undefined;
100+
const previousRelease = versions[1] as HeadingNode | undefined;
102101

103102
if (!previousRelease) {
104103
return null;
@@ -171,7 +170,7 @@ function convertUnreleasedSectionToNewRelease(
171170
},
172171
{
173172
type: "text",
174-
value: value
173+
value
175174
}
176175
];
177176

0 commit comments

Comments
 (0)