Skip to content

Commit 5bc2328

Browse files
Merge pull request #11 from h4sh3d/add-tag-argument
2 parents 9f6c16b + 7e9f6cc commit 5bc2328

File tree

19 files changed

+278
-35
lines changed

19 files changed

+278
-35
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- New optional `tag` argument allowing `v`-prefixed versions
13+
14+
### Changed
15+
16+
- The `version` argument is no longer required
17+
18+
### Deprecated
19+
20+
- The `version` argument will be replaced in favor of the `tag` argument
21+
1022
## [1.2.1] - 2021-02-23
1123

1224
### Fixed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Update changelog
5454
uses: thomaseizinger/keep-a-changelog-new-release@v1
5555
with:
56-
version: 0.6.0 # You probably want to have this dynamic :)
56+
tag: v0.6.0 # You probably want to have this dynamic :)
5757
```
5858
5959
The action will do nothing else apart from modifying the changelog.

__tests__/fixtures/empty_release/fixture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
tag: '0.3.0',
23
version: '0.3.0',
34
date: '2019-12-06',
45
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',

__tests__/fixtures/first_release/fixture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
tag: '0.1.0',
23
version: '0.1.0',
34
date: '2020-02-15',
45
genesisHash: 'f29bb46e40c323fe0af44dda68c6f60e5b263c64',

__tests__/fixtures/lowercase_link_reference/fixture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
tag: '0.3.0',
23
version: "0.3.0",
34
date: "2019-12-06",
45
genesisHash: "1625533e04119e8496b14d5e18786f150b4fce4d",

__tests__/fixtures/standard/fixture.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default {
2+
tag: '0.3.0',
23
version: '0.3.0',
34
date: '2019-12-06',
45
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.3.0] - 2019-12-06
11+
12+
### Changed
13+
14+
- Our main theme is now blue instead of red.
15+
16+
## [0.2.0] - 2019-09-13
17+
18+
### Added
19+
20+
- First feature that is gonna make us money.
21+
- Quite a few bugs, sorry in advance!
22+
23+
### Changed
24+
25+
- Reworked the login system. You have to provide a password now!
26+
27+
## [0.1.0] - 2019-09-05
28+
29+
### Added
30+
31+
- Initial release :tada:
32+
33+
[Unreleased]: https://github.com/foo/bar/compare/v0.3.0...HEAD
34+
35+
[0.3.0]: https://github.com/foo/bar/compare/v0.2.0...v0.3.0
36+
37+
[0.2.0]: https://github.com/foo/bar/compare/0.1.0...v0.2.0
38+
39+
[0.1.0]: https://github.com/foo/bar/compare/1625533e04119e8496b14d5e18786f150b4fce4d...0.1.0
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Changed
11+
12+
- Our main theme is now blue instead of red.
13+
14+
## [0.2.0] - 2019-09-13
15+
16+
### Added
17+
18+
- First feature that is gonna make us money.
19+
- Quite a few bugs, sorry in advance!
20+
21+
### Changed
22+
23+
- Reworked the login system. You have to provide a password now!
24+
25+
## [0.1.0] - 2019-09-05
26+
27+
### Added
28+
29+
- Initial release :tada:
30+
31+
[Unreleased]: https://github.com/foo/bar/compare/v0.2.0...HEAD
32+
33+
[0.2.0]: https://github.com/foo/bar/compare/0.1.0...v0.2.0
34+
35+
[0.1.0]: https://github.com/foo/bar/compare/1625533e04119e8496b14d5e18786f150b4fce4d...0.1.0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
tag: 'v0.3.0',
3+
version: '0.3.0',
4+
date: '2019-12-06',
5+
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',
6+
owner: 'foo',
7+
repo: 'bar'
8+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.3.0] - 2019-12-06
11+
12+
### Changed
13+
14+
- Our main theme is now blue instead of red.
15+
16+
## [0.2.0] - 2019-09-13
17+
18+
### Added
19+
20+
- First feature that is gonna make us money.
21+
- Quite a few bugs, sorry in advance!
22+
23+
### Changed
24+
25+
- Reworked the login system. You have to provide a password now!
26+
27+
## [0.1.0] - 2019-09-05
28+
29+
### Added
30+
31+
- Initial release :tada:
32+
33+
[Unreleased]: https://github.com/foo/bar/compare/v0.3.0...HEAD
34+
35+
[0.3.0]: https://github.com/foo/bar/compare/0.2.0...v0.3.0
36+
37+
[0.2.0]: https://github.com/foo/bar/compare/0.1.0...0.2.0
38+
39+
[0.1.0]: https://github.com/foo/bar/compare/1625533e04119e8496b14d5e18786f150b4fce4d...0.1.0
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Changed
11+
12+
- Our main theme is now blue instead of red.
13+
14+
## [0.2.0] - 2019-09-13
15+
16+
### Added
17+
18+
- First feature that is gonna make us money.
19+
- Quite a few bugs, sorry in advance!
20+
21+
### Changed
22+
23+
- Reworked the login system. You have to provide a password now!
24+
25+
## [0.1.0] - 2019-09-05
26+
27+
### Added
28+
29+
- Initial release :tada:
30+
31+
[Unreleased]: https://github.com/foo/bar/compare/0.2.0...HEAD
32+
33+
[0.2.0]: https://github.com/foo/bar/compare/0.1.0...0.2.0
34+
35+
[0.1.0]: https://github.com/foo/bar/compare/1625533e04119e8496b14d5e18786f150b4fce4d...0.1.0
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
tag: 'v0.3.0',
3+
version: '0.3.0',
4+
date: '2019-12-06',
5+
genesisHash: '1625533e04119e8496b14d5e18786f150b4fce4d',
6+
owner: 'foo',
7+
repo: 'bar'
8+
};

__tests__/getInputs.test.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,54 @@
11
import { morph } from "mock-env";
22
import getInputs from "../src/getInputs";
33

4-
test("version is required", function() {
4+
test("version or tag is required", function() {
55
expect(() => morph(getInputs, { GITHUB_REPOSITORY: "foo/bar" })).toThrow();
66
});
77

8-
test("date is optional but has a default", function() {
8+
test("tag is used before version", function() {
9+
const inputs = morph(getInputs, {
10+
INPUT_TAG: "0.7.0",
11+
INPUT_VERSION: "0.6.0",
12+
GITHUB_REPOSITORY: "foo/bar"
13+
});
14+
15+
expect(inputs).toHaveProperty("tag", "0.7.0");
16+
expect(inputs).toHaveProperty("version", "0.7.0");
17+
});
18+
19+
test("version fallback works", function() {
920
const inputs = morph(getInputs, {
1021
INPUT_VERSION: "0.6.0",
1122
GITHUB_REPOSITORY: "foo/bar"
1223
});
1324

25+
expect(inputs).toHaveProperty("tag", "0.6.0");
26+
expect(inputs).toHaveProperty("version", "0.6.0");
27+
});
28+
29+
test("can parse prefixed tag", function() {
30+
const inputs = morph(getInputs, {
31+
INPUT_TAG: "v0.6.0",
32+
GITHUB_REPOSITORY: "foo/bar"
33+
});
34+
35+
expect(inputs).toHaveProperty("tag", "v0.6.0");
36+
expect(inputs).toHaveProperty("version", "0.6.0");
37+
});
38+
39+
test("date is optional but has a default", function() {
40+
const inputs = morph(getInputs, {
41+
INPUT_TAG: "0.6.0",
42+
GITHUB_REPOSITORY: "foo/bar"
43+
});
44+
1445
expect(inputs).toHaveProperty("version", "0.6.0");
1546
expect(inputs).toHaveProperty("date");
1647
});
1748

1849
test("parses date into ISO8601", function() {
1950
const inputs = morph(getInputs, {
20-
INPUT_VERSION: "0.6.0",
51+
INPUT_TAG: "0.6.0",
2152
INPUT_DATE: "Dec 09 2019"
2253
});
2354

@@ -26,7 +57,7 @@ test("parses date into ISO8601", function() {
2657

2758
test("parses GITHUB_REPOSITORY into owner and repo", function() {
2859
const inputs = morph(getInputs, {
29-
INPUT_VERSION: "0.6.0",
60+
INPUT_TAG: "0.6.0",
3061
GITHUB_REPOSITORY: "foo/bar"
3162
});
3263

@@ -36,7 +67,7 @@ test("parses GITHUB_REPOSITORY into owner and repo", function() {
3667

3768
test("can handle ISO8601 date", function() {
3869
const inputs = morph(getInputs, {
39-
INPUT_VERSION: "0.6.0",
70+
INPUT_TAG: "0.6.0",
4071
INPUT_DATE: "2019-12-09"
4172
});
4273

@@ -45,7 +76,7 @@ test("can handle ISO8601 date", function() {
4576

4677
test("changelog path is optional but has a default", function() {
4778
const inputs = morph(getInputs, {
48-
INPUT_VERSION: "0.6.0",
79+
INPUT_TAG: "0.6.0",
4980
GITHUB_REPOSITORY: "foo/bar"
5081
});
5182

@@ -54,7 +85,7 @@ test("changelog path is optional but has a default", function() {
5485

5586
test("parse changelog path from input", function() {
5687
const inputs = morph(getInputs, {
57-
INPUT_VERSION: "0.6.0",
88+
INPUT_TAG: "0.6.0",
5889
GITHUB_REPOSITORY: "foo/bar",
5990
INPUT_CHANGELOGPATH: "./foo/bar/CHANGELOG.md"
6091
});

__tests__/updateChangelog.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import updateChangelog from "../src/updateChangelog";
22
import { read, write } from "to-vfile";
33

44
interface Fixture {
5+
tag: string;
56
version: string;
67
date: string;
78
genesisHash: string;
89
owner: string;
910
repo: string;
1011
}
1112

12-
it.each(["empty_release", "standard", "first_release", "lowercase_link_reference"])(
13+
it.each(["empty_release", "standard", "first_release", "lowercase_link_reference", "tag_release", "tag_on_tag"])(
1314
`should update %s changelog`,
1415
async function(testcase) {
1516
const before = await read(`./__tests__/fixtures/${testcase}/CHANGELOG.md`, {
@@ -27,6 +28,7 @@ it.each(["empty_release", "standard", "first_release", "lowercase_link_reference
2728

2829
const actual = await updateChangelog(
2930
before,
31+
release.tag,
3032
release.version,
3133
release.date,
3234
release.genesisHash,

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ branding:
77
inputs:
88
version:
99
description: 'The version of the new release'
10-
required: true
10+
required: false
11+
tag:
12+
description: 'The tag that contains the version of the new release'
13+
required: false
1114
date:
1215
description: 'The date of the release. Defaults to today at the execution time. Accepts any format that Date.parse will accept.'
1316
required: false

dist/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/getInputs.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
11
import formatDate from "./formatDate";
2-
import { getInput } from "@actions/core/lib/core";
2+
import { getInput, warning } from "@actions/core/lib/core";
33

44
interface Inputs {
5+
tag: string;
56
version: string;
67
date: string;
78
owner: string;
89
repo: string;
910
changelogPath: string;
1011
}
1112

13+
function parseTagAndVersion(): [string, string] {
14+
const tagInput = getInput("tag");
15+
if (tagInput) {
16+
const version = tagInput.startsWith("v") ? tagInput.substring(1) : tagInput;
17+
return [tagInput, version];
18+
} else {
19+
const versionInput = getInput("version");
20+
21+
if (!versionInput) {
22+
throw new Error("Neither version nor tag specified");
23+
}
24+
25+
warning("Version argument will be deprecated soon, use tag instead.");
26+
return [versionInput, versionInput];
27+
}
28+
}
29+
1230
export default function getInputs(): Inputs {
13-
const version = getInput("version", { required: true });
31+
const [tag, version] = parseTagAndVersion();
32+
1433
const dateInput = getInput("date");
1534
const date = formatDate(
1635
dateInput ? new Date(Date.parse(dateInput)) : new Date()
@@ -25,6 +44,7 @@ export default function getInputs(): Inputs {
2544
const [owner, repo] = githubRepository.split("/");
2645

2746
return {
47+
tag,
2848
version,
2949
date,
3050
owner,

0 commit comments

Comments
 (0)