Skip to content

Commit 090ed5c

Browse files
Dillon Nysdnys1
authored andcommitted
fix(aft): Include/exclude for aft version-bump
1 parent abd6786 commit 090ed5c

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

packages/aft/lib/src/commands/version_bump_command.dart

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ class VersionBumpCommand extends AmplifyCommand
2929
help: 'Responds "yes" to all prompts',
3030
defaultsTo: false,
3131
negatable: false,
32+
)
33+
..addFlag(
34+
'force-breaking',
35+
help: 'Forces a major version bump',
36+
negatable: false,
37+
)
38+
..addFlag(
39+
'force-non-breaking',
40+
help: 'Forces a minor version bump',
41+
negatable: false,
42+
)
43+
..addFlag(
44+
'force-patch',
45+
help: 'Forces a patch version bump',
46+
negatable: false,
3247
);
3348
}
3449

@@ -43,6 +58,16 @@ class VersionBumpCommand extends AmplifyCommand
4358

4459
late final bool preview = argResults!['preview'] as bool;
4560

61+
late final VersionBumpType? forcedBumpType = () {
62+
final forceBreaking = argResults!['force-breaking'] as bool;
63+
if (forceBreaking) return VersionBumpType.breaking;
64+
final forceNonBreaking = argResults!['force-non-breaking'] as bool;
65+
if (forceNonBreaking) return VersionBumpType.nonBreaking;
66+
final forcePatch = argResults!['force-patch'] as bool;
67+
if (forcePatch) return VersionBumpType.patch;
68+
return null;
69+
}();
70+
4671
GitChanges _changesForPackage(PackageInfo package) {
4772
final baseRef = this.baseRef ?? repo.latestBumpRef(package);
4873
if (baseRef == null) {
@@ -56,12 +81,14 @@ class VersionBumpCommand extends AmplifyCommand
5681

5782
Future<List<PackageInfo>> _updateVersions() async {
5883
repo.bumpAllVersions(
84+
commandPackages,
5985
changesForPackage: _changesForPackage,
86+
forcedBumpType: forcedBumpType,
6087
);
6188
final changelogUpdates = repo.changelogUpdates;
6289

6390
final bumpedPackages = <PackageInfo>[];
64-
for (final package in commandPackages.values) {
91+
for (final package in repo.publishablePackages()) {
6592
final edits = package.pubspecInfo.pubspecYamlEditor.edits;
6693
if (edits.isNotEmpty) {
6794
bumpedPackages.add(package);
@@ -121,7 +148,7 @@ class VersionBumpCommand extends AmplifyCommand
121148
logger.info('Version successfully bumped');
122149
// Stage changes
123150
final publishableBumpedPackages =
124-
bumpedPackages.where((pkg) => pkg.isPublishable).toList();
151+
commandPackages.values.where((pkg) => pkg.isPublishable).toList();
125152
final mergedChangelog = Changelog.empty().makeVersionEntry(
126153
commits: {
127154
for (final package in publishableBumpedPackages)

packages/aft/lib/src/repo.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,17 @@ class Repo {
221221
final Map<PackageInfo, ChangelogUpdate> changelogUpdates = {};
222222

223223
/// Bumps the version for all packages in the repo.
224-
void bumpAllVersions({
224+
void bumpAllVersions(
225+
Map<String, PackageInfo> packages, {
225226
required GitChanges Function(PackageInfo) changesForPackage,
227+
VersionBumpType? forcedBumpType,
226228
}) {
227-
final sortedPackages = List.of(publishablePackages());
229+
final sortedPackages = List.of(publishablePackages(packages));
228230
sortPackagesTopologically(
229231
sortedPackages,
230232
(PackageInfo pkg) => pkg.pubspecInfo.pubspec,
231233
);
234+
bool canBump(PackageInfo package) => packages.containsKey(package.name);
232235
for (final package in sortedPackages) {
233236
final changes = changesForPackage(package);
234237
final commits = (changes.commitsByPackage[package]?.toList() ?? const [])
@@ -237,12 +240,13 @@ class Repo {
237240
if (commit.type == CommitType.version) {
238241
continue;
239242
}
240-
final bumpType = commit.bumpType;
243+
final bumpType = forcedBumpType ?? commit.bumpType;
241244
if (bumpType != null) {
242245
bumpVersion(
243246
package,
244247
commit: commit,
245248
type: bumpType,
249+
canBump: canBump,
246250
includeInChangelog: commit.includeInChangelog,
247251
);
248252
}
@@ -272,6 +276,7 @@ class Repo {
272276
PackageInfo package, {
273277
required CommitMessage commit,
274278
required VersionBumpType type,
279+
required bool Function(PackageInfo) canBump,
275280
required bool includeInChangelog,
276281
bool? propagateToComponent,
277282
}) {
@@ -344,11 +349,12 @@ class Repo {
344349
.contains(package.name),
345350
)) {
346351
logger.verbose('found dependent package ${dependent.name}');
347-
if (dependent.isPublishable) {
352+
if (dependent.isPublishable && canBump(dependent)) {
348353
bumpVersion(
349354
dependent,
350355
commit: commit,
351356
type: VersionBumpType.patch,
357+
canBump: canBump,
352358
includeInChangelog: false,
353359
);
354360
}
@@ -364,14 +370,17 @@ class Repo {
364370
return MapEntry(allPackages[name]!, dependents);
365371
}),
366372
(componentPackage) {
367-
if (componentPackage == package) return;
373+
if (componentPackage == package || !canBump(componentPackage)) {
374+
return;
375+
}
368376
logger.verbose(
369377
'Bumping component package ${componentPackage.name}',
370378
);
371379
bumpVersion(
372380
componentPackage,
373381
commit: commit,
374382
type: type,
383+
canBump: canBump,
375384
includeInChangelog: false,
376385
propagateToComponent: false,
377386
);

packages/aft/test/e2e_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ environment:
469469

470470
setUp(() async {
471471
repo.bumpAllVersions(
472+
repo.allPackages,
472473
changesForPackage: (pkg) => changesForPackage(
473474
pkg.name,
474475
baseRef: baseRef,

0 commit comments

Comments
 (0)