Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(release): allow version plans to have multi-line, arbitrarily formatted messages #27323

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 43 additions & 45 deletions e2e/release/src/version-plans.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('nx release version plans', () => {
await ensureDir(versionPlansDir);

runCLI(
'release plan minor -g fixed-group -m "feat: Update the fixed packages with a minor release." --verbose',
'release plan minor -g fixed-group -m "Update the fixed packages with a minor release." --verbose',
{
silenceError: true,
}
Expand All @@ -128,7 +128,9 @@ ${pkg4}: preminor
${pkg5}: prerelease
---

feat: Update the independent packages with a patch, preminor, and prerelease.
Update the independent packages with a patch, preminor, and prerelease.

Here is another line in the message.
`
);

Expand Down Expand Up @@ -193,9 +195,11 @@ feat: Update the independent packages with a patch, preminor, and prerelease.
+ ## 0.0.1 (YYYY-MM-DD)
+
+
+ ### 🚀 Features
+ ### 🩹 Fixes
+
+ - **${pkg3}:** Update the independent packages with a patch, preminor, and prerelease.
+
+ - Update the independent packages with a patch, preminor, and prerelease.`
+ Here is another line in the message.`
);

expect(resultWithoutDate).toContain(
Expand All @@ -207,7 +211,9 @@ feat: Update the independent packages with a patch, preminor, and prerelease.
+
+ ### 🚀 Features
+
+ - Update the independent packages with a patch, preminor, and prerelease.`
+ - **${pkg4}:** Update the independent packages with a patch, preminor, and prerelease.
+
+ Here is another line in the message.`
);

expect(resultWithoutDate).toContain(
Expand All @@ -217,9 +223,11 @@ feat: Update the independent packages with a patch, preminor, and prerelease.
+ ## 0.0.1-0 (YYYY-MM-DD)
+
+
+ ### 🚀 Features
+ ### 🩹 Fixes
+
+ - Update the independent packages with a patch, preminor, and prerelease.`
+ - **${pkg5}:** Update the independent packages with a patch, preminor, and prerelease.
+
+ Here is another line in the message.`
);

await writeFile(
Expand All @@ -229,7 +237,7 @@ ${pkg1}: minor
${pkg3}: patch
---

fix: Update packages in both groups with a bug fix
Update packages in both groups with a mix #1
`
);
await writeFile(
Expand All @@ -240,7 +248,7 @@ ${pkg4}: preminor
${pkg5}: patch
---

feat: Update packages in both groups with a feat
Update packages in both groups with a mix #2
`
);

Expand Down Expand Up @@ -291,12 +299,12 @@ feat: Update packages in both groups with a feat
+
+ ### 🚀 Features
+
+ - Update packages in both groups with a feat
+ - **${pkg1}:** Update packages in both groups with a mix #1
+
+
+ ### 🩹 Fixes
+
+ - Update packages in both groups with a bug fix`
+ - Update packages in both groups with a mix #2`
);
expect(result2WithoutDate).toContain(
`NX Generating an entry in ${pkg2}/CHANGELOG.md for v0.2.0
Expand All @@ -306,14 +314,9 @@ feat: Update packages in both groups with a feat
+ ## 0.2.0 (YYYY-MM-DD)
+
+
+ ### 🚀 Features
+
+ - Update packages in both groups with a feat
+
+
+ ### 🩹 Fixes
+
+ - Update packages in both groups with a bug fix
+ - Update packages in both groups with a mix #2
`
);
expect(result2WithoutDate).toContain(
Expand All @@ -326,7 +329,7 @@ feat: Update packages in both groups with a feat
+
+ ### 🩹 Fixes
+
+ - Update packages in both groups with a bug fix`
+ - **${pkg3}:** Update packages in both groups with a mix #1`
);

expect(result2WithoutDate).toContain(
Expand All @@ -339,7 +342,7 @@ feat: Update packages in both groups with a feat
+
+ ### 🚀 Features
+
+ - Update packages in both groups with a feat`
+ - **${pkg4}:** Update packages in both groups with a mix #2`
);

expect(result2WithoutDate).toContain(
Expand All @@ -350,9 +353,9 @@ feat: Update packages in both groups with a feat
+ ## 0.0.1 (YYYY-MM-DD)
+
+
+ ### 🚀 Features
+ ### 🩹 Fixes
+
+ - Update packages in both groups with a feat`
+ - **${pkg5}:** Update packages in both groups with a mix #2`
);

expect(exists(join(versionPlansDir, 'bump-mixed1.md'))).toBeFalsy();
Expand Down Expand Up @@ -394,7 +397,7 @@ feat: Update packages in both groups with a feat
fixed-group: minor
---

feat: Update the fixed packages with a minor release.
Update the fixed packages with a minor release.
`
);

Expand All @@ -406,7 +409,7 @@ ${pkg4}: preminor
${pkg5}: prerelease
---

feat: Update the independent packages with a patch, preminor, and prerelease.
Update the independent packages with a patch, preminor, and prerelease.
`
);

Expand Down Expand Up @@ -530,9 +533,9 @@ const yargs = require('yargs');
+ ## 0.0.1 (YYYY-MM-DD)
+
+
+ ### 🚀 Features
+ ### 🩹 Fixes
+
+ - Update the independent packages with a patch, preminor, and prerelease.`
+ - **${pkg3}:** Update the independent packages with a patch, preminor, and prerelease.`
);

expect(resultWithoutDate).toContain(
Expand All @@ -544,7 +547,7 @@ const yargs = require('yargs');
+
+ ### 🚀 Features
+
+ - Update the independent packages with a patch, preminor, and prerelease.`
+ - **${pkg4}:** Update the independent packages with a patch, preminor, and prerelease.`
);

expect(resultWithoutDate).toContain(
Expand All @@ -554,9 +557,9 @@ const yargs = require('yargs');
+ ## 0.0.1-0 (YYYY-MM-DD)
+
+
+ ### 🚀 Features
+ ### 🩹 Fixes
+
+ - Update the independent packages with a patch, preminor, and prerelease.`
+ - **${pkg5}:** Update the independent packages with a patch, preminor, and prerelease.`
);

expect(exists(join(versionPlansDir, 'bump-fixed.md'))).toBeFalsy();
Expand All @@ -569,8 +572,8 @@ ${pkg1}: minor
${pkg3}: patch
---

fix: Update packages in both groups with a bug fix
`
Update packages in both groups with a mix #1
`
);
await writeFile(
join(versionPlansDir, 'bump-mixed2.md'),
Expand All @@ -580,8 +583,8 @@ ${pkg4}: preminor
${pkg5}: patch
---

feat: Update packages in both groups with a feat
`
Update packages in both groups with a mix #2
`
);

await runCommandAsync(`git add ${join(versionPlansDir, 'bump-mixed1.md')}`);
Expand Down Expand Up @@ -631,12 +634,12 @@ feat: Update packages in both groups with a feat
+
+ ### 🚀 Features
+
+ - Update packages in both groups with a feat
+ - **${pkg1}:** Update packages in both groups with a mix #1
+
+
+ ### 🩹 Fixes
+
+ - Update packages in both groups with a bug fix`
+ - Update packages in both groups with a mix #2`
);
expect(result2WithoutDate).toContain(
`NX Generating an entry in ${pkg2}/CHANGELOG.md for v0.2.0
Expand All @@ -646,14 +649,9 @@ feat: Update packages in both groups with a feat
+ ## 0.2.0 (YYYY-MM-DD)
+
+
+ ### 🚀 Features
+
+ - Update packages in both groups with a feat
+
+
+ ### 🩹 Fixes
+
+ - Update packages in both groups with a bug fix
+ - Update packages in both groups with a mix #2
`
);
expect(result2WithoutDate).toContain(
Expand All @@ -666,7 +664,7 @@ feat: Update packages in both groups with a feat
+
+ ### 🩹 Fixes
+
+ - Update packages in both groups with a bug fix`
+ - **${pkg3}:** Update packages in both groups with a mix #1`
);

expect(result2WithoutDate).toContain(
Expand All @@ -679,7 +677,7 @@ feat: Update packages in both groups with a feat
+
+ ### 🚀 Features
+
+ - Update packages in both groups with a feat`
+ - **${pkg4}:** Update packages in both groups with a mix #2`
);

expect(result2WithoutDate).toContain(
Expand All @@ -690,9 +688,9 @@ feat: Update packages in both groups with a feat
+ ## 0.0.1 (YYYY-MM-DD)
+
+
+ ### 🚀 Features
+ ### 🩹 Fixes
+
+ - Update packages in both groups with a feat`
+ - **${pkg5}:** Update packages in both groups with a mix #2`
);

expect(exists(join(versionPlansDir, 'bump-mixed1.md'))).toBeFalsy();
Expand All @@ -715,7 +713,7 @@ feat: Update packages in both groups with a feat
await ensureDir(versionPlansDir);

runCLI(
'release plan minor -m "feat: Update the fixed packages with a minor release." --verbose',
'release plan minor -m "Update the fixed packages with a minor release." --verbose',
{
silenceError: true,
}
Expand Down
18 changes: 17 additions & 1 deletion packages/nx/release/changelog-renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,30 @@ function formatChange(
changelogRenderOptions: DefaultChangelogRenderOptions,
repoSlug?: RepoSlug
): string {
let description = change.description;
let extraLines = [];
let extraLinesStr = '';
if (description.includes('\n')) {
[description, ...extraLines] = description.split('\n');
// Align the extra lines with the start of the description for better readability
const indentation = ' ';
extraLinesStr = extraLines
.filter((l) => l.trim().length > 0)
.map((l) => `${indentation}${l}`)
.join('\n');
}

let changeLine =
'- ' +
(change.isBreaking ? '⚠️ ' : '') +
(change.scope ? `**${change.scope.trim()}:** ` : '') +
change.description;
description;
if (repoSlug && changelogRenderOptions.commitReferences) {
changeLine += formatReferences(change.githubReferences, repoSlug);
}
if (extraLinesStr) {
changeLine += '\n\n' + extraLinesStr;
}
return changeLine;
}

Expand Down
Loading