Thanks to visit codestin.com
Credit goes to github.com

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

Commit bc95853

Browse files
[flutter_plugin_tools] Add 'main' support (#4474)
Treat `main` the same as `master` for branch-based switching, in preparation for switching the branch names in Flutter repositories. Also updates all of the tests that used `master` as the explicit base to use `main` instead; what the tests use is arbitrary, so they can be switched now even though the repo itself hasn't switched. Part of flutter/flutter#90476
1 parent 020c855 commit bc95853

9 files changed

+122
-148
lines changed

script/tool/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## NEXT
1+
## 0.7.2
22

33
- Update Firebase Testlab deprecated test device. (Pixel 4 API 29 -> Pixel 5 API 30).
44
- `native-test --android`, `--ios`, and `--macos` now fail plugins that don't
@@ -15,6 +15,8 @@
1515
length.
1616
- Fix `license-check` when run on Windows with line ending conversion enabled.
1717
- Fixed `pubspec-check` on Windows.
18+
- Add support for `main` as a primary branch. `master` continues to work for
19+
compatibility.
1820

1921
## 0.7.1
2022

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ abstract class PluginCommand extends Command<void> {
8181
argParser.addFlag(_packagesForBranchArg,
8282
help:
8383
'This runs on all packages (equivalent to no package selection flag)\n'
84-
'on master, and behaves like --run-on-changed-packages on any other branch.\n\n'
84+
'on main (or master), and behaves like --run-on-changed-packages on '
85+
'any other branch.\n\n'
8586
'Cannot be combined with $_packagesArg.\n\n'
8687
'This is intended for use in CI.\n',
8788
hide: true);
@@ -301,7 +302,7 @@ abstract class PluginCommand extends Command<void> {
301302
'only be used in a git repository.');
302303
throw ToolExit(exitInvalidArguments);
303304
} else {
304-
runOnChangedPackages = branch != 'master';
305+
runOnChangedPackages = branch != 'master' && branch != 'main';
305306
// Log the mode for auditing what was intended to run.
306307
print('--$_packagesForBranchArg: running on '
307308
'${runOnChangedPackages ? 'changed' : 'all'} packages');

script/tool/lib/src/test_command.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TestCommand extends PackageLoopingCommand {
2424
defaultsTo: '',
2525
help:
2626
'Runs Dart unit tests in Dart VM with the given experiments enabled. '
27-
'See https://github.com/dart-lang/sdk/blob/master/docs/process/experimental-flags.md '
27+
'See https://github.com/dart-lang/sdk/blob/main/docs/process/experimental-flags.md '
2828
'for details.',
2929
);
3030
}

script/tool/lib/src/version_check_command.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
262262
// This method isn't called unless `version` is non-null.
263263
final Version currentVersion = pubspec.version!;
264264
Version? previousVersion;
265+
String previousVersionSource;
265266
if (getBoolArg(_againstPubFlag)) {
267+
previousVersionSource = 'pub';
266268
previousVersion = await _fetchPreviousVersionFromPub(pubspec.name);
267269
if (previousVersion == null) {
268270
return _CurrentVersionState.unknown;
@@ -273,6 +275,7 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
273275
}
274276
} else {
275277
final GitVersionFinder gitVersionFinder = await retrieveVersionFinder();
278+
previousVersionSource = await gitVersionFinder.getBaseSha();
276279
previousVersion = await _getPreviousVersionFromGit(package,
277280
gitVersionFinder: gitVersionFinder) ??
278281
Version.none;
@@ -310,9 +313,8 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
310313
if (allowedNextVersions.containsKey(currentVersion)) {
311314
print('$indentation$previousVersion -> $currentVersion');
312315
} else {
313-
final String source = (getBoolArg(_againstPubFlag)) ? 'pub' : 'master';
314316
printError('${indentation}Incorrectly updated version.\n'
315-
'${indentation}HEAD: $currentVersion, $source: $previousVersion.\n'
317+
'${indentation}HEAD: $currentVersion, $previousVersionSource: $previousVersion.\n'
316318
'${indentation}Allowed versions: $allowedNextVersions');
317319
return _CurrentVersionState.invalidChange;
318320
}

script/tool/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_plugin_tools
22
description: Productivity utils for flutter/plugins and flutter/packages
33
repository: https://github.com/flutter/plugins/tree/master/script/tool
4-
version: 0.7.1
4+
version: 0.7.2
55

66
dependencies:
77
args: ^2.1.0

script/tool/test/analyze_command_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ void main() {
253253
});
254254

255255
// Ensure that the command used to analyze flutter/plugins in the Dart repo:
256-
// https://github.com/dart-lang/sdk/blob/master/tools/bots/flutter/analyze_flutter_plugins.sh
256+
// https://github.com/dart-lang/sdk/blob/main/tools/bots/flutter/analyze_flutter_plugins.sh
257257
// continues to work.
258258
//
259259
// DO NOT remove or modify this test without a coordination plan in place to

script/tool/test/common/plugin_command_test.dart

Lines changed: 50 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,8 @@ void main() {
246246
test('all plugins should be tested if there are no changes.', () async {
247247
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
248248
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
249-
await runCapturingPrint(runner, <String>[
250-
'sample',
251-
'--base-sha=master',
252-
'--run-on-changed-packages'
253-
]);
249+
await runCapturingPrint(runner,
250+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
254251

255252
expect(command.plugins,
256253
unorderedEquals(<String>[plugin1.path, plugin2.path]));
@@ -264,11 +261,8 @@ void main() {
264261
];
265262
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
266263
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
267-
await runCapturingPrint(runner, <String>[
268-
'sample',
269-
'--base-sha=master',
270-
'--run-on-changed-packages'
271-
]);
264+
await runCapturingPrint(runner,
265+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
272266

273267
expect(command.plugins,
274268
unorderedEquals(<String>[plugin1.path, plugin2.path]));
@@ -283,11 +277,8 @@ packages/plugin1/CHANGELOG
283277
];
284278
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
285279
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
286-
await runCapturingPrint(runner, <String>[
287-
'sample',
288-
'--base-sha=master',
289-
'--run-on-changed-packages'
290-
]);
280+
await runCapturingPrint(runner,
281+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
291282

292283
expect(command.plugins,
293284
unorderedEquals(<String>[plugin1.path, plugin2.path]));
@@ -302,11 +293,8 @@ packages/plugin1/CHANGELOG
302293
];
303294
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
304295
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
305-
await runCapturingPrint(runner, <String>[
306-
'sample',
307-
'--base-sha=master',
308-
'--run-on-changed-packages'
309-
]);
296+
await runCapturingPrint(runner,
297+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
310298

311299
expect(command.plugins,
312300
unorderedEquals(<String>[plugin1.path, plugin2.path]));
@@ -322,11 +310,8 @@ packages/plugin1/CHANGELOG
322310
];
323311
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
324312
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
325-
await runCapturingPrint(runner, <String>[
326-
'sample',
327-
'--base-sha=master',
328-
'--run-on-changed-packages'
329-
]);
313+
await runCapturingPrint(runner,
314+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
330315

331316
expect(command.plugins,
332317
unorderedEquals(<String>[plugin1.path, plugin2.path]));
@@ -342,11 +327,8 @@ packages/plugin1/CHANGELOG
342327
];
343328
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
344329
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
345-
await runCapturingPrint(runner, <String>[
346-
'sample',
347-
'--base-sha=master',
348-
'--run-on-changed-packages'
349-
]);
330+
await runCapturingPrint(runner,
331+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
350332

351333
expect(command.plugins,
352334
unorderedEquals(<String>[plugin1.path, plugin2.path]));
@@ -362,11 +344,8 @@ packages/plugin1/CHANGELOG
362344
];
363345
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
364346
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
365-
await runCapturingPrint(runner, <String>[
366-
'sample',
367-
'--base-sha=master',
368-
'--run-on-changed-packages'
369-
]);
347+
await runCapturingPrint(runner,
348+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
370349

371350
expect(command.plugins,
372351
unorderedEquals(<String>[plugin1.path, plugin2.path]));
@@ -382,11 +361,8 @@ packages/plugin1/CHANGELOG
382361
];
383362
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
384363
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
385-
await runCapturingPrint(runner, <String>[
386-
'sample',
387-
'--base-sha=master',
388-
'--run-on-changed-packages'
389-
]);
364+
await runCapturingPrint(runner,
365+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
390366

391367
expect(command.plugins,
392368
unorderedEquals(<String>[plugin1.path, plugin2.path]));
@@ -398,17 +374,14 @@ packages/plugin1/CHANGELOG
398374
];
399375
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
400376
createFakePlugin('plugin2', packagesDir);
401-
final List<String> output = await runCapturingPrint(runner, <String>[
402-
'sample',
403-
'--base-sha=master',
404-
'--run-on-changed-packages'
405-
]);
377+
final List<String> output = await runCapturingPrint(runner,
378+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
406379

407380
expect(
408381
output,
409382
containsAllInOrder(<Matcher>[
410383
contains(
411-
'Running for all packages that have changed relative to "master"'),
384+
'Running for all packages that have changed relative to "main"'),
412385
]));
413386

414387
expect(command.plugins, unorderedEquals(<String>[plugin1.path]));
@@ -424,11 +397,8 @@ packages/plugin1/ios/plugin1.m
424397
];
425398
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
426399
createFakePlugin('plugin2', packagesDir);
427-
await runCapturingPrint(runner, <String>[
428-
'sample',
429-
'--base-sha=master',
430-
'--run-on-changed-packages'
431-
]);
400+
await runCapturingPrint(runner,
401+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
432402

433403
expect(command.plugins, unorderedEquals(<String>[plugin1.path]));
434404
});
@@ -444,11 +414,8 @@ packages/plugin2/ios/plugin2.m
444414
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
445415
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
446416
createFakePlugin('plugin3', packagesDir);
447-
await runCapturingPrint(runner, <String>[
448-
'sample',
449-
'--base-sha=master',
450-
'--run-on-changed-packages'
451-
]);
417+
await runCapturingPrint(runner,
418+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
452419

453420
expect(command.plugins,
454421
unorderedEquals(<String>[plugin1.path, plugin2.path]));
@@ -468,11 +435,8 @@ packages/plugin1/plugin1_web/plugin1_web.dart
468435
createFakePlugin('plugin1', packagesDir.childDirectory('plugin1'));
469436
createFakePlugin('plugin2', packagesDir);
470437
createFakePlugin('plugin3', packagesDir);
471-
await runCapturingPrint(runner, <String>[
472-
'sample',
473-
'--base-sha=master',
474-
'--run-on-changed-packages'
475-
]);
438+
await runCapturingPrint(runner,
439+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
476440

477441
expect(command.plugins, unorderedEquals(<String>[plugin1.path]));
478442
});
@@ -491,11 +455,8 @@ packages/plugin1/plugin1/plugin1.dart
491455
packagesDir.childDirectory('plugin1'));
492456
final Directory plugin3 = createFakePlugin(
493457
'plugin1_web', packagesDir.childDirectory('plugin1'));
494-
await runCapturingPrint(runner, <String>[
495-
'sample',
496-
'--base-sha=master',
497-
'--run-on-changed-packages'
498-
]);
458+
await runCapturingPrint(runner,
459+
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);
499460

500461
expect(
501462
command.plugins,
@@ -518,7 +479,7 @@ packages/plugin3/plugin3.dart
518479
await runCapturingPrint(runner, <String>[
519480
'sample',
520481
'--exclude=plugin2,plugin3',
521-
'--base-sha=master',
482+
'--base-sha=main',
522483
'--run-on-changed-packages'
523484
]);
524485

@@ -549,6 +510,28 @@ packages/plugin3/plugin3.dart
549510
]));
550511
});
551512

513+
test('tests all packages on main', () async {
514+
processRunner.mockProcessesForExecutable['git-diff'] = <Process>[
515+
MockProcess(stdout: 'packages/plugin1/plugin1.dart'),
516+
];
517+
processRunner.mockProcessesForExecutable['git-rev-parse'] = <Process>[
518+
MockProcess(stdout: 'main'),
519+
];
520+
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
521+
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
522+
523+
final List<String> output = await runCapturingPrint(
524+
runner, <String>['sample', '--packages-for-branch']);
525+
526+
expect(command.plugins,
527+
unorderedEquals(<String>[plugin1.path, plugin2.path]));
528+
expect(
529+
output,
530+
containsAllInOrder(<Matcher>[
531+
contains('--packages-for-branch: running on all packages'),
532+
]));
533+
});
534+
552535
test('tests all packages on master', () async {
553536
processRunner.mockProcessesForExecutable['git-diff'] = <Process>[
554537
MockProcess(stdout: 'packages/plugin1/plugin1.dart'),

script/tool/test/pubspec_check_command_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ String _headerSection(
3838
'flutter',
3939
if (isPlugin) 'plugins' else 'packages',
4040
'tree',
41-
'master',
41+
'main',
4242
'packages',
4343
repositoryPath,
4444
];

0 commit comments

Comments
 (0)