Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[flutter_plugin_tools] Improve version check error handling #4376

Merged
merged 4 commits into from
Sep 23, 2021
Merged
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
1 change: 1 addition & 0 deletions script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `publish-check` now validates that there is an `AUTHORS` file.
- Added flags to `version-check` to allow overriding the platform interface
major version change restriction.
- Improved error handling and error messages in CHANGELOG version checks.

## 0.7.1

Expand Down
23 changes: 16 additions & 7 deletions script/tool/lib/src/version_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,9 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
print(
'${indentation}Found NEXT; validating next version in the CHANGELOG.');
// Ensure that the version in pubspec hasn't changed without updating
// CHANGELOG. That means the next version entry in the CHANGELOG pass the
// normal validation.
// CHANGELOG. That means the next version entry in the CHANGELOG should
// pass the normal validation.
versionString = null;
while (iterator.moveNext()) {
if (iterator.current.trim().startsWith('## ')) {
versionString = iterator.current.trim().split(' ').last;
Expand All @@ -384,11 +385,19 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
}
}

final Version? fromChangeLog =
versionString == null ? null : Version.parse(versionString);
if (fromChangeLog == null) {
printError(
'${indentation}Cannot find version on the first line CHANGELOG.md');
if (versionString == null) {
printError('${indentation}Unable to find a version in CHANGELOG.md');
print('${indentation}The current version should be on a line starting '
'with "## ", either on the first non-empty line or after a "## NEXT" '
'section.');
return false;
}

final Version fromChangeLog;
try {
fromChangeLog = Version.parse(versionString);
} on FormatException {
printError('"$versionString" could not be parsed as a version.');
return false;
}

Expand Down
67 changes: 67 additions & 0 deletions script/tool/test/version_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,73 @@ This is necessary because of X, Y, and Z
);
});

test(
'fails gracefully if the version headers are not found due to using the wrong style',
() async {
final Directory pluginDirectory =
createFakePlugin('plugin', packagesDir, version: '1.0.0');

const String changelog = '''
## NEXT
* Some changes for a later release.
# 1.0.0
* Some other changes.
''';
createFakeCHANGELOG(pluginDirectory, changelog);
gitShowResponses = <String, String>{
'master:packages/plugin/pubspec.yaml': 'version: 1.0.0',
};

Error? commandError;
final List<String> output = await runCapturingPrint(runner, <String>[
'version-check',
'--base-sha=master',
], errorHandler: (Error e) {
commandError = e;
});

expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains('Unable to find a version in CHANGELOG.md'),
contains('The current version should be on a line starting with '
'"## ", either on the first non-empty line or after a "## NEXT" '
'section.'),
]),
);
});

test('fails gracefully if the version is unparseable', () async {
final Directory pluginDirectory =
createFakePlugin('plugin', packagesDir, version: '1.0.0');

const String changelog = '''
## Alpha
* Some changes.
''';
createFakeCHANGELOG(pluginDirectory, changelog);
gitShowResponses = <String, String>{
'master:packages/plugin/pubspec.yaml': 'version: 1.0.0',
};

Error? commandError;
final List<String> output = await runCapturingPrint(runner, <String>[
'version-check',
'--base-sha=master',
], errorHandler: (Error e) {
commandError = e;
});

expect(commandError, isA<ToolExit>());
expect(
output,
containsAllInOrder(<Matcher>[
contains('"Alpha" could not be parsed as a version.'),
]),
);
});

test('allows valid against pub', () async {
mockHttpResponse = <String, dynamic>{
'name': 'some_package',
Expand Down