This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Publish check #3556
Merged
Merged
Publish check #3556
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Null> run() async { | ||
checkSharding(); | ||
final List<Directory> failedPackages = <Directory>[]; | ||
|
||
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()); | ||
bparrishMines marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} on Exception catch (exception) { | ||
print( | ||
'Failed to parse `pubspec.yaml` at ${pubspecFile.path}: $exception}', | ||
); | ||
return null; | ||
} | ||
|
||
return pubspec; | ||
} | ||
|
||
Future<bool> 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', | ||
<String>['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; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.