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

Commit 7dc808a

Browse files
[tools] Fix publish flag calculation (#5694)
1 parent debc272 commit 7dc808a

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

script/tool/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## NEXT
22

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

56
## 0.8.5
67

script/tool/lib/src/common/plugin_command.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ abstract class PluginCommand extends Command<void> {
192192

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

198200
/// If true, commands should log timing information that might be useful in

script/tool/lib/src/publish_plugin_command.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class PublishPluginCommand extends PackageLoopingCommand {
121121
List<String> _existingGitTags = <String>[];
122122
// The remote to push tags to.
123123
late _RemoteInfo _remote;
124+
// Flags to pass to `pub publish`.
125+
late List<String> _publishFlags;
124126

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

154+
_publishFlags = <String>[
155+
...getStringListArg(_pubFlagsOption),
156+
if (getBoolArg(_skipConfirmationFlag)) '--force',
157+
];
158+
152159
if (getBoolArg(_dryRunFlag)) {
153160
print('=============== DRY RUN ===============');
154161
}
@@ -333,22 +340,18 @@ Safe to ignore if the package is deleted in this commit.
333340

334341
Future<bool> _publish(RepositoryPackage package) async {
335342
print('Publishing...');
336-
final List<String> publishFlags = getStringListArg(_pubFlagsOption);
337-
print('Running `pub publish ${publishFlags.join(' ')}` in '
343+
print('Running `pub publish ${_publishFlags.join(' ')}` in '
338344
'${package.directory.absolute.path}...\n');
339345
if (getBoolArg(_dryRunFlag)) {
340346
return true;
341347
}
342348

343-
if (getBoolArg(_skipConfirmationFlag)) {
344-
publishFlags.add('--force');
345-
}
346-
if (publishFlags.contains('--force')) {
349+
if (_publishFlags.contains('--force')) {
347350
_ensureValidPubCredential();
348351
}
349352

350353
final io.Process publish = await processRunner.start(
351-
flutterCommand, <String>['pub', 'publish'] + publishFlags,
354+
flutterCommand, <String>['pub', 'publish', ..._publishFlags],
352355
workingDirectory: package.directory);
353356
publish.stdout.transform(utf8.decoder).listen((String data) => print(data));
354357
publish.stderr.transform(utf8.decoder).listen((String data) => print(data));

script/tool/test/publish_plugin_command_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,35 @@ void main() {
224224
plugin.path)));
225225
});
226226

227+
test('--force is only added once, regardless of plugin count', () async {
228+
_createMockCredentialFile();
229+
final RepositoryPackage plugin1 =
230+
createFakePlugin('plugin_a', packagesDir, examples: <String>[]);
231+
final RepositoryPackage plugin2 =
232+
createFakePlugin('plugin_b', packagesDir, examples: <String>[]);
233+
234+
await runCapturingPrint(commandRunner, <String>[
235+
'publish-plugin',
236+
'--packages=plugin_a,plugin_b',
237+
'--skip-confirmation',
238+
'--pub-publish-flags',
239+
'--server=bar'
240+
]);
241+
242+
expect(
243+
processRunner.recordedCalls,
244+
containsAllInOrder(<ProcessCall>[
245+
ProcessCall(
246+
flutterCommand,
247+
const <String>['pub', 'publish', '--server=bar', '--force'],
248+
plugin1.path),
249+
ProcessCall(
250+
flutterCommand,
251+
const <String>['pub', 'publish', '--server=bar', '--force'],
252+
plugin2.path),
253+
]));
254+
});
255+
227256
test('throws if pub publish fails', () async {
228257
createFakePlugin('foo', packagesDir, examples: <String>[]);
229258

0 commit comments

Comments
 (0)