Skip to content

Commit ab5a8c0

Browse files
[tool] Allow importing packages with NEXT (#3215)
Fixes an issue that showed up in the trial repo merge PR; if a pacakge is new to the repository (i.e., has no git history in the parent commit), it was being treated as a version bump, which caused failures if NEXT was present. This adds a new state so that we can allow NEXT during import.
1 parent ce9c61b commit ab5a8c0

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

script/tool/lib/src/version_check_command.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ enum _CurrentVersionState {
4747
/// The version has changed, and the transition is invalid.
4848
invalidChange,
4949

50+
/// The package is new.
51+
newPackage,
52+
5053
/// There was an error determining the version state.
5154
unknown,
5255
}
@@ -216,6 +219,7 @@ class VersionCheckCommand extends PackageLoopingCommand {
216219
break;
217220
case _CurrentVersionState.validIncrease:
218221
case _CurrentVersionState.validRevert:
222+
case _CurrentVersionState.newPackage:
219223
versionChanged = true;
220224
break;
221225
case _CurrentVersionState.invalidChange:
@@ -318,7 +322,7 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
318322
'${getBoolArg(_againstPubFlag) ? 'on pub server' : 'at git base'}.');
319323
logWarning(
320324
'${indentation}If this package is not new, something has gone wrong.');
321-
return _CurrentVersionState.validIncrease; // Assume new, thus valid.
325+
return _CurrentVersionState.newPackage;
322326
}
323327

324328
if (previousVersion == currentVersion) {

script/tool/test/version_check_command_test.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ void main() {
525525
const String version = '1.0.1';
526526
final RepositoryPackage plugin =
527527
createFakePlugin('plugin', packagesDir, version: version);
528+
processRunner.mockProcessesForExecutable['git-show'] = <io.Process>[
529+
MockProcess(stdout: 'version: 1.0.0'),
530+
];
528531

529532
const String changelog = '''
530533
## NEXT
@@ -538,7 +541,7 @@ void main() {
538541

539542
bool hasError = false;
540543
final List<String> output = await runCapturingPrint(
541-
runner, <String>['version-check', '--base-sha=main', '--against-pub'],
544+
runner, <String>['version-check', '--base-sha=main'],
542545
errorHandler: (Error e) {
543546
expect(e, isA<ToolExit>());
544547
hasError = true;
@@ -559,6 +562,9 @@ void main() {
559562
test('fails if the version increases without replacing NEXT', () async {
560563
final RepositoryPackage plugin =
561564
createFakePlugin('plugin', packagesDir, version: '1.0.1');
565+
processRunner.mockProcessesForExecutable['git-show'] = <io.Process>[
566+
MockProcess(stdout: 'version: 1.0.0'),
567+
];
562568

563569
const String changelog = '''
564570
## NEXT
@@ -570,7 +576,7 @@ void main() {
570576

571577
bool hasError = false;
572578
final List<String> output = await runCapturingPrint(
573-
runner, <String>['version-check', '--base-sha=main', '--against-pub'],
579+
runner, <String>['version-check', '--base-sha=main'],
574580
errorHandler: (Error e) {
575581
expect(e, isA<ToolExit>());
576582
hasError = true;
@@ -613,6 +619,30 @@ void main() {
613619
);
614620
});
615621

622+
// This handles imports of a package with a NEXT section.
623+
test('allows NEXT for a new package', () async {
624+
final RepositoryPackage plugin =
625+
createFakePackage('a_package', packagesDir, version: '1.0.0');
626+
627+
const String changelog = '''
628+
## NEXT
629+
* Some changes that should be listed in the next release.
630+
## 1.0.0
631+
* Some other changes.
632+
''';
633+
plugin.changelogFile.writeAsStringSync(changelog);
634+
635+
final List<String> output = await runCapturingPrint(
636+
runner, <String>['version-check', '--base-sha=main']);
637+
expect(
638+
output,
639+
containsAllInOrder(<Matcher>[
640+
contains('Unable to find previous version at git base'),
641+
contains('Found NEXT; validating next version in the CHANGELOG'),
642+
]),
643+
);
644+
});
645+
616646
test(
617647
'fails gracefully if the version headers are not found due to using the wrong style',
618648
() async {

0 commit comments

Comments
 (0)