Skip to content

fix(release): sort groups topologically bottom-up and fix typo to allow multi-level group dependencies #31374

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,118 @@ describe('Multiple Release Groups', () => {
});
});

describe('Three related groups, all fixed relationship, just JS', () => {
it('should correctly version projects across transitive group boundaries', async () => {
const {
nxReleaseConfig,
projectGraph,
releaseGroups,
releaseGroupToFilteredProjects,
filters,
} = await createNxReleaseConfigAndPopulateWorkspace(
tree,
`
group1 ({ "projectsRelationship": "fixed" }):
- pkg-a@1.0.0 [js]
-> depends on pkg-c
- pkg-b@1.0.0 [js]
group2 ({ "projectsRelationship": "fixed" }):
- pkg-c@2.0.0 [js]
-> depends on pkg-e
- pkg-d@2.0.0 [js]
group3 ({ "projectsRelationship": "fixed" }):
- pkg-e@3.0.0 [js]
- pkg-f@3.0.0 [js]
`,
{
version: {
conventionalCommits: true,
},
},
mockResolveCurrentVersion
);

mockDeriveSpecifierFromConventionalCommits.mockImplementation(
(_, __, ___, ____, { name: projectName }) => {
// pkg-e has a bump, which should cause pkg-f to bump because they are in a fixed group
// pkg-c depends on pkg-e so should also bump, and pkg-d is in a fixed group with pkg-c so should also bump
// pkg-a depends on pkg-c so should also bump, and pkg-b is in a fixed group with pkg-a so should also bump
if (projectName === 'pkg-e') return 'patch';
return 'none';
}
);

const processor = new ReleaseGroupProcessor(
tree,
projectGraph,
nxReleaseConfig,
releaseGroups,
releaseGroupToFilteredProjects,
{
dryRun: false,
verbose: false,
firstRelease: false,
preid: undefined,
filters,
}
);

await processor.init();
await processor.processGroups();

expect(mockResolveVersionActionsForProject).toHaveBeenCalledTimes(6);

expect(tree.read('pkg-a/package.json', 'utf-8')).toMatchInlineSnapshot(`
"{
"name": "pkg-a",
"version": "1.0.1",
"dependencies": {
"pkg-c": "2.0.1"
}
}
"
`);
expect(tree.read('pkg-b/package.json', 'utf-8')).toMatchInlineSnapshot(`
"{
"name": "pkg-b",
"version": "1.0.1"
}
"
`);
expect(tree.read('pkg-c/package.json', 'utf-8')).toMatchInlineSnapshot(`
"{
"name": "pkg-c",
"version": "2.0.1",
"dependencies": {
"pkg-e": "3.0.1"
}
}
"
`);
expect(tree.read('pkg-d/package.json', 'utf-8')).toMatchInlineSnapshot(`
"{
"name": "pkg-d",
"version": "2.0.1"
}
"
`);
expect(tree.read('pkg-e/package.json', 'utf-8')).toMatchInlineSnapshot(`
"{
"name": "pkg-e",
"version": "3.0.1"
}
"
`);
expect(tree.read('pkg-f/package.json', 'utf-8')).toMatchInlineSnapshot(`
"{
"name": "pkg-f",
"version": "3.0.1"
}
"
`);
});
});

describe('Two related groups, both independent relationship, just JS', () => {
const graphDefinition = `
group1 ({ "projectsRelationship": "independent" }):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ Valid values are: ${validReleaseVersionPrefixes

if (releaseGroup.projectsRelationship === 'fixed') {
// For fixed groups, we only need to check one project
const project = releaseGroupFilteredProjects[0];
const project = releaseGroupFilteredProjects.values().next().value;
const dependencies = this.projectGraph.dependencies[project] || [];
const hasDependencyInChangedGroup = dependencies.some(
(dep) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ describe('topologicalSort', () => {
const indexC = result.indexOf('C');
const indexD = result.indexOf('D');

expect(indexA).toBeLessThan(indexB); // A before B
expect(indexA).toBeLessThan(indexD); // A before D
expect(indexB).toBeLessThan(indexC); // B before C
expect(indexD).toBeLessThan(indexC); // D before C
expect(indexB).toBeLessThan(indexA); // B before A
expect(indexD).toBeLessThan(indexA); // D before A
expect(indexC).toBeLessThan(indexB); // C before B
expect(indexC).toBeLessThan(indexD); // C before D
});

it('should handle cycles by breaking them', () => {
Expand Down Expand Up @@ -149,8 +149,8 @@ describe('topologicalSort', () => {
const indexC = result.indexOf('C');
const indexD = result.indexOf('D');

expect(indexA).toBeLessThan(indexB); // A before B
expect(indexC).toBeLessThan(indexD); // C before D
expect(indexB).toBeLessThan(indexA); // B before A
expect(indexD).toBeLessThan(indexC); // D before C
});

it('should handle circular dependencies between two nodes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ export function topologicalSort<T>(
}
}

return result.reverse();
return result;
}
Loading