From 5b8a0da3c37d3c59d2d0ad954a842a6383f8c541 Mon Sep 17 00:00:00 2001 From: Tanner Lyons Date: Mon, 1 Aug 2022 14:15:43 -0700 Subject: [PATCH] grouped packages propagate the change type based on ChangeType order, not change file load order --- ...-84084dc1-705a-499a-bf96-644bc4222a6f.json | 7 ++ src/__e2e__/bump.test.ts | 65 +++++++++++++++++++ src/bump/bumpInPlace.ts | 6 +- 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 change/beachball-84084dc1-705a-499a-bf96-644bc4222a6f.json diff --git a/change/beachball-84084dc1-705a-499a-bf96-644bc4222a6f.json b/change/beachball-84084dc1-705a-499a-bf96-644bc4222a6f.json new file mode 100644 index 000000000..fd87e1c3b --- /dev/null +++ b/change/beachball-84084dc1-705a-499a-bf96-644bc4222a6f.json @@ -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": "tanner.m.lyons@gmail.com", + "dependentChangeType": "patch" +} diff --git a/src/__e2e__/bump.test.ts b/src/__e2e__/bump.test.ts index 12954b2fe..ac91a8ab4 100644 --- a/src/__e2e__/bump.test.ts +++ b/src/__e2e__/bump.test.ts @@ -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: 'test@test.com', + packageName: 'z-commonlib', + dependentChangeType: 'none', + }, + { + type: 'minor', + comment: 'test', + email: 'test@test.com', + 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(); diff --git a/src/bump/bumpInPlace.ts b/src/bump/bumpInPlace.ts index 3d686ddd0..02d31575d 100644 --- a/src/bump/bumpInPlace.ts +++ b/src/bump/bumpInPlace.ts @@ -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 @@ -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; } } }