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.

[tool] Get dependencies in package examples before publish check. #6596

Merged
merged 1 commit into from
Oct 20, 2022
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
5 changes: 5 additions & 0 deletions script/tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.12.1

* Modifies `publish_check_command.dart` to do a `dart pub get` in all examples
of the package being checked. Workaround for [dart-lang/pub#3618](https://github.com/dart-lang/pub/issues/3618).

## 0.12.0

* Changes the behavior of `--packages-for-branch` on main/master to run for
Expand Down
16 changes: 16 additions & 0 deletions script/tool/lib/src/publish_check_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,23 @@ class PublishCheckCommand extends PackageLoopingCommand {
}
}

// Run `dart pub get` on the examples of [package].
Future<void> _fetchExampleDeps(RepositoryPackage package) async {
for (final RepositoryPackage example in package.getExamples()) {
await processRunner.runAndStream(
'dart',
<String>['pub', 'get'],
workingDir: example.directory,
);
}
}

Future<bool> _hasValidPublishCheckRun(RepositoryPackage package) async {
// `pub publish` does not do `dart pub get` inside `example` directories
// of a package (but they're part of the analysis output!).
// Issue: https://github.com/flutter/flutter/issues/113788
await _fetchExampleDeps(package);

print('Running pub publish --dry-run:');
final io.Process process = await processRunner.start(
flutterCommand,
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/main/script/tool
version: 0.12.0
version: 0.12.1

dependencies:
args: ^2.1.0
Expand Down
57 changes: 53 additions & 4 deletions script/tool/test/publish_check_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ void main() {
});

test('publish check all packages', () async {
final RepositoryPackage plugin1 =
createFakePlugin('plugin_tools_test_package_a', packagesDir);
final RepositoryPackage plugin2 =
createFakePlugin('plugin_tools_test_package_b', packagesDir);
final RepositoryPackage plugin1 = createFakePlugin(
'plugin_tools_test_package_a',
packagesDir,
examples: <String>[],
);
final RepositoryPackage plugin2 = createFakePlugin(
'plugin_tools_test_package_b',
packagesDir,
examples: <String>[],
);

await runCapturingPrint(runner, <String>['publish-check']);

Expand All @@ -65,6 +71,49 @@ void main() {
]));
});

test('publish prepares dependencies of examples (when present)', () async {
final RepositoryPackage plugin1 = createFakePlugin(
'plugin_tools_test_package_a',
packagesDir,
examples: <String>['example1', 'example2'],
);
final RepositoryPackage plugin2 = createFakePlugin(
'plugin_tools_test_package_b',
packagesDir,
examples: <String>[],
);

await runCapturingPrint(runner, <String>['publish-check']);

// For plugin1, these are the expected pub get calls that will happen
final Iterable<ProcessCall> pubGetCalls =
plugin1.getExamples().map((RepositoryPackage example) {
return ProcessCall(
'dart',
const <String>['pub', 'get'],
example.path,
);
});

expect(pubGetCalls, hasLength(2));
expect(
processRunner.recordedCalls,
orderedEquals(<ProcessCall>[
// plugin1 has 2 examples, so there's some 'dart pub get' calls.
...pubGetCalls,
ProcessCall(
'flutter',
const <String>['pub', 'publish', '--', '--dry-run'],
plugin1.path),
// plugin2 has no examples, so there's no extra 'dart pub get' calls.
ProcessCall(
'flutter',
const <String>['pub', 'publish', '--', '--dry-run'],
plugin2.path),
]),
);
});

test('fail on negative test', () async {
createFakePlugin('plugin_tools_test_package_a', packagesDir);

Expand Down