From 79ed52f5c4324a8a03c0c31c592b955d8c6ee695 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 21 Apr 2021 15:41:46 -0700 Subject: [PATCH 1/4] fix version check for new packages --- script/tool/lib/src/common.dart | 1 + .../tool/lib/src/version_check_command.dart | 6 ++++-- script/tool/test/version_check_test.dart | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/script/tool/lib/src/common.dart b/script/tool/lib/src/common.dart index d8826c793088..d02626ff757e 100644 --- a/script/tool/lib/src/common.dart +++ b/script/tool/lib/src/common.dart @@ -609,6 +609,7 @@ class GitVersionFinder { return null; } final String fileContent = gitShow.stdout as String; + print('xx $fileContent'); final String versionString = loadYaml(fileContent)['version'] as String; return versionString == null ? null : Version.parse(versionString); } diff --git a/script/tool/lib/src/version_check_command.dart b/script/tool/lib/src/version_check_command.dart index 14dc8fb28ef8..485900ebfae8 100644 --- a/script/tool/lib/src/version_check_command.dart +++ b/script/tool/lib/src/version_check_command.dart @@ -3,7 +3,6 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:io' as io; import 'package:meta/meta.dart'; import 'package:file/file.dart'; @@ -116,11 +115,14 @@ class VersionCheckCommand extends PluginCommand { 'intentionally has no version should be marked ' '"publish_to: none".'); } - final Version masterVersion = + Version masterVersion = await gitVersionFinder.getPackageVersion(pubspecPath); if (masterVersion == null) { + // If no masterVersion, set it to 0.0.0 so new package can calculate valid versions. + masterVersion = Version.none; print('${indentation}Unable to find pubspec in master. ' 'Safe to ignore if the project is new.'); + print(masterVersion); } if (masterVersion == headVersion) { diff --git a/script/tool/test/version_check_test.dart b/script/tool/test/version_check_test.dart index ed953e0b7fa4..04348310a2f6 100644 --- a/script/tool/test/version_check_test.dart +++ b/script/tool/test/version_check_test.dart @@ -61,6 +61,9 @@ void main() { } else if (invocation.positionalArguments[0][0] == 'show') { final String response = gitShowResponses[invocation.positionalArguments[0][1]]; + if (response == null) { + throw const io.ProcessException('git', ['show']); + } when(mockProcessResult.stdout as String).thenReturn(response); } else if (invocation.positionalArguments[0][0] == 'merge-base') { when(mockProcessResult.stdout as String).thenReturn('abc123'); @@ -150,6 +153,23 @@ void main() { ); }); + test('allows valid version for new package.', () async { + createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); + gitDiffResponse = 'packages/plugin/pubspec.yaml'; + gitShowResponses = { + 'HEAD:packages/plugin/pubspec.yaml': 'version: 1.0.0', + }; + final List output = + await runCapturingPrint(runner, ['version-check']); + + expect( + output, + containsAllInOrder([ + 'No version check errors found!', + ]), + ); + }); + test('denies invalid version without explicit base-sha', () async { createFakePlugin('plugin', includeChangeLog: true, includeVersion: true); gitDiffResponse = 'packages/plugin/pubspec.yaml'; From 8c5ca69d39eccddabbdf26a677f8e6e41ffcac5b Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 21 Apr 2021 15:44:45 -0700 Subject: [PATCH 2/4] cleanup --- script/tool/lib/src/common.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/script/tool/lib/src/common.dart b/script/tool/lib/src/common.dart index d02626ff757e..d8826c793088 100644 --- a/script/tool/lib/src/common.dart +++ b/script/tool/lib/src/common.dart @@ -609,7 +609,6 @@ class GitVersionFinder { return null; } final String fileContent = gitShow.stdout as String; - print('xx $fileContent'); final String versionString = loadYaml(fileContent)['version'] as String; return versionString == null ? null : Version.parse(versionString); } From b1e6ac01c4a7f7298bc3ef2d2a2c76aee9323b23 Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 21 Apr 2021 15:45:45 -0700 Subject: [PATCH 3/4] cleanup --- script/tool/lib/src/version_check_command.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/script/tool/lib/src/version_check_command.dart b/script/tool/lib/src/version_check_command.dart index 485900ebfae8..95c10a3a3b89 100644 --- a/script/tool/lib/src/version_check_command.dart +++ b/script/tool/lib/src/version_check_command.dart @@ -122,7 +122,6 @@ class VersionCheckCommand extends PluginCommand { masterVersion = Version.none; print('${indentation}Unable to find pubspec in master. ' 'Safe to ignore if the project is new.'); - print(masterVersion); } if (masterVersion == headVersion) { From 90adda4b1fcf397d4170c09e9bf849d33ff5710d Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Wed, 21 Apr 2021 15:50:23 -0700 Subject: [PATCH 4/4] just skip version check --- script/tool/lib/src/version_check_command.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/script/tool/lib/src/version_check_command.dart b/script/tool/lib/src/version_check_command.dart index 95c10a3a3b89..0b552e8bff4d 100644 --- a/script/tool/lib/src/version_check_command.dart +++ b/script/tool/lib/src/version_check_command.dart @@ -115,13 +115,12 @@ class VersionCheckCommand extends PluginCommand { 'intentionally has no version should be marked ' '"publish_to: none".'); } - Version masterVersion = + final Version masterVersion = await gitVersionFinder.getPackageVersion(pubspecPath); if (masterVersion == null) { - // If no masterVersion, set it to 0.0.0 so new package can calculate valid versions. - masterVersion = Version.none; print('${indentation}Unable to find pubspec in master. ' 'Safe to ignore if the project is new.'); + continue; } if (masterVersion == headVersion) {