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

Allow reverts when checking versions #3981

Merged
merged 2 commits into from
May 27, 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
6 changes: 6 additions & 0 deletions script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.1.3

- Cosmetic fix to `publish-check` output
- Add a --dart-sdk option to `analyze`
- Allow reverts in `version-check`

## 0.1.2

- Add `against-pub` flag for version-check, which allows the command to check version with pub.
Expand Down
14 changes: 14 additions & 0 deletions script/tool/lib/src/version_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
continue;
}

// Check for reverts when doing local validation.
if (!getBoolArg(_againstPubFlag) && headVersion < sourceVersion) {
final Map<Version, NextVersionType> possibleVersionsFromNewVersion =
getAllowedNextVersions(headVersion, sourceVersion);
// Since this skips validation, try to ensure that it really is likely
// to be a revert rather than a typo by checking that the transition
// from the lower version to the new version would have been valid.
if (possibleVersionsFromNewVersion.containsKey(sourceVersion)) {
print('${indentation}New version is lower than previous version. '
'This is assumed to be a revert.');
continue;
}
}

final Map<Version, NextVersionType> allowedNextVersions =
getAllowedNextVersions(sourceVersion, headVersion);

Expand Down
2 changes: 1 addition & 1 deletion script/tool/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: flutter_plugin_tools
description: Productivity utils for flutter/plugins and flutter/packages
repository: https://github.com/flutter/plugins/tree/master/script/tool
version: 0.1.2
version: 0.1.3

dependencies:
args: ^2.1.0
Expand Down
34 changes: 34 additions & 0 deletions script/tool/test/version_check_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,40 @@ void main() {
);
});

test('allows likely reverts.', () async {
createFakePlugin('plugin', includeChangeLog: true, includeVersion: true);
gitDiffResponse = 'packages/plugin/pubspec.yaml';
gitShowResponses = <String, String>{
'abc123:packages/plugin/pubspec.yaml': 'version: 0.6.2',
'HEAD:packages/plugin/pubspec.yaml': 'version: 0.6.1',
};
final List<String> output =
await runCapturingPrint(runner, <String>['version-check']);

expect(
output,
containsAllInOrder(<String>[
'${indentation}New version is lower than previous version. This is assumed to be a revert.',
]),
);
});

test('denies lower version that could not be a simple revert', () async {
createFakePlugin('plugin', includeChangeLog: true, includeVersion: true);
gitDiffResponse = 'packages/plugin/pubspec.yaml';
gitShowResponses = <String, String>{
'abc123:packages/plugin/pubspec.yaml': 'version: 0.6.2',
'HEAD:packages/plugin/pubspec.yaml': 'version: 0.5.1',
};
final Future<List<String>> result =
runCapturingPrint(runner, <String>['version-check']);

await expectLater(
result,
throwsA(const TypeMatcher<ToolExit>()),
);
});

test('denies invalid version without explicit base-sha', () async {
createFakePlugin('plugin', includeChangeLog: true, includeVersion: true);
gitDiffResponse = 'packages/plugin/pubspec.yaml';
Expand Down