Skip to content

Commit

Permalink
Merge pull request #11 from h4sh3d/add-tag-argument
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Oct 12, 2021
2 parents 9f6c16b + 7e9f6cc commit 5bc2328
Show file tree
Hide file tree
Showing 19 changed files with 278 additions and 35 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- New optional `tag` argument allowing `v`-prefixed versions

### Changed

- The `version` argument is no longer required

### Deprecated

- The `version` argument will be replaced in favor of the `tag` argument

## [1.2.1] - 2021-02-23

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Update changelog
uses: thomaseizinger/keep-a-changelog-new-release@v1
with:
version: 0.6.0 # You probably want to have this dynamic :)
tag: v0.6.0 # You probably want to have this dynamic :)
```

The action will do nothing else apart from modifying the changelog.
Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/empty_release/fixture.ts
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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
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
@@ -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("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()
Expand All @@ -25,6 +44,7 @@ export default function getInputs(): Inputs {
const [owner, repo] = githubRepository.split("/");

return {
tag,
version,
date,
owner,
Expand Down

0 comments on commit 5bc2328

Please sign in to comment.