diff --git a/script/tool/CHANGELOG.md b/script/tool/CHANGELOG.md index 79e2de01dead..d7e58dcfba5f 100644 --- a/script/tool/CHANGELOG.md +++ b/script/tool/CHANGELOG.md @@ -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. diff --git a/script/tool/lib/src/version_check_command.dart b/script/tool/lib/src/version_check_command.dart index a802c4d425ee..c095273a7721 100644 --- a/script/tool/lib/src/version_check_command.dart +++ b/script/tool/lib/src/version_check_command.dart @@ -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 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 allowedNextVersions = getAllowedNextVersions(sourceVersion, headVersion); diff --git a/script/tool/pubspec.yaml b/script/tool/pubspec.yaml index 13413b50b5dd..8ea735f2b675 100644 --- a/script/tool/pubspec.yaml +++ b/script/tool/pubspec.yaml @@ -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 diff --git a/script/tool/test/version_check_test.dart b/script/tool/test/version_check_test.dart index cef2ab1cfad3..536b885dd578 100644 --- a/script/tool/test/version_check_test.dart +++ b/script/tool/test/version_check_test.dart @@ -187,6 +187,40 @@ void main() { ); }); + test('allows likely reverts.', () async { + createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + gitDiffResponse = 'packages/plugin/pubspec.yaml'; + gitShowResponses = { + 'abc123:packages/plugin/pubspec.yaml': 'version: 0.6.2', + 'HEAD:packages/plugin/pubspec.yaml': 'version: 0.6.1', + }; + final List output = + await runCapturingPrint(runner, ['version-check']); + + expect( + output, + containsAllInOrder([ + '${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 = { + 'abc123:packages/plugin/pubspec.yaml': 'version: 0.6.2', + 'HEAD:packages/plugin/pubspec.yaml': 'version: 0.5.1', + }; + final Future> result = + runCapturingPrint(runner, ['version-check']); + + await expectLater( + result, + throwsA(const TypeMatcher()), + ); + }); + test('denies invalid version without explicit base-sha', () async { createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml';