Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Publish check ignores prerelease sdk #3560

Merged
merged 4 commits into from
Feb 18, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions script/tool/lib/src/publish_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'dart:async';
import 'dart:io' as io;

import 'package:colorize/colorize.dart';
import 'package:file/file.dart';
Expand Down Expand Up @@ -63,6 +64,33 @@ class PublishCheckCommand extends PluginCommand {
}
}

Future<bool> hasValidPublishCheckRun(Directory package) async {
final io.Process process = await io.Process.start(
'flutter',
<String>['pub', 'publish', '--', '--dry-run'],
workingDirectory: package.path,
);

String output = '';
process.stdout.listen((List<int> event) {
io.stdout.add(event);
output += String.fromCharCodes(event);
});

process.stderr.listen((List<int> event) {
io.stderr.add(event);
output += String.fromCharCodes(event);
});

final int exitCode = await process.exitCode;

bparrishMines marked this conversation as resolved.
Show resolved Hide resolved
final bool hasPreReleaseSdk = output.contains('Package has 1 warning.') &&
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to wait on the output to ensure we're getting it all, to avoid potentially flaky results from the contains check. The exitCode docs say:

There is no guarantee that stdout and stderr have finished reporting the buffered output of the process when the returned future completes. To be sure that all output is captured, wait for the done event on the streams.

output.contains(
'Packages with an SDK constraint on a pre-release of the Dart SDK should themselves be published as a pre-release version.');

return exitCode == 0 || hasPreReleaseSdk;
}

Future<bool> passesPublishCheck(Directory package) async {
final String packageName = package.basename;
print('Checking that $packageName can be published.');
Expand All @@ -75,13 +103,7 @@ class PublishCheckCommand extends PluginCommand {
return true;
}

final int exitCode = await processRunner.runAndStream(
'flutter',
<String>['pub', 'publish', '--', '--dry-run'],
workingDir: package,
);

if (exitCode == 0) {
if (await hasValidPublishCheckRun(package)) {
print("Package $packageName is able to be published.");
return true;
} else {
Expand Down