New tag argument to control prefix of version

Add an new input `tag` and remove `version` as required option to allow
smooth transition to the new `tag` argument later. If tag is set version
argument is ignored, if version argument is set a warning is emitted to
transition to tag and tag is set to its value.

Internally tag is added along version to differentiate the version
(strict semver) and the tag (potentially 'v' prefixed semver). If the
tag is prefixed, version is set as the non-prefixed tag value.
This commit is contained in:
h4sh3d 2021-10-05 17:47:28 +02:00
parent 9f6c16b8af
commit 576342e16c
No known key found for this signature in database
GPG Key ID: EDC803B0489692C3
17 changed files with 265 additions and 34 deletions

View File

@ -1,4 +1,5 @@
export default {
tag: '0.3.0',
version: '0.3.0',
date: '2019-12-06',
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',

View File

@ -1,4 +1,5 @@
export default {
tag: '0.1.0',
version: '0.1.0',
date: '2020-02-15',
genesisHash: 'f29bb46e40c323fe0af44dda68c6f60e5b263c64',

View File

@ -1,4 +1,5 @@
export default {
tag: '0.3.0',
version: "0.3.0",
date: "2019-12-06",
genesisHash: "1625533e04119e8496b14d5e18786f150b4fce4d",

View File

@ -1,4 +1,5 @@
export default {
tag: '0.3.0',
version: '0.3.0',
date: '2019-12-06',
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',

View File

@ -0,0 +1,39 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.3.0] - 2019-12-06
### Changed
- Our main theme is now blue instead of red.
## [0.2.0] - 2019-09-13
### Added
- First feature that is gonna make us money.
- Quite a few bugs, sorry in advance!
### Changed
- Reworked the login system. You have to provide a password now!
## [0.1.0] - 2019-09-05
### Added
- Initial release :tada:
[Unreleased]: https://github.com/foo/bar/compare/v0.3.0...HEAD
[0.3.0]: https://github.com/foo/bar/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/foo/bar/compare/0.1.0...v0.2.0
[0.1.0]: https://github.com/foo/bar/compare/1625533e04119e8496b14d5e18786f150b4fce4d...0.1.0

View File

@ -0,0 +1,35 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
- Our main theme is now blue instead of red.
## [0.2.0] - 2019-09-13
### Added
- First feature that is gonna make us money.
- Quite a few bugs, sorry in advance!
### Changed
- Reworked the login system. You have to provide a password now!
## [0.1.0] - 2019-09-05
### Added
- Initial release :tada:
[Unreleased]: https://github.com/foo/bar/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/foo/bar/compare/0.1.0...v0.2.0
[0.1.0]: https://github.com/foo/bar/compare/1625533e04119e8496b14d5e18786f150b4fce4d...0.1.0

View File

@ -0,0 +1,8 @@
export default {
tag: 'v0.3.0',
version: '0.3.0',
date: '2019-12-06',
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',
owner: 'foo',
repo: 'bar'
};

View File

@ -0,0 +1,39 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.3.0] - 2019-12-06
### Changed
- Our main theme is now blue instead of red.
## [0.2.0] - 2019-09-13
### Added
- First feature that is gonna make us money.
- Quite a few bugs, sorry in advance!
### Changed
- Reworked the login system. You have to provide a password now!
## [0.1.0] - 2019-09-05
### Added
- Initial release :tada:
[Unreleased]: https://github.com/foo/bar/compare/v0.3.0...HEAD
[0.3.0]: https://github.com/foo/bar/compare/0.2.0...v0.3.0
[0.2.0]: https://github.com/foo/bar/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/foo/bar/compare/1625533e04119e8496b14d5e18786f150b4fce4d...0.1.0

View File

@ -0,0 +1,35 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Changed
- Our main theme is now blue instead of red.
## [0.2.0] - 2019-09-13
### Added
- First feature that is gonna make us money.
- Quite a few bugs, sorry in advance!
### Changed
- Reworked the login system. You have to provide a password now!
## [0.1.0] - 2019-09-05
### Added
- Initial release :tada:
[Unreleased]: https://github.com/foo/bar/compare/0.2.0...HEAD
[0.2.0]: https://github.com/foo/bar/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/foo/bar/compare/1625533e04119e8496b14d5e18786f150b4fce4d...0.1.0

View File

@ -0,0 +1,8 @@
export default {
tag: 'v0.3.0',
version: '0.3.0',
date: '2019-12-06',
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',
owner: 'foo',
repo: 'bar'
};

View File

@ -1,13 +1,44 @@
import { morph } from "mock-env";
import getInputs from "../src/getInputs";
test("version is required", function() {
test("version or tag is required", function() {
expect(() => morph(getInputs, { GITHUB_REPOSITORY: "foo/bar" })).toThrow();
});
test("tag is used before version", function() {
const inputs = morph(getInputs, {
INPUT_TAG: "0.7.0",
INPUT_VERSION: "0.6.0",
GITHUB_REPOSITORY: "foo/bar"
});
expect(inputs).toHaveProperty("tag", "0.7.0");
expect(inputs).toHaveProperty("version", "0.7.0");
});
test("version fallback works", function() {
const inputs = morph(getInputs, {
INPUT_VERSION: "0.6.0",
GITHUB_REPOSITORY: "foo/bar"
});
expect(inputs).toHaveProperty("tag", "0.6.0");
expect(inputs).toHaveProperty("version", "0.6.0");
});
test("can parse prefixed tag", function() {
const inputs = morph(getInputs, {
INPUT_TAG: "v0.6.0",
GITHUB_REPOSITORY: "foo/bar"
});
expect(inputs).toHaveProperty("tag", "v0.6.0");
expect(inputs).toHaveProperty("version", "0.6.0");
});
test("date is optional but has a default", function() {
const inputs = morph(getInputs, {
INPUT_VERSION: "0.6.0",
INPUT_TAG: "0.6.0",
GITHUB_REPOSITORY: "foo/bar"
});
@ -17,7 +48,7 @@ test("date is optional but has a default", function() {
test("parses date into ISO8601", function() {
const inputs = morph(getInputs, {
INPUT_VERSION: "0.6.0",
INPUT_TAG: "0.6.0",
INPUT_DATE: "Dec 09 2019"
});
@ -26,7 +57,7 @@ test("parses date into ISO8601", function() {
test("parses GITHUB_REPOSITORY into owner and repo", function() {
const inputs = morph(getInputs, {
INPUT_VERSION: "0.6.0",
INPUT_TAG: "0.6.0",
GITHUB_REPOSITORY: "foo/bar"
});
@ -36,7 +67,7 @@ test("parses GITHUB_REPOSITORY into owner and repo", function() {
test("can handle ISO8601 date", function() {
const inputs = morph(getInputs, {
INPUT_VERSION: "0.6.0",
INPUT_TAG: "0.6.0",
INPUT_DATE: "2019-12-09"
});
@ -45,7 +76,7 @@ test("can handle ISO8601 date", function() {
test("changelog path is optional but has a default", function() {
const inputs = morph(getInputs, {
INPUT_VERSION: "0.6.0",
INPUT_TAG: "0.6.0",
GITHUB_REPOSITORY: "foo/bar"
});
@ -54,7 +85,7 @@ test("changelog path is optional but has a default", function() {
test("parse changelog path from input", function() {
const inputs = morph(getInputs, {
INPUT_VERSION: "0.6.0",
INPUT_TAG: "0.6.0",
GITHUB_REPOSITORY: "foo/bar",
INPUT_CHANGELOGPATH: "./foo/bar/CHANGELOG.md"
});

View File

@ -2,6 +2,7 @@ import updateChangelog from "../src/updateChangelog";
import { read, write } from "to-vfile";
interface Fixture {
tag: string;
version: string;
date: string;
genesisHash: string;
@ -9,7 +10,7 @@ interface Fixture {
repo: string;
}
it.each(["empty_release", "standard", "first_release", "lowercase_link_reference"])(
it.each(["empty_release", "standard", "first_release", "lowercase_link_reference", "tag_release", "tag_on_tag"])(
`should update %s changelog`,
async function(testcase) {
const before = await read(`./__tests__/fixtures/${testcase}/CHANGELOG.md`, {
@ -27,6 +28,7 @@ it.each(["empty_release", "standard", "first_release", "lowercase_link_reference
const actual = await updateChangelog(
before,
release.tag,
release.version,
release.date,
release.genesisHash,

View File

@ -7,7 +7,10 @@ branding:
inputs:
version:
description: 'The version of the new release'
required: true
required: false
tag:
description: 'The tag that contains the version of the new release'
required: false
date:
description: 'The date of the release. Defaults to today at the execution time. Accepts any format that Date.parse will accept.'
required: false

4
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,8 @@
import formatDate from "./formatDate";
import { getInput } from "@actions/core/lib/core";
import { getInput, warning } from "@actions/core/lib/core";
interface Inputs {
tag: string;
version: string;
date: string;
owner: string;
@ -9,8 +10,26 @@ interface Inputs {
changelogPath: string;
}
function parseTagAndVersion(): [string, string] {
const tagInput = getInput("tag");
if (tagInput) {
const version = tagInput.startsWith("v") ? tagInput.substring(1) : tagInput;
return [tagInput, version];
} else {
const versionInput = getInput("version");
if (!versionInput) {
throw new Error("Neither version nor tag specified");
}
warning("Version argument will be deprecated soon, use tag instead.");
return [versionInput, versionInput];
}
}
export default function getInputs(): Inputs {
const version = getInput("version", { required: true });
const [tag, version] = parseTagAndVersion();
const dateInput = getInput("date");
const date = formatDate(
dateInput ? new Date(Date.parse(dateInput)) : new Date()
@ -25,6 +44,7 @@ export default function getInputs(): Inputs {
const [owner, repo] = githubRepository.split("/");
return {
tag,
version,
date,
owner,

View File

@ -6,13 +6,14 @@ import getGenesisHash from "./getGenesisHash";
async function run(): Promise<void> {
try {
const { version, date, owner, repo, changelogPath } = getInputs();
const { tag, version, date, owner, repo, changelogPath } = getInputs();
const genesisHash = await getGenesisHash();
const changelog = await read(changelogPath, { encoding: "utf-8" });
const newChangelog = await updateChangelog(
changelog,
tag,
version,
date,
genesisHash,

View File

@ -64,6 +64,7 @@ type MarkdownNode =
| TextNode;
interface Options {
tag: string;
version: string;
releaseDate: string;
genesisHash: string;
@ -72,6 +73,7 @@ interface Options {
}
function releaseTransformation({
tag,
version,
releaseDate,
genesisHash,
@ -84,7 +86,15 @@ function releaseTransformation({
const previousVersion = determinePreviousVersion(tree);
convertUnreleasedSectionToNewRelease(tree, version, releaseDate);
addEmptyUnreleasedSection(tree);
updateCompareUrls(tree, version, previousVersion, genesisHash, owner, repo);
updateCompareUrls(
tree,
tag,
version,
previousVersion,
genesisHash,
owner,
repo
);
return tree as Node;
}
@ -94,32 +104,25 @@ function determinePreviousVersion(tree: MarkdownRootNode): string | null {
const children = tree.children;
const versions = children.filter(
node => node.type === "heading" && node.depth === 2
node => node.type === "definition"
);
const previousRelease = versions[1] as HeadingNode | undefined;
const previousRelease = versions[1] as DefinitionNode | undefined;
if (!previousRelease) {
return null;
}
const linkReference = previousRelease.children[0];
const link = previousRelease.url;
const split = link.split("...");
if (!linkReference || linkReference.type !== "linkReference") {
if (split.length !== 2) {
throw new Error(
"Invalid changelog format, previous version is not a link reference"
"Invalid changelog format, compare url is not standard"
);
}
const linkReferenceTextNode = linkReference.children[0];
if (!linkReferenceTextNode) {
throw new Error(
"Invalid changelog format, link reference does not have a text"
);
}
return linkReferenceTextNode.value;
return split[1];
}
function convertUnreleasedSectionToNewRelease(
@ -214,8 +217,9 @@ function addEmptyUnreleasedSection(tree: MarkdownRootNode) {
function updateCompareUrls(
tree: MarkdownRootNode,
newTag: string,
newVersion: string,
previousVersion: string | null,
previousTag: string | null,
genesisHash: string,
owner: string,
repo: string
@ -235,10 +239,10 @@ function updateCompareUrls(
? children.slice(unreleasedDefinitionIndex + 1)
: [];
const unreleasedCompareUrl = `https://github.com/${owner}/${repo}/compare/${newVersion}...HEAD`;
const previousVersionCompareUrl = previousVersion
? `https://github.com/${owner}/${repo}/compare/${previousVersion}...${newVersion}`
: `https://github.com/${owner}/${repo}/compare/${genesisHash}...${newVersion}`;
const unreleasedCompareUrl = `https://github.com/${owner}/${repo}/compare/${newTag}...HEAD`;
const previousVersionCompareUrl = previousTag
? `https://github.com/${owner}/${repo}/compare/${previousTag}...${newTag}`
: `https://github.com/${owner}/${repo}/compare/${genesisHash}...${newTag}`;
tree.children = [
...before,
@ -260,6 +264,7 @@ function updateCompareUrls(
export default async function updateChangelog(
file: VFile,
tag: string,
version: string,
releaseDate: string,
genesisHash: string,
@ -269,6 +274,7 @@ export default async function updateChangelog(
return await unified()
.use(markdown)
.use(releaseTransformation, {
tag,
version,
releaseDate,
genesisHash,