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

grouped packages propagate the change type based on ChangeType order #691

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
7 changes: 7 additions & 0 deletions change/beachball-84084dc1-705a-499a-bf96-644bc4222a6f.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "grouped packages propagate the change type based on ChangeType order, not change file load order.",
"packageName": "beachball",
"email": "[email protected]",
"dependentChangeType": "patch"
}
65 changes: 65 additions & 0 deletions src/__e2e__/bump.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,71 @@ describe('version bumping', () => {
expect(changeFiles.length).toBe(0);
});

it('bumps all grouped packages to the greatest change type in the group, regardless of change file order', async () => {
repositoryFactory = new RepositoryFactory();
repositoryFactory.create();
const repo = repositoryFactory.cloneRepository();

repo.commitChange(
'packages/commonlib/package.json',
JSON.stringify({
// We'll use the prefix z- here to make sure commonlib's change file is loaded AFTER
// its dependents.
// This makes sure we set the group's version bumps based on ChangeType order and not in
// the sort order the filesystem gives us.
name: 'z-commonlib',
version: '1.0.0',
})
);

repo.commitChange(
'packages/pkg-1/package.json',
JSON.stringify({
name: 'pkg-1',
version: '1.0.0',
dependencies: {
'z-commonlib': '1.0.0',
},
})
);

writeChangeFiles({
changes: [
{
type: 'none',
comment: 'just refactor stuff',
email: '[email protected]',
packageName: 'z-commonlib',
dependentChangeType: 'none',
},
{
type: 'minor',
comment: 'test',
email: '[email protected]',
packageName: 'pkg-1',
dependentChangeType: 'minor',
},
],
cwd: repo.rootPath,
});

git(['push', 'origin', 'master'], { cwd: repo.rootPath });

await bump({
path: repo.rootPath,
groups: [{ include: 'packages/*', name: 'grp' }],
bumpDeps: true,
} as BeachballOptions);

const packageInfos = getPackageInfos(repo.rootPath);

expect(packageInfos['pkg-1'].version).toBe('1.1.0');
expect(packageInfos['z-commonlib'].version).toBe('1.1.0');

const changeFiles = getChangeFiles(repo.rootPath);
expect(changeFiles.length).toBe(0);
});

it('should not bump out-of-scope package even if package has change', async () => {
repositoryFactory = new MonoRepoFactory();
repositoryFactory.create();
Expand Down
6 changes: 5 additions & 1 deletion src/bump/bumpInPlace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { bumpPackageInfoVersion } from './bumpPackageInfoVersion';
import { BeachballOptions } from '../types/BeachballOptions';
import { setGroupsInBumpInfo } from './setGroupsInBumpInfo';
import { setDependentVersions } from './setDependentVersions';
import { getMaxChangeType, MinChangeType } from '../changefile/getPackageChangeTypes';

/**
* Updates BumpInfo according to change types, bump deps, and version groups
Expand Down Expand Up @@ -33,8 +34,11 @@ export function bumpInPlace(bumpInfo: BumpInfo, options: BeachballOptions) {
);

if (groupName) {
const maxChangeTypeInGroup = bumpInfo.packageGroups[groupName].packageNames
.map(packageNameInGroup => calculatedChangeTypes[packageNameInGroup])
.reduce((prev, next) => getMaxChangeType(prev, next, null), MinChangeType);
for (const packageNameInGroup of bumpInfo.packageGroups[groupName].packageNames) {
calculatedChangeTypes[packageNameInGroup] = changeInfo.type;
calculatedChangeTypes[packageNameInGroup] = maxChangeTypeInGroup;
}
}
}
Expand Down