-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add CI steps to test iOS and macOS plugins with both CocoaPods and Swift Package Manager #6557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
91781e7
ea572aa
730aafe
1e555ba
ce01604
7fc426b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,9 @@ const String _flutterBuildTypeWindows = 'windows'; | |
|
|
||
| const String _flutterBuildTypeAndroidAlias = 'android'; | ||
|
|
||
| /// Key for Swift Package Manager. | ||
| const String _swiftPackageManagerFlag = 'swift-package-manager'; | ||
|
|
||
| /// A command to build the example applications for packages. | ||
| class BuildExamplesCommand extends PackageLoopingCommand { | ||
| /// Creates an instance of the build command. | ||
|
|
@@ -58,6 +61,7 @@ class BuildExamplesCommand extends PackageLoopingCommand { | |
| defaultsTo: '', | ||
| help: 'Enables the given Dart SDK experiments.', | ||
| ); | ||
| argParser.addFlag(_swiftPackageManagerFlag); | ||
| } | ||
|
|
||
| // Maps the switch this command uses to identify a platform to information | ||
|
|
@@ -111,6 +115,15 @@ class BuildExamplesCommand extends PackageLoopingCommand { | |
| 'single key "$_pluginToolsConfigGlobalKey" containing a list of build ' | ||
| 'arguments.'; | ||
|
|
||
| /// Returns true if `--swift-package-manager` flag was passed along with | ||
| /// either `--ios` or `--macos`. | ||
| bool get usingSwiftPackageManager { | ||
| final List<String> platformFlags = _platforms.keys.toList(); | ||
| return getBoolArg(_swiftPackageManagerFlag) && | ||
| (platformFlags.contains(platformIOS) || | ||
| platformFlags.contains(platformMacOS)); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> initializeRun() async { | ||
| final List<String> platformFlags = _platforms.keys.toList(); | ||
|
|
@@ -121,6 +134,14 @@ class BuildExamplesCommand extends PackageLoopingCommand { | |
| 'were specified. At least one platform must be provided.'); | ||
| throw ToolExit(_exitNoPlatformFlags); | ||
| } | ||
|
|
||
| if (usingSwiftPackageManager) { | ||
| await processRunner.runAndStream( | ||
| flutterCommand, | ||
| <String>['config', '--enable-swift-package-manager'], | ||
| exitOnError: true, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will explode on our
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh good catch, done and validated: https://chromium-swarm.appspot.com/task?id=6929f2858af7f110 |
||
| ); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -269,6 +290,12 @@ class BuildExamplesCommand extends PackageLoopingCommand { | |
| }) async { | ||
| final String enableExperiment = getStringArg(kEnableExperiment); | ||
|
|
||
| // Clean app before building when using Swift Package Manager since this | ||
| // is the second time it's being built. | ||
| if (usingSwiftPackageManager) { | ||
| await _cleanExample(example); | ||
| } | ||
|
|
||
| final int exitCode = await processRunner.runAndStream( | ||
| flutterCommand, | ||
| <String>[ | ||
|
|
@@ -283,6 +310,19 @@ class BuildExamplesCommand extends PackageLoopingCommand { | |
| ); | ||
| return exitCode == 0; | ||
| } | ||
|
|
||
| Future<bool> _cleanExample( | ||
| RepositoryPackage example, | ||
| ) async { | ||
| final int exitCode = await processRunner.runAndStream( | ||
| flutterCommand, | ||
| <String>[ | ||
| 'clean', | ||
| ], | ||
| workingDir: example.directory, | ||
| ); | ||
| return exitCode == 0; | ||
| } | ||
| } | ||
|
|
||
| /// A collection of information related to a specific platform. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to build-all twice; there's already some redundancy in the build-all app vs individual example builds. We use that redundancy to get x64/arm64 coverage already, and I would vote for doing the same thing here.
To do that we would remove this step, and only build-all with SPM. That gives us SPM build coverage of all plugin in this step, and CocoaPods coverage in all the example app builds. Then when the flag is removed or reversed, we switch build-all to force SPM off and reverse the coverage roles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if I understand correctly, you're suggesting we update build-all (https://github.com/flutter/packages/blob/main/.ci/targets/ios_build_all_packages.yaml / https://github.com/flutter/packages/blob/main/.ci/scripts/build_all_packages_app.sh) to have SPM enabled so it builds all with SPM.
And then in platform tests (this file), only build with CocoaPods?
Just a reminder, native tests will need to be run with SPM enabled because CocoaPod testing dependencies will have been removed (see "Updating unit tests in plugin example app"), which will make native tests not be able to be run without SPM. But we can still do what you're suggesting and just add a new step to the yaml that enables SPM
packages/.ci/targets/ios_platform_tests.yaml
Lines 25 to 28 in ea572aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, I was skimming and thought this was the build-all step. But yes, thanks for figuring out what I meant despite the confusing description.
Right, I forgot about that.
I guess we could flip it around from the start, and do the SPM testing in-package, and the CocoaPod testing only in build-all (and, until the flag reaches stable, in stable post-submit). The reason I was thinking we should start the other way is that we could potentially break the example app for people who don't have the flag enabled without noticing if we only tested SPM in-package, but the impact of that if it happens is extremely small, so probably not worth worrying about unless it actually starts happening in practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the way I currently have set up, it builds the example app with the flag disabled, then it builds with the flag enabled, then it runs tests (still with the flag enabled).
So the example app builds with both the flag disabled (aka CocoaPods only) and enabled. I'm inclined to keep it this way so we can be sure the example app works both ways.
As for build-all, we could also do it twice - once with it disabled and once with it enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that adds about 5 minutes to each shard (a roughly 25-33% increase). If the only thing we get from that is coverage of an example app that almost nobody but us runs most of the time, and doesn't affect production clients, I don't think that's a good tradeoff of CI resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, then yeah I think we keep build-all using CocoaPods and do platform tests with SPM (because the example app has to be built with SPM so native tests use SPM).