Skip to content

Commit

Permalink
fix: corrupt changelog for prefixed releases (projen#1661)
Browse files Browse the repository at this point in the history
When multiple version lines exist for a project, we use a [`releaseTagPrefix`](https://github.com/cdk8s-team/cdk8s-plus/blob/k8s-22/main/.projenrc.js#L50) property to distinguish between them. 

The problem was that this prefix wasn't being considered when generating the changelog, resulting in it simply accumulating commits, instead of doing proper diffs. 

> See https://github.com/cdk8s-team/cdk8s-plus/releases 

This PR fixes the issue by passing the `releaseTagPrefix` configuration down to `standard-version`, which generates the changelog. 

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
iliapolo authored Mar 16, 2022
1 parent 0b4aced commit 44bb912
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 3 deletions.
6 changes: 4 additions & 2 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/api/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2840,6 +2840,7 @@ new Version(project: Project, options: VersionOptions)
* **options** (<code>[VersionOptions](#projen-versionoptions)</code>) *No description*
* **artifactsDirectory** (<code>string</code>) The name of the directory into which `changelog.md` and `version.txt` files are emitted.
* **versionInputFile** (<code>string</code>) A name of a .json file to set the `version` field in after a bump.
* **tagPrefix** (<code>string</code>) The tag prefix corresponding to this version. __*Optional*__
* **versionrcOptions** (<code>Map<string, any></code>) Custom configuration for versionrc file used by standard-release. __*Optional*__


Expand Down Expand Up @@ -11481,6 +11482,7 @@ Name | Type | Description
-----|------|-------------
**artifactsDirectory**🔹 | <code>string</code> | The name of the directory into which `changelog.md` and `version.txt` files are emitted.
**versionInputFile**🔹 | <code>string</code> | A name of a .json file to set the `version` field in after a bump.
**tagPrefix**?🔹 | <code>string</code> | The tag prefix corresponding to this version.<br/>__*Optional*__
**versionrcOptions**?🔹 | <code>Map<string, any></code> | Custom configuration for versionrc file used by standard-release.<br/>__*Optional*__


Expand Down
3 changes: 3 additions & 0 deletions src/release/bump-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export async function bump(cwd: string, options: BumpOptions) {
if (isFirstRelease) {
cmd.push("--first-release");
}
if (prefix) {
cmd.push(`--tag-prefix ${prefix}v`);
}

exec(cmd.join(" "), { cwd });

Expand Down
1 change: 1 addition & 0 deletions src/release/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export class Release extends Component {
versionInputFile: this.versionFile,
artifactsDirectory: this.artifactsDirectory,
versionrcOptions: options.versionrcOptions,
tagPrefix: options.releaseTagPrefix,
});

this.publisher = new Publisher(project, {
Expand Down
6 changes: 6 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export interface VersionOptions {
* Custom configuration for versionrc file used by standard-release
*/
readonly versionrcOptions?: Record<string, any>;

/**
* The tag prefix corresponding to this version.
*/
readonly tagPrefix?: string;
}

export class Version extends Component {
Expand Down Expand Up @@ -80,6 +85,7 @@ export class Version extends Component {
CHANGELOG: changelogFile,
BUMPFILE: bumpFile,
RELEASETAG: releaseTagFile,
RELEASE_TAG_PREFIX: options.tagPrefix ?? "",
// doesn't work if custom configuration is long
VERSIONRCOPTIONS: JSON.stringify(options.versionrcOptions),
};
Expand Down
4 changes: 4 additions & 0 deletions test/__snapshots__/integ.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions test/release/__snapshots__/release.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion test/release/bump.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test("select latest, with prefix", async () => {
commits: [
{ message: "first version", tag: "prefix/v1.1.0" },
{ message: "unrelated version", tag: "v2.0.0" },
{ message: "second version", tag: "prefix/v1.2.0" },
{ message: "feat: feature 1", tag: "prefix/v1.2.0" },
{ message: "fix: bug" },
{ message: "fix: another bug" },
],
Expand All @@ -91,6 +91,7 @@ test("select latest, with prefix", async () => {
expect(result.changelog.includes("Bug Fixes")).toBeTruthy();
expect(result.changelog.includes("another bug")).toBeTruthy();
expect(result.changelog.includes("bug")).toBeTruthy();
expect(result.changelog.includes("feature 1")).toBeFalsy();
expect(result.bumpfile).toStrictEqual("1.2.1");
expect(result.tag).toStrictEqual("prefix/v1.2.1");
});
Expand Down
2 changes: 2 additions & 0 deletions test/web/__snapshots__/nextjs-project.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions test/web/__snapshots__/react-project.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 44bb912

Please sign in to comment.