From 42c18eb1bc17935a2f909958b9068834bd2228fc Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 26 May 2021 20:00:01 -0400 Subject: [PATCH 1/2] Allow reverts when checking versions If a new version is lower than the current checked-in version, and the transition from the new version to the old version is valid (indicating that it could have been the previous version), allow the change. This prevents the version check from failing when reverting a PR. This is not fool-proof (e.g., it would allow a revert of an already-published PR); if we have issues in practice we can further restrict the check (by checking that the new version is the current pub version, for instance). --- .../tool/lib/src/version_check_command.dart | 14 ++++++++ script/tool/test/version_check_test.dart | 34 +++++++++++++++++++ 2 files changed, 48 insertions(+) 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/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'; From 77f0e1fa7006e49e69c3deeb08f7fdbb18df16c3 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Wed, 26 May 2021 20:05:38 -0400 Subject: [PATCH 2/2] Update version and changelog --- script/tool/CHANGELOG.md | 6 ++++++ script/tool/pubspec.yaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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/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