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

[tools] Fix publish flag calculation #5694

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT

- Fixes changelog validation when reverting to a `NEXT` state.
- Fixes multiplication of `--force` flag when publishing multiple packages.

## 0.8.5

Expand Down
4 changes: 3 additions & 1 deletion script/tool/lib/src/common/plugin_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ abstract class PluginCommand extends Command<void> {

/// Convenience accessor for List<String> arguments.
List<String> getStringListArg(String key) {
return (argResults![key] as List<String>?) ?? <String>[];
// Clone the list so that if a caller modifies the result it won't change
// the actual arguments list for future queries.
return List<String>.from(argResults![key] as List<String>? ?? <String>[]);
}

/// If true, commands should log timing information that might be useful in
Expand Down
17 changes: 10 additions & 7 deletions script/tool/lib/src/publish_plugin_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class PublishPluginCommand extends PackageLoopingCommand {
List<String> _existingGitTags = <String>[];
// The remote to push tags to.
late _RemoteInfo _remote;
// Flags to pass to `pub publish`.
late List<String> _publishFlags;

@override
String get successSummaryMessage => 'published';
Expand Down Expand Up @@ -149,6 +151,11 @@ class PublishPluginCommand extends PackageLoopingCommand {
_existingGitTags = (existingTagsResult.stdout as String).split('\n')
..removeWhere((String element) => element.isEmpty);

_publishFlags = <String>[
...getStringListArg(_pubFlagsOption),
if (getBoolArg(_skipConfirmationFlag)) '--force',
];

if (getBoolArg(_dryRunFlag)) {
print('=============== DRY RUN ===============');
}
Expand Down Expand Up @@ -333,22 +340,18 @@ Safe to ignore if the package is deleted in this commit.

Future<bool> _publish(RepositoryPackage package) async {
print('Publishing...');
final List<String> publishFlags = getStringListArg(_pubFlagsOption);
print('Running `pub publish ${publishFlags.join(' ')}` in '
print('Running `pub publish ${_publishFlags.join(' ')}` in '
'${package.directory.absolute.path}...\n');
if (getBoolArg(_dryRunFlag)) {
return true;
}

if (getBoolArg(_skipConfirmationFlag)) {
publishFlags.add('--force');
}
if (publishFlags.contains('--force')) {
if (_publishFlags.contains('--force')) {
_ensureValidPubCredential();
}

final io.Process publish = await processRunner.start(
flutterCommand, <String>['pub', 'publish'] + publishFlags,
flutterCommand, <String>['pub', 'publish', ..._publishFlags],
workingDirectory: package.directory);
publish.stdout.transform(utf8.decoder).listen((String data) => print(data));
publish.stderr.transform(utf8.decoder).listen((String data) => print(data));
Expand Down
29 changes: 29 additions & 0 deletions script/tool/test/publish_plugin_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,35 @@ void main() {
plugin.path)));
});

test('--force is only added once, regardless of plugin count', () async {
_createMockCredentialFile();
final RepositoryPackage plugin1 =
createFakePlugin('plugin_a', packagesDir, examples: <String>[]);
final RepositoryPackage plugin2 =
createFakePlugin('plugin_b', packagesDir, examples: <String>[]);

await runCapturingPrint(commandRunner, <String>[
'publish-plugin',
'--packages=plugin_a,plugin_b',
'--skip-confirmation',
'--pub-publish-flags',
'--server=bar'
]);

expect(
processRunner.recordedCalls,
containsAllInOrder(<ProcessCall>[
ProcessCall(
flutterCommand,
const <String>['pub', 'publish', '--server=bar', '--force'],
plugin1.path),
ProcessCall(
flutterCommand,
const <String>['pub', 'publish', '--server=bar', '--force'],
plugin2.path),
]));
});

test('throws if pub publish fails', () async {
createFakePlugin('foo', packagesDir, examples: <String>[]);

Expand Down