Skip to content

Commit

Permalink
Merge pull request #4 from thomaseizinger/configurable-changelog-path
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger authored Sep 22, 2020
2 parents 67553fa + ed61da0 commit 2e5b150
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion __tests__/getGenesisHash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ it("should return a hash", async function() {
const hash = await getGenesisHash();

expect(hash).toHaveLength(40);
expect(hash).toMatch(/[a-f0-9]+/) // must be valid hex
expect(hash).toMatch(/[a-f0-9]+/); // must be valid hex
});
19 changes: 19 additions & 0 deletions __tests__/getInputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,22 @@ test("can handle ISO8601 date", function() {

expect(inputs).toHaveProperty("date", "2019-12-09");
});

test("changelog path is optional but has a default", function() {
const inputs = morph(getInputs, {
INPUT_VERSION: "0.6.0",
GITHUB_REPOSITORY: "foo/bar"
});

expect(inputs).toHaveProperty("changelogPath", "./CHANGELOG.md");
});

test("parse changelog path from input", function() {
const inputs = morph(getInputs, {
INPUT_VERSION: "0.6.0",
GITHUB_REPOSITORY: "foo/bar",
INPUT_CHANGELOGPATH: "./foo/bar/CHANGELOG.md"
});

expect(inputs).toHaveProperty("changelogPath", "./foo/bar/CHANGELOG.md");
});
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
date:
description: 'The date of the release. Defaults to today at the execution time. Accepts any format that Date.parse will accept.'
required: false
changelogPath:
description: 'The path to the changelog file. Defaults to `./CHANGELOG.md`'
required: false
runs:
using: 'node12'
main: 'dist/index.js'
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/getGenesisHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function getGenesisHash(): Promise<string> {
throw new Error("unable to parse genesis hash from git");
}

const lines = genesisHash.split("\n")
const lines = genesisHash.split("\n");

return lines[1];
}
5 changes: 4 additions & 1 deletion src/getInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ interface Inputs {
date: string;
owner: string;
repo: string;
changelogPath: string;
}

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

if (!githubRepository) {
Expand All @@ -26,6 +28,7 @@ export default function getInputs(): Inputs {
version,
date,
owner,
repo
repo,
changelogPath
};
}
9 changes: 4 additions & 5 deletions src/updateChangelog.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import unified, { Transformer } from "unified";
import markdown from "remark-parse";
import stringify from "remark-stringify";
import vFile, { VFile } from "vfile";
import { VFile } from "vfile";
import { Node, Position } from "unist";
import { version } from "punycode";

type MarkdownRootNode = {
type: "root";
Expand Down Expand Up @@ -81,7 +80,7 @@ function releaseTransformation({
}: Options) {
return transformer as Transformer;

function transformer(tree: MarkdownRootNode, file: VFile) {
function transformer(tree: MarkdownRootNode, _file: VFile) {
const previousVersion = determinePreviousVersion(tree);
convertUnreleasedSectionToNewRelease(tree, version, releaseDate);
addEmptyUnreleasedSection(tree);
Expand All @@ -98,7 +97,7 @@ function determinePreviousVersion(tree: MarkdownRootNode): string | null {
node => node.type === "heading" && node.depth === 2
);

let previousRelease = versions[1] as HeadingNode | undefined;
const previousRelease = versions[1] as HeadingNode | undefined;

if (!previousRelease) {
return null;
Expand Down Expand Up @@ -171,7 +170,7 @@ function convertUnreleasedSectionToNewRelease(
},
{
type: "text",
value: value
value
}
];

Expand Down

0 comments on commit 2e5b150

Please sign in to comment.