mirror of
https://github.com/flutter/packages.git
synced 2025-06-09 14:19:08 +08:00
[flutter_plugin_tools] Migrate publish and version checks to NNBD (#4037)
Migrates publish-check and version-check commands to NNBD. Reworks the version-check flow so that it's more consistent with the other commands: instead of immediately exiting on failure, it checks all plugins, gathers failures, and summarizes all failures at the end. This ensures that we don't have failures in one package temporarily masked by failures in another, so PRs don't need to go through as many check cycles. Part of https://github.com/flutter/flutter/issues/81912
This commit is contained in:
@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io' as io;
|
||||
@ -11,7 +9,6 @@ import 'dart:io' as io;
|
||||
import 'package:colorize/colorize.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:pub_semver/pub_semver.dart';
|
||||
import 'package:pubspec_parse/pubspec_parse.dart';
|
||||
|
||||
@ -23,7 +20,7 @@ class PublishCheckCommand extends PluginCommand {
|
||||
PublishCheckCommand(
|
||||
Directory packagesDir, {
|
||||
ProcessRunner processRunner = const ProcessRunner(),
|
||||
this.httpClient,
|
||||
http.Client? httpClient,
|
||||
}) : _pubVersionFinder =
|
||||
PubVersionFinder(httpClient: httpClient ?? http.Client()),
|
||||
super(packagesDir, processRunner: processRunner) {
|
||||
@ -65,9 +62,6 @@ class PublishCheckCommand extends PluginCommand {
|
||||
final String description =
|
||||
'Checks to make sure that a plugin *could* be published.';
|
||||
|
||||
/// The custom http client used to query versions on pub.
|
||||
final http.Client httpClient;
|
||||
|
||||
final PubVersionFinder _pubVersionFinder;
|
||||
|
||||
// The output JSON when the _machineFlag is on.
|
||||
@ -135,7 +129,7 @@ class PublishCheckCommand extends PluginCommand {
|
||||
}
|
||||
}
|
||||
|
||||
Pubspec _tryParsePubspec(Directory package) {
|
||||
Pubspec? _tryParsePubspec(Directory package) {
|
||||
final File pubspecFile = package.childFile('pubspec.yaml');
|
||||
|
||||
try {
|
||||
@ -205,7 +199,7 @@ class PublishCheckCommand extends PluginCommand {
|
||||
final String packageName = package.basename;
|
||||
print('Checking that $packageName can be published.');
|
||||
|
||||
final Pubspec pubspec = _tryParsePubspec(package);
|
||||
final Pubspec? pubspec = _tryParsePubspec(package);
|
||||
if (pubspec == null) {
|
||||
print('no pubspec');
|
||||
return _PublishCheckResult._error;
|
||||
@ -214,7 +208,7 @@ class PublishCheckCommand extends PluginCommand {
|
||||
return _PublishCheckResult._published;
|
||||
}
|
||||
|
||||
final Version version = pubspec.version;
|
||||
final Version? version = pubspec.version;
|
||||
final _PublishCheckResult alreadyPublishedResult =
|
||||
await _checkIfAlreadyPublished(
|
||||
packageName: packageName, version: version);
|
||||
@ -238,29 +232,24 @@ class PublishCheckCommand extends PluginCommand {
|
||||
|
||||
// Check if `packageName` already has `version` published on pub.
|
||||
Future<_PublishCheckResult> _checkIfAlreadyPublished(
|
||||
{String packageName, Version version}) async {
|
||||
{required String packageName, required Version? version}) async {
|
||||
final PubVersionFinderResponse pubVersionFinderResponse =
|
||||
await _pubVersionFinder.getPackageVersion(package: packageName);
|
||||
_PublishCheckResult result;
|
||||
switch (pubVersionFinderResponse.result) {
|
||||
case PubVersionFinderResult.success:
|
||||
result = pubVersionFinderResponse.versions.contains(version)
|
||||
return pubVersionFinderResponse.versions.contains(version)
|
||||
? _PublishCheckResult._published
|
||||
: _PublishCheckResult._notPublished;
|
||||
break;
|
||||
case PubVersionFinderResult.fail:
|
||||
print('''
|
||||
Error fetching version on pub for $packageName.
|
||||
HTTP Status ${pubVersionFinderResponse.httpResponse.statusCode}
|
||||
HTTP response: ${pubVersionFinderResponse.httpResponse.body}
|
||||
''');
|
||||
result = _PublishCheckResult._error;
|
||||
break;
|
||||
return _PublishCheckResult._error;
|
||||
case PubVersionFinderResult.noPackageFound:
|
||||
result = _PublishCheckResult._notPublished;
|
||||
break;
|
||||
return _PublishCheckResult._notPublished;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void _setStatus(String status) {
|
||||
@ -272,7 +261,7 @@ HTTP response: ${pubVersionFinderResponse.httpResponse.body}
|
||||
return const JsonEncoder.withIndent(' ').convert(_machineOutput);
|
||||
}
|
||||
|
||||
void _printImportantStatusMessage(String message, {@required bool isError}) {
|
||||
void _printImportantStatusMessage(String message, {required bool isError}) {
|
||||
final String statusMessage = '${isError ? 'ERROR' : 'SUCCESS'}: $message';
|
||||
if (getBoolArg(_machineFlag)) {
|
||||
print(statusMessage);
|
||||
|
Reference in New Issue
Block a user