From a63a40bf66d828425f57c65eebbab472c92611c0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Feb 2021 12:52:58 -0800 Subject: [PATCH 1/5] publish check command --- script/tool/lib/src/main.dart | 2 + .../tool/lib/src/publish_check_command.dart | 95 +++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 script/tool/lib/src/publish_check_command.dart diff --git a/script/tool/lib/src/main.dart b/script/tool/lib/src/main.dart index bb3f67c0a9e1..fa81597237d7 100644 --- a/script/tool/lib/src/main.dart +++ b/script/tool/lib/src/main.dart @@ -7,6 +7,7 @@ import 'dart:io' as io; import 'package:args/command_runner.dart'; import 'package:file/file.dart'; import 'package:file/local.dart'; +import 'package:flutter_plugin_tools/src/publish_check_command.dart'; import 'package:flutter_plugin_tools/src/publish_plugin_command.dart'; import 'package:path/path.dart' as p; @@ -51,6 +52,7 @@ void main(List args) { ..addCommand(JavaTestCommand(packagesDir, fileSystem)) ..addCommand(LintPodspecsCommand(packagesDir, fileSystem)) ..addCommand(ListCommand(packagesDir, fileSystem)) + ..addCommand(PublishCheckCommand(packagesDir, fileSystem)) ..addCommand(PublishPluginCommand(packagesDir, fileSystem)) ..addCommand(TestCommand(packagesDir, fileSystem)) ..addCommand(VersionCheckCommand(packagesDir, fileSystem)) diff --git a/script/tool/lib/src/publish_check_command.dart b/script/tool/lib/src/publish_check_command.dart new file mode 100644 index 000000000000..417e7d406093 --- /dev/null +++ b/script/tool/lib/src/publish_check_command.dart @@ -0,0 +1,95 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:colorize/colorize.dart'; +import 'package:file/file.dart'; +import 'package:pubspec_parse/pubspec_parse.dart'; + +import 'common.dart'; + +class PublishCheckCommand extends PluginCommand { + PublishCheckCommand( + Directory packagesDir, + FileSystem fileSystem, { + ProcessRunner processRunner = const ProcessRunner(), + }) : super(packagesDir, fileSystem, processRunner: processRunner); + + @override + final String name = 'publish-check'; + + @override + final String description = + 'Checks to make sure that a plugin *could* be published.'; + + @override + Future run() async { + checkSharding(); + final List failedPackages = []; + + await for (Directory plugin in getPlugins()) { + if (!(await passesPublishCheck(plugin))) failedPackages.add(plugin); + } + + if (failedPackages.isNotEmpty) { + final String error = + 'FAIL: The following ${failedPackages.length} package(s) failed the ' + 'publishing check:'; + final String joinedFailedPackages = failedPackages.join('\n'); + + final Colorize colorizedError = Colorize('$error\n$joinedFailedPackages') + ..red(); + print(colorizedError); + throw ToolExit(64); + } + + final Colorize passedMessage = + Colorize('All packages passed publish check!')..green(); + print(passedMessage); + } + + Pubspec tryParsePubspec(Directory package) { + final File pubspecFile = package.childFile('pubspec.yaml'); + + Pubspec pubspec; + try { + pubspec = Pubspec.parse(pubspecFile.readAsStringSync()); + } on Exception catch (exception) { + print( + 'Failed to parse `pubspec.yaml` at ${pubspecFile.path}: $exception}', + ); + return null; + } + + return pubspec; + } + + Future passesPublishCheck(Directory package) async { + final String packageName = package.basename; + print('Checking that $packageName can be published.'); + + final Pubspec pubspec = tryParsePubspec(package); + if (pubspec == null) { + return false; + } else if (pubspec.publishTo == 'none') { + print('Package $packageName is marked as unpublishable. Skipping.'); + return true; + } + + final int exitCode = await processRunner.runAndStream( + 'flutter', + ['pub', 'publish', '--', '--dry-run'], + workingDir: package, + ); + + if (exitCode == 0) { + print("Package $packageName is able to be published."); + return true; + } else { + print('Unable to publish $packageName'); + return false; + } + } +} From 0efdcb38457b6a893248ea56072edd8deebcb354 Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Feb 2021 13:01:09 -0800 Subject: [PATCH 2/5] publish check --- packages/webview_flutter/pubspec.yaml | 2 +- script/check_publish.sh | 26 +------------------------- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index 5d8e512b5aa5..e55d4d737057 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: webview_flutter description: A Flutter plugin that provides a WebView widget on Android and iOS. -version: 2.0.0-nullsafety.5 +version: 2.0.0.0-nullsafety.5 homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter environment: diff --git a/script/check_publish.sh b/script/check_publish.sh index 5584fc601916..13e5b676b8f8 100755 --- a/script/check_publish.sh +++ b/script/check_publish.sh @@ -10,33 +10,9 @@ readonly REPO_DIR="$(dirname "$SCRIPT_DIR")" source "$SCRIPT_DIR/common.sh" -function check_publish() { - local failures=() - for dir in $(plugin_tools list --plugins="$1"); do - local package_name=$(basename "$dir") - - echo "Checking that $package_name can be published." - if [[ $(cd "$dir" && cat pubspec.yaml | grep -E "^publish_to: none") ]]; then - echo "Package $package_name is marked as unpublishable. Skipping." - elif (cd "$dir" && flutter pub publish -- --dry-run > /dev/null); then - echo "Package $package_name is able to be published." - else - error "Unable to publish $package_name" - failures=("${failures[@]}" "$package_name") - fi - done - if [[ "${#failures[@]}" != 0 ]]; then - error "FAIL: The following ${#failures[@]} package(s) failed the publishing check:" - for failure in "${failures[@]}"; do - error "$failure" - done - fi - return "${#failures[@]}" -} - # Sets CHANGED_PACKAGE_LIST and CHANGED_PACKAGES check_changed_packages if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then - check_publish "${CHANGED_PACKAGES}" + plugin_tools --plugins="${CHANGED_PACKAGES}" fi From d099ee267802840de80b4ac025b215cfa9c33a4f Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Feb 2021 13:04:35 -0800 Subject: [PATCH 3/5] run command --- script/check_publish.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/check_publish.sh b/script/check_publish.sh index 13e5b676b8f8..f0676964fa79 100755 --- a/script/check_publish.sh +++ b/script/check_publish.sh @@ -14,5 +14,5 @@ source "$SCRIPT_DIR/common.sh" check_changed_packages if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then - plugin_tools --plugins="${CHANGED_PACKAGES}" + plugin_tools publish_check --plugins="${CHANGED_PACKAGES}" fi From e6d02ec58b01b8bde5882fa67987c70f1764704e Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Feb 2021 13:07:42 -0800 Subject: [PATCH 4/5] fix command and pubspec --- packages/webview_flutter/pubspec.yaml | 2 +- script/check_publish.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/pubspec.yaml b/packages/webview_flutter/pubspec.yaml index e55d4d737057..5d8e512b5aa5 100644 --- a/packages/webview_flutter/pubspec.yaml +++ b/packages/webview_flutter/pubspec.yaml @@ -1,6 +1,6 @@ name: webview_flutter description: A Flutter plugin that provides a WebView widget on Android and iOS. -version: 2.0.0.0-nullsafety.5 +version: 2.0.0-nullsafety.5 homepage: https://github.com/flutter/plugins/tree/master/packages/webview_flutter environment: diff --git a/script/check_publish.sh b/script/check_publish.sh index f0676964fa79..c92de4be2e08 100755 --- a/script/check_publish.sh +++ b/script/check_publish.sh @@ -14,5 +14,5 @@ source "$SCRIPT_DIR/common.sh" check_changed_packages if [[ "${#CHANGED_PACKAGE_LIST[@]}" != 0 ]]; then - plugin_tools publish_check --plugins="${CHANGED_PACKAGES}" + plugin_tools publish-check --plugins="${CHANGED_PACKAGES}" fi From 4d0f7fbcca4807901af5c006b6883492d600c67b Mon Sep 17 00:00:00 2001 From: Maurice Parrish Date: Tue, 16 Feb 2021 14:25:37 -0800 Subject: [PATCH 5/5] set tool exit to 1 and return pubspec --- script/tool/lib/src/publish_check_command.dart | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/script/tool/lib/src/publish_check_command.dart b/script/tool/lib/src/publish_check_command.dart index 417e7d406093..8d6f6bb9ab61 100644 --- a/script/tool/lib/src/publish_check_command.dart +++ b/script/tool/lib/src/publish_check_command.dart @@ -42,7 +42,7 @@ class PublishCheckCommand extends PluginCommand { final Colorize colorizedError = Colorize('$error\n$joinedFailedPackages') ..red(); print(colorizedError); - throw ToolExit(64); + throw ToolExit(1); } final Colorize passedMessage = @@ -53,17 +53,14 @@ class PublishCheckCommand extends PluginCommand { Pubspec tryParsePubspec(Directory package) { final File pubspecFile = package.childFile('pubspec.yaml'); - Pubspec pubspec; try { - pubspec = Pubspec.parse(pubspecFile.readAsStringSync()); + return Pubspec.parse(pubspecFile.readAsStringSync()); } on Exception catch (exception) { print( 'Failed to parse `pubspec.yaml` at ${pubspecFile.path}: $exception}', ); return null; } - - return pubspec; } Future passesPublishCheck(Directory package) async {