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

Commit 3a03925

Browse files
authored
[tool] Get dependencies in package examples before publish check. (#6596)
1 parent 09a4a09 commit 3a03925

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
lines changed

script/tool/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.12.1
2+
3+
* Modifies `publish_check_command.dart` to do a `dart pub get` in all examples
4+
of the package being checked. Workaround for [dart-lang/pub#3618](https://github.com/dart-lang/pub/issues/3618).
5+
16
## 0.12.0
27

38
* Changes the behavior of `--packages-for-branch` on main/master to run for

script/tool/lib/src/publish_check_command.dart

+16
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,23 @@ class PublishCheckCommand extends PackageLoopingCommand {
130130
}
131131
}
132132

133+
// Run `dart pub get` on the examples of [package].
134+
Future<void> _fetchExampleDeps(RepositoryPackage package) async {
135+
for (final RepositoryPackage example in package.getExamples()) {
136+
await processRunner.runAndStream(
137+
'dart',
138+
<String>['pub', 'get'],
139+
workingDir: example.directory,
140+
);
141+
}
142+
}
143+
133144
Future<bool> _hasValidPublishCheckRun(RepositoryPackage package) async {
145+
// `pub publish` does not do `dart pub get` inside `example` directories
146+
// of a package (but they're part of the analysis output!).
147+
// Issue: https://github.com/flutter/flutter/issues/113788
148+
await _fetchExampleDeps(package);
149+
134150
print('Running pub publish --dry-run:');
135151
final io.Process process = await processRunner.start(
136152
flutterCommand,

script/tool/pubspec.yaml

+1-1
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/main/script/tool
4-
version: 0.12.0
4+
version: 0.12.1
55

66
dependencies:
77
args: ^2.1.0

script/tool/test/publish_check_command_test.dart

+53-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ void main() {
4444
});
4545

4646
test('publish check all packages', () async {
47-
final RepositoryPackage plugin1 =
48-
createFakePlugin('plugin_tools_test_package_a', packagesDir);
49-
final RepositoryPackage plugin2 =
50-
createFakePlugin('plugin_tools_test_package_b', packagesDir);
47+
final RepositoryPackage plugin1 = createFakePlugin(
48+
'plugin_tools_test_package_a',
49+
packagesDir,
50+
examples: <String>[],
51+
);
52+
final RepositoryPackage plugin2 = createFakePlugin(
53+
'plugin_tools_test_package_b',
54+
packagesDir,
55+
examples: <String>[],
56+
);
5157

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

@@ -65,6 +71,49 @@ void main() {
6571
]));
6672
});
6773

74+
test('publish prepares dependencies of examples (when present)', () async {
75+
final RepositoryPackage plugin1 = createFakePlugin(
76+
'plugin_tools_test_package_a',
77+
packagesDir,
78+
examples: <String>['example1', 'example2'],
79+
);
80+
final RepositoryPackage plugin2 = createFakePlugin(
81+
'plugin_tools_test_package_b',
82+
packagesDir,
83+
examples: <String>[],
84+
);
85+
86+
await runCapturingPrint(runner, <String>['publish-check']);
87+
88+
// For plugin1, these are the expected pub get calls that will happen
89+
final Iterable<ProcessCall> pubGetCalls =
90+
plugin1.getExamples().map((RepositoryPackage example) {
91+
return ProcessCall(
92+
'dart',
93+
const <String>['pub', 'get'],
94+
example.path,
95+
);
96+
});
97+
98+
expect(pubGetCalls, hasLength(2));
99+
expect(
100+
processRunner.recordedCalls,
101+
orderedEquals(<ProcessCall>[
102+
// plugin1 has 2 examples, so there's some 'dart pub get' calls.
103+
...pubGetCalls,
104+
ProcessCall(
105+
'flutter',
106+
const <String>['pub', 'publish', '--', '--dry-run'],
107+
plugin1.path),
108+
// plugin2 has no examples, so there's no extra 'dart pub get' calls.
109+
ProcessCall(
110+
'flutter',
111+
const <String>['pub', 'publish', '--', '--dry-run'],
112+
plugin2.path),
113+
]),
114+
);
115+
});
116+
68117
test('fail on negative test', () async {
69118
createFakePlugin('plugin_tools_test_package_a', packagesDir);
70119

0 commit comments

Comments
 (0)