Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -6,6 +6,7 @@
federated packages that have been done in such a way that they will pass in
CI, but fail once the change is landed and published.
- `publish-check` now validates that there is an `AUTHORS` file.
- 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 @@ -348,8 +348,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 @@ -358,11 +359,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" '
Comment thread
stuartmorgan-g marked this conversation as resolved.
Outdated
'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 @@ -514,6 +514,73 @@ void main() {
);
});

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" '
Comment thread
ditman marked this conversation as resolved.
'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