Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Merge branch 'master' into tool-analysis-alignment
  • Loading branch information
stuartmorgan-g committed Apr 6, 2021
commit 1b15e77793f38baff5dcdc02b4fe53a968554a15
46 changes: 31 additions & 15 deletions script/tool/lib/src/publish_plugin_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,19 @@ class PublishPluginCommand extends PluginCommand {

@override
Future<void> run() async {
final String package = argResults[_packageOption] as String;
if (package == null) {
_print(
'Must specify a package to publish. See `plugin_tools help publish-plugin`.');
throw ToolExit(1);
}

_print('Checking local repo...');
_packageDir = _checkPackageDir();
await _checkGitStatus();
if (!await GitDir.isGitDir(packagesDir.path)) {
_print('$packagesDir is not a valid Git repository.');
throw ToolExit(1);
}

final bool shouldPushTag = argResults[_pushTagsOption] == true;
final String remote = argResults[_remoteOption] as String;
String remoteUrl;
Expand All @@ -101,10 +111,14 @@ class PublishPluginCommand extends PluginCommand {
}
_print('Local repo is ready!');

await _publish();
_print('Package published!');
if (argResults[_tagReleaseOption] != true) {
return await _finishSuccesfully();
final Directory packageDir = _getPackageDir(package);
await _publishPlugin(packageDir: packageDir);
if (argResults[_tagReleaseOption] as bool) {
await _tagRelease(
packageDir: packageDir,
remote: remote,
remoteUrl: remoteUrl,
shouldPushTag: shouldPushTag);
}
await _finishSuccesfully();
}
Expand Down Expand Up @@ -137,11 +151,12 @@ class PublishPluginCommand extends PluginCommand {
_print('Done!');
}

Directory _checkPackageDir() {
final String package = argResults[_packageOption] as String;
if (package == null) {
_print(
'Must specify a package to publish. See `plugin_tools help publish-plugin`.');
// Returns the packageDirectory based on the package name.
// Throws ToolExit if the `package` doesn't exist.
Directory _getPackageDir(String package) {
final Directory packageDir = packagesDir.childDirectory(package);
if (!packageDir.existsSync()) {
_print('${packageDir.absolute.path} does not exist.');
throw ToolExit(1);
}
return packageDir;
Expand All @@ -156,7 +171,8 @@ class PublishPluginCommand extends PluginCommand {
'--ignored',
packageDir.absolute.path
],
workingDir: _packageDir);
workingDir: packageDir);

final String statusOutput = statusResult.stdout as String;
if (statusOutput.isNotEmpty) {
_print(
Expand All @@ -170,11 +186,11 @@ class PublishPluginCommand extends PluginCommand {
Future<String> _verifyRemote(String remote) async {
final ProcessResult remoteInfo = await processRunner.runAndExitOnError(
'git', <String>['remote', 'get-url', remote],
workingDir: _packageDir);
workingDir: packagesDir);
return remoteInfo.stdout as String;
}

Future<void> _publish() async {
Future<void> _publish(Directory packageDir) async {
final List<String> publishFlags =
argResults[_pubFlagsOption] as List<String>;
_print(
Expand All @@ -200,7 +216,7 @@ class PublishPluginCommand extends PluginCommand {

String _getTag(Directory packageDir) {
final File pubspecFile =
fileSystem.file(p.join(_packageDir.path, 'pubspec.yaml'));
fileSystem.file(p.join(packageDir.path, 'pubspec.yaml'));
final YamlMap pubspecYaml =
loadYaml(pubspecFile.readAsStringSync()) as YamlMap;
final String name = pubspecYaml['name'] as String;
Expand Down
17 changes: 12 additions & 5 deletions script/tool/test/publish_plugin_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ void main() {

test('requires an existing flag', () async {
await expectLater(
() => commandRunner
.run(<String>['publish-plugin', '--package', 'iamerror', '--no-push-tags']),
() => commandRunner.run(<String>[
'publish-plugin',
'--package',
'iamerror',
'--no-push-tags'
]),
throwsA(const TypeMatcher<ToolExit>()));

expect(printedMessages.last, contains('iamerror does not exist'));
Expand All @@ -82,8 +86,12 @@ void main() {
pluginDir.childFile('tmp').createSync();

await expectLater(
() => commandRunner
.run(<String>['publish-plugin', '--package', testPluginName, '--no-push-tags']),
() => commandRunner.run(<String>[
'publish-plugin',
'--package',
testPluginName,
'--no-push-tags'
]),
throwsA(const TypeMatcher<ToolExit>()));

expect(
Expand All @@ -97,7 +105,6 @@ void main() {
() => commandRunner
.run(<String>['publish-plugin', '--package', testPluginName]),
throwsA(const TypeMatcher<ToolExit>()));

expect(processRunner.results.last.stderr, contains('No such remote'));
});

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.