Skip to content

Commit

Permalink
fix(release): do not add groups to commit message when their projects…
Browse files Browse the repository at this point in the history
… have no changes (#27218)

(cherry picked from commit 8c88968)
  • Loading branch information
JamesHenry authored and FrozenPandaz committed Jul 30, 2024
1 parent e5b1f38 commit f5fa7ec
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
65 changes: 65 additions & 0 deletions packages/nx/src/command-line/release/utils/shared.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
{
Expand Down
17 changes: 9 additions & 8 deletions packages/nx/src/command-line/release/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f5fa7ec

Please sign in to comment.