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.

[flutter_plugin_tools] Add 'main' support #4474

Merged
merged 1 commit into from
Nov 10, 2021
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
4 changes: 3 additions & 1 deletion script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## NEXT
## 0.7.2

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

## 0.7.1

Expand Down
5 changes: 3 additions & 2 deletions script/tool/lib/src/common/plugin_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ abstract class PluginCommand extends Command<void> {
argParser.addFlag(_packagesForBranchArg,
help:
'This runs on all packages (equivalent to no package selection flag)\n'
'on master, and behaves like --run-on-changed-packages on any other branch.\n\n'
'on main (or master), and behaves like --run-on-changed-packages on '
'any other branch.\n\n'
'Cannot be combined with $_packagesArg.\n\n'
'This is intended for use in CI.\n',
hide: true);
Expand Down Expand Up @@ -301,7 +302,7 @@ abstract class PluginCommand extends Command<void> {
'only be used in a git repository.');
throw ToolExit(exitInvalidArguments);
} else {
runOnChangedPackages = branch != 'master';
runOnChangedPackages = branch != 'master' && branch != 'main';
// Log the mode for auditing what was intended to run.
print('--$_packagesForBranchArg: running on '
'${runOnChangedPackages ? 'changed' : 'all'} packages');
Expand Down
2 changes: 1 addition & 1 deletion script/tool/lib/src/test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestCommand extends PackageLoopingCommand {
defaultsTo: '',
help:
'Runs Dart unit tests in Dart VM with the given experiments enabled. '
'See https://github.com/dart-lang/sdk/blob/master/docs/process/experimental-flags.md '
'See https://github.com/dart-lang/sdk/blob/main/docs/process/experimental-flags.md '
'for details.',
);
}
Expand Down
6 changes: 4 additions & 2 deletions script/tool/lib/src/version_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
// This method isn't called unless `version` is non-null.
final Version currentVersion = pubspec.version!;
Version? previousVersion;
String previousVersionSource;
if (getBoolArg(_againstPubFlag)) {
previousVersionSource = 'pub';
previousVersion = await _fetchPreviousVersionFromPub(pubspec.name);
if (previousVersion == null) {
return _CurrentVersionState.unknown;
Expand All @@ -273,6 +275,7 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
}
} else {
final GitVersionFinder gitVersionFinder = await retrieveVersionFinder();
previousVersionSource = await gitVersionFinder.getBaseSha();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a logical change since getBaseSha() isn't necessarily master (or main), right? This sounds like the correct thing to do. It might be worth mentioning this a bit more explicitly in the description in case it does cause some problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a logical change since getBaseSha() isn't necessarily master (or main), right?

In that the error logging was wrong before, and now isn't, yes. getBaseSha() is what the code that populates previousVersion actually uses; the error logging on failure (which is all this is used for) was incorrectly hard-coding that to master. In practice, in presubmit, it's the same thing, so it hadn't been noticed.

It might be worth mentioning this a bit more explicitly in the description in case it does cause some problems.

It would only be a problem if something were parsing human-targeted error output (which we aren't, and we only guarantee this tool's behavior for our use currently), and relying on the exact output, and were using a base revision other than master.

previousVersion = await _getPreviousVersionFromGit(package,
gitVersionFinder: gitVersionFinder) ??
Version.none;
Expand Down Expand Up @@ -310,9 +313,8 @@ ${indentation}HTTP response: ${pubVersionFinderResponse.httpResponse.body}
if (allowedNextVersions.containsKey(currentVersion)) {
print('$indentation$previousVersion -> $currentVersion');
} else {
final String source = (getBoolArg(_againstPubFlag)) ? 'pub' : 'master';
printError('${indentation}Incorrectly updated version.\n'
'${indentation}HEAD: $currentVersion, $source: $previousVersion.\n'
'${indentation}HEAD: $currentVersion, $previousVersionSource: $previousVersion.\n'
'${indentation}Allowed versions: $allowedNextVersions');
return _CurrentVersionState.invalidChange;
}
Expand Down
2 changes: 1 addition & 1 deletion script/tool/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: flutter_plugin_tools
description: Productivity utils for flutter/plugins and flutter/packages
repository: https://github.com/flutter/plugins/tree/master/script/tool
version: 0.7.1
version: 0.7.2

dependencies:
args: ^2.1.0
Expand Down
2 changes: 1 addition & 1 deletion script/tool/test/analyze_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void main() {
});

// Ensure that the command used to analyze flutter/plugins in the Dart repo:
// https://github.com/dart-lang/sdk/blob/master/tools/bots/flutter/analyze_flutter_plugins.sh
// https://github.com/dart-lang/sdk/blob/main/tools/bots/flutter/analyze_flutter_plugins.sh
// continues to work.
//
// DO NOT remove or modify this test without a coordination plan in place to
Expand Down
117 changes: 50 additions & 67 deletions script/tool/test/common/plugin_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,8 @@ void main() {
test('all plugins should be tested if there are no changes.', () async {
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
Expand All @@ -264,11 +261,8 @@ void main() {
];
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
Expand All @@ -283,11 +277,8 @@ packages/plugin1/CHANGELOG
];
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
Expand All @@ -302,11 +293,8 @@ packages/plugin1/CHANGELOG
];
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
Expand All @@ -322,11 +310,8 @@ packages/plugin1/CHANGELOG
];
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
Expand All @@ -342,11 +327,8 @@ packages/plugin1/CHANGELOG
];
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
Expand All @@ -362,11 +344,8 @@ packages/plugin1/CHANGELOG
];
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
Expand All @@ -382,11 +361,8 @@ packages/plugin1/CHANGELOG
];
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
Expand All @@ -398,17 +374,14 @@ packages/plugin1/CHANGELOG
];
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
createFakePlugin('plugin2', packagesDir);
final List<String> output = await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
final List<String> output = await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(
output,
containsAllInOrder(<Matcher>[
contains(
'Running for all packages that have changed relative to "master"'),
'Running for all packages that have changed relative to "main"'),
]));

expect(command.plugins, unorderedEquals(<String>[plugin1.path]));
Expand All @@ -424,11 +397,8 @@ packages/plugin1/ios/plugin1.m
];
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
createFakePlugin('plugin2', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins, unorderedEquals(<String>[plugin1.path]));
});
Expand All @@ -444,11 +414,8 @@ packages/plugin2/ios/plugin2.m
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);
createFakePlugin('plugin3', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
Expand All @@ -468,11 +435,8 @@ packages/plugin1/plugin1_web/plugin1_web.dart
createFakePlugin('plugin1', packagesDir.childDirectory('plugin1'));
createFakePlugin('plugin2', packagesDir);
createFakePlugin('plugin3', packagesDir);
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(command.plugins, unorderedEquals(<String>[plugin1.path]));
});
Expand All @@ -491,11 +455,8 @@ packages/plugin1/plugin1/plugin1.dart
packagesDir.childDirectory('plugin1'));
final Directory plugin3 = createFakePlugin(
'plugin1_web', packagesDir.childDirectory('plugin1'));
await runCapturingPrint(runner, <String>[
'sample',
'--base-sha=master',
'--run-on-changed-packages'
]);
await runCapturingPrint(runner,
<String>['sample', '--base-sha=main', '--run-on-changed-packages']);

expect(
command.plugins,
Expand All @@ -518,7 +479,7 @@ packages/plugin3/plugin3.dart
await runCapturingPrint(runner, <String>[
'sample',
'--exclude=plugin2,plugin3',
'--base-sha=master',
'--base-sha=main',
'--run-on-changed-packages'
]);

Expand Down Expand Up @@ -549,6 +510,28 @@ packages/plugin3/plugin3.dart
]));
});

test('tests all packages on main', () async {
processRunner.mockProcessesForExecutable['git-diff'] = <Process>[
MockProcess(stdout: 'packages/plugin1/plugin1.dart'),
];
processRunner.mockProcessesForExecutable['git-rev-parse'] = <Process>[
MockProcess(stdout: 'main'),
];
final Directory plugin1 = createFakePlugin('plugin1', packagesDir);
final Directory plugin2 = createFakePlugin('plugin2', packagesDir);

final List<String> output = await runCapturingPrint(
runner, <String>['sample', '--packages-for-branch']);

expect(command.plugins,
unorderedEquals(<String>[plugin1.path, plugin2.path]));
expect(
output,
containsAllInOrder(<Matcher>[
contains('--packages-for-branch: running on all packages'),
]));
});

test('tests all packages on master', () async {
processRunner.mockProcessesForExecutable['git-diff'] = <Process>[
MockProcess(stdout: 'packages/plugin1/plugin1.dart'),
Expand Down
2 changes: 1 addition & 1 deletion script/tool/test/pubspec_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ String _headerSection(
'flutter',
if (isPlugin) 'plugins' else 'packages',
'tree',
'master',
'main',
'packages',
repositoryPath,
];
Expand Down
Loading