From 59502a4b08902b190bb7d4df35aa070af5798807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CJamesHenry=E2=80=9D?= Date: Tue, 30 Jul 2024 23:33:33 +0400 Subject: [PATCH] fix(release): do not add groups to commit message when their projects have no changes --- .../command-line/release/utils/shared.spec.ts | 65 +++++++++++++++++++ .../src/command-line/release/utils/shared.ts | 17 ++--- 2 files changed, 74 insertions(+), 8 deletions(-) diff --git a/packages/nx/src/command-line/release/utils/shared.spec.ts b/packages/nx/src/command-line/release/utils/shared.spec.ts index 6d76eb23789ea..7d86b9d4a6ad5 100644 --- a/packages/nx/src/command-line/release/utils/shared.spec.ts +++ b/packages/nx/src/command-line/release/utils/shared.spec.ts @@ -70,6 +70,71 @@ describe('shared', () => { `); }); + it('should not add release groups to the commit message whose projects have no changes', () => { + const releaseGroups: ReleaseGroupWithName[] = [ + { + name: 'one', + projectsRelationship: 'independent', + projects: ['foo'], // single project, will get flattened in the final commit message + version: { + conventionalCommits: false, + generator: '@nx/js:version', + generatorOptions: {}, + }, + changelog: false, + releaseTagPattern: '{projectName}-{version}', + versionPlans: false, + }, + { + name: 'two', + projectsRelationship: 'fixed', + projects: ['bar', 'baz'], + version: { + conventionalCommits: false, + generator: '@nx/js:version', + generatorOptions: {}, + }, + changelog: false, + releaseTagPattern: '{projectName}-{version}', + versionPlans: false, + }, + ]; + const releaseGroupToFilteredProjects = new Map() + .set(releaseGroups[0], new Set(['foo'])) + .set(releaseGroups[1], new Set(['bar', 'baz'])); + const versionData = { + foo: { + currentVersion: '1.0.0', + dependentProjects: [], + newVersion: '1.0.1', + }, + bar: { + currentVersion: '1.0.0', + dependentProjects: [], + newVersion: null, // no changes + }, + baz: { + currentVersion: '1.0.0', + dependentProjects: [], + newVersion: null, // no changes + }, + }; + const userCommitMessage = + 'chore(release): publish {projectName} v{version}'; + const result = createCommitMessageValues( + releaseGroups, + releaseGroupToFilteredProjects, + versionData, + userCommitMessage + ); + expect(result).toMatchInlineSnapshot(` + [ + "chore(release): publish", + "- project: foo 1.0.1", + ] + `); + }); + it('should interpolate the {projectName} and {version} within the main commit message if a single project within a single independent release group is being committed', () => { const releaseGroups: ReleaseGroupWithName[] = [ { diff --git a/packages/nx/src/command-line/release/utils/shared.ts b/packages/nx/src/command-line/release/utils/shared.ts index 4ef8018f32969..f83327862072a 100644 --- a/packages/nx/src/command-line/release/utils/shared.ts +++ b/packages/nx/src/command-line/release/utils/shared.ts @@ -212,14 +212,15 @@ export function createCommitMessageValues( // One entry for the whole group for fixed groups const projectVersionData = versionData[releaseGroupProjectNames[0]]; // all at the same version, so we can just pick the first one - const releaseVersion = new ReleaseVersion({ - version: projectVersionData.newVersion, - releaseTagPattern: releaseGroup.releaseTagPattern, - }); - - commitMessageValues.push( - `- release-group: ${releaseGroup.name} ${releaseVersion.rawVersion}` - ); + if (projectVersionData.newVersion !== null) { + const releaseVersion = new ReleaseVersion({ + version: projectVersionData.newVersion, + releaseTagPattern: releaseGroup.releaseTagPattern, + }); + commitMessageValues.push( + `- release-group: ${releaseGroup.name} ${releaseVersion.rawVersion}` + ); + } } return commitMessageValues;