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): do not add groups to commit message when their projects have no changes #27218

Merged
merged 1 commit into from
Jul 30, 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
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