Skip to content

Commit

Permalink
New tag argument to control prefix of version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
h4sh3d committed Oct 5, 2021
1 parent 9f6c16b commit ea1c9cb
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 34 deletions.
1 change: 1 addition & 0 deletions __tests__/fixtures/empty_release/fixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
tag: '0.3.0',
version: '0.3.0',
date: '2019-12-06',
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',
Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/first_release/fixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
tag: '0.1.0',
version: '0.1.0',
date: '2020-02-15',
genesisHash: 'f29bb46e40c323fe0af44dda68c6f60e5b263c64',
Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/lowercase_link_reference/fixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
tag: '0.3.0',
version: "0.3.0",
date: "2019-12-06",
genesisHash: "1625533e04119e8496b14d5e18786f150b4fce4d",
Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/standard/fixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default {
tag: '0.3.0',
version: '0.3.0',
date: '2019-12-06',
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',
Expand Down
39 changes: 39 additions & 0 deletions __tests__/fixtures/tag_on_tag/CHANGELOG.expected.md
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions __tests__/fixtures/tag_on_tag/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions __tests__/fixtures/tag_on_tag/fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
tag: 'v0.3.0',
version: '0.3.0',
date: '2019-12-06',
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',
owner: 'foo',
repo: 'bar'
};
39 changes: 39 additions & 0 deletions __tests__/fixtures/tag_release/CHANGELOG.expected.md
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions __tests__/fixtures/tag_release/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions __tests__/fixtures/tag_release/fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
tag: 'v0.3.0',
version: '0.3.0',
date: '2019-12-06',
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',
owner: 'foo',
repo: 'bar'
};
45 changes: 38 additions & 7 deletions __tests__/getInputs.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
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("date is optional but has a default", function() {
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_TAG: "0.6.0",
GITHUB_REPOSITORY: "foo/bar"
});

expect(inputs).toHaveProperty("version", "0.6.0");
expect(inputs).toHaveProperty("date");
});

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"
});

Expand All @@ -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"
});

Expand All @@ -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"
});

Expand All @@ -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"
});

Expand All @@ -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"
});
Expand Down
4 changes: 3 additions & 1 deletion __tests__/updateChangelog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import updateChangelog from "../src/updateChangelog";
import { read, write } 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"])(
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`, {
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions src/getInputs.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
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;
repo: string;
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("No 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()
Expand All @@ -25,6 +44,7 @@ export default function getInputs(): Inputs {
const [owner, repo] = githubRepository.split("/");

return {
tag,
version,
date,
owner,
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ea1c9cb

Please sign in to comment.