Open tys-ley opened 3 years ago
Good question, and an interesting (but still rather common!) scenario which I will add to the e2e tests and documentation.
tl;dr: set FLUTTER_ROOT
environment variable to something like /tmp/flutter
and this should just work (I see you're probably using it with GitHub Actions; adding FLUTTER_ROOT: "/tmp/flutter"
to job's "env" section should do the trick).
What seems to be happening here is flutter tool finding its own installation and tries to run tests for its examples... Not good. The reason is that "flutter_bootstrap" is installing flutter toolchain inside your own repository (which is arguable, but without any configuration maybe not the worst thing to do). So naturally, when flutter starts at your project's directory level and tries to recurse...
To fix it, the best way is to pin Flutter to a specific version. This isn't supported by Flutter core today, but it's trivial to do with git submodules. A common name for submodule (also one used by flutterw) is .flutter
directory inside your application's folder. I think that flutter toolchain purposefully ignores dot-files and thus does not descend into ~madness~ recursion of its own installation.
If you don't want to mess with submodules, it's also okay to put Flutter anywhere else outside the repo. If you're using "flutter_bootstrap" action, there's no need to preinstall flutter. Just set FLUTTER_ROOT
to some temporary directory and you should be good to go. If you already have flutter installed, e.g. with flutter-action, and your PATH
contains a path to flutter
executable, the plugin will autodetect it.
On a related note, there's already a fix in this repo's head which would eliminate the need for extra configuration. I'll need to add some tests and release 0.7.0 later this week, no environment variables will be necessary from that point on.
Updating the plugin should resolve this problem now.
Hi,
Thanks for your fast response and sorry for my late reply. I tried it and it works partially.
I need Dir.chdir("..")
before running the tests, due to the wrong directory. The current directory is the android
directory not the project root directory where the flutter tests are located.
Dir.chdir("..")
flutter(args: ["test"])
But when i try to call flutter(args: ["test", "--coverage"])
i get Could not find a command named "test --coverage".
Thanks in advance.
Regarding Dir.chdir
: may I ask where the Fastfile
is located, relative to the flutter's test
directory of the project?
E.g. my project directory structure is usually:
as for the flutter(args: ["test", "--coverage"])
line, I have tested it on my side and couldn't reproduce the problem. Would you like to share your Gemfile.lock
so I can check the versions?
My project structure is different from yours. I did my fastlane setup according to this manual and this project.
source "https://rubygems.org" gem "fastlane" plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') eval_gemfile(plugins_path) if File.exist?(plugins_path)
GEM remote: https://rubygems.org/ specs: CFPropertyList (3.0.4) rexml addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) artifactory (3.0.15) atomos (0.1.3) aws-eventstream (1.2.0) aws-partitions (1.507.0) aws-sdk-core (3.121.1) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) aws-sdk-kms (1.48.0) aws-sdk-core (~> 3, >= 3.120.0) aws-sigv4 (~> 1.1) aws-sdk-s3 (1.103.0) aws-sdk-core (~> 3, >= 3.120.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.4) aws-sigv4 (1.4.0) aws-eventstream (~> 1, >= 1.0.2) babosa (1.0.4) claide (1.0.3) colored (1.2) colored2 (3.1.2) commander (4.6.0) highline (~> 2.0.0) declarative (0.0.20) digest-crc (0.6.4) rake (>= 12.0.0, < 14.0.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) dotenv (2.7.6) emoji_regex (3.2.2) excon (0.85.0) faraday (1.8.0) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) faraday-httpclient (~> 1.0.1) faraday-net_http (~> 1.0) faraday-net_http_persistent (~> 1.1) faraday-patron (~> 1.0) faraday-rack (~> 1.0) multipart-post (>= 1.2, < 3) ruby2_keywords (>= 0.0.4) faraday-cookie_jar (0.0.7) faraday (>= 0.8.0) http-cookie (~> 1.0.0) faraday-em_http (1.0.0) faraday-em_synchrony (1.0.0) faraday-excon (1.1.0) faraday-httpclient (1.0.1) faraday-net_http (1.0.1) faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) faraday-rack (1.0.0) faraday_middleware (1.1.0) faraday (~> 1.0) fastimage (2.2.5) fastlane (2.195.0) CFPropertyList (>= 2.3, < 4.0.0) addressable (>= 2.8, < 3.0.0) artifactory (~> 3.0) aws-sdk-s3 (~> 1.0) babosa (>= 1.0.3, < 2.0.0) bundler (>= 1.12.0, < 3.0.0) colored commander (~> 4.6) dotenv (>= 2.1.1, < 3.0.0) emoji_regex (>= 0.1, < 4.0) excon (>= 0.71.0, < 1.0.0) faraday (~> 1.0) faraday-cookie_jar (~> 0.0.6) faraday_middleware (~> 1.0) fastimage (>= 2.1.0, < 3.0.0) gh_inspector (>= 1.1.2, < 2.0.0) google-apis-androidpublisher_v3 (~> 0.3) google-apis-playcustomapp_v1 (~> 0.1) google-cloud-storage (~> 1.31) highline (~> 2.0) json (< 3.0.0) jwt (>= 2.1.0, < 3) mini_magick (>= 4.9.4, < 5.0.0) multipart-post (~> 2.0.0) naturally (~> 2.2) optparse (~> 0.1.1) plist (>= 3.1.0, < 4.0.0) rubyzip (>= 2.0.0, < 3.0.0) security (= 0.1.3) simctl (~> 1.6.3) terminal-notifier (>= 2.0.0, < 3.0.0) terminal-table (>= 1.4.5, < 2.0.0) tty-screen (>= 0.6.3, < 1.0.0) tty-spinner (>= 0.8.0, < 1.0.0) word_wrap (~> 1.0.0) xcodeproj (>= 1.13.0, < 2.0.0) xcpretty (~> 0.3.0) xcpretty-travis-formatter (>= 0.0.3) fastlane-plugin-flutter (0.7.0) gh_inspector (1.1.3) google-apis-androidpublisher_v3 (0.11.0) google-apis-core (>= 0.4, < 2.a) google-apis-core (0.4.1) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) httpclient (>= 2.8.1, < 3.a) mini_mime (~> 1.0) representable (~> 3.0) retriable (>= 2.0, < 4.a) rexml webrick google-apis-iamcredentials_v1 (0.7.0) google-apis-core (>= 0.4, < 2.a) google-apis-playcustomapp_v1 (0.5.0) google-apis-core (>= 0.4, < 2.a) google-apis-storage_v1 (0.8.0) google-apis-core (>= 0.4, < 2.a) google-cloud-core (1.6.0) google-cloud-env (~> 1.0) google-cloud-errors (~> 1.0) google-cloud-env (1.5.0) faraday (>= 0.17.3, < 2.0) google-cloud-errors (1.2.0) google-cloud-storage (1.34.1) addressable (~> 2.5) digest-crc (~> 0.4) google-apis-iamcredentials_v1 (~> 0.1) google-apis-storage_v1 (~> 0.1) google-cloud-core (~> 1.6) googleauth (>= 0.16.2, < 2.a) mini_mime (~> 1.0) googleauth (0.17.1) faraday (>= 0.17.3, < 2.0) jwt (>= 1.4, < 3.0) memoist (~> 0.16) multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (~> 0.15) highline (2.0.3) http-cookie (1.0.4) domain_name (~> 0.5) httpclient (2.8.3) jmespath (1.4.0) json (2.5.1) jwt (2.2.3) memoist (0.16.2) mini_magick (4.11.0) mini_mime (1.1.1) multi_json (1.15.0) multipart-post (2.0.0) nanaimo (0.3.0) naturally (2.2.1) optparse (0.1.1) os (1.1.1) plist (3.6.0) public_suffix (4.0.6) rake (13.0.6) representable (3.1.1) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) retriable (3.1.2) rexml (3.2.5) rouge (2.0.7) ruby2_keywords (0.0.5) rubyzip (2.3.2) security (0.1.3) signet (0.16.0) addressable (~> 2.8) faraday (>= 0.17.3, < 2.0) jwt (>= 1.5, < 3.0) multi_json (~> 1.10) simctl (1.6.8) CFPropertyList naturally terminal-notifier (2.0.0) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) trailblazer-option (0.1.1) tty-cursor (0.7.1) tty-screen (0.8.1) tty-spinner (0.9.3) tty-cursor (~> 0.7) uber (0.1.0) unf (0.1.4) unf_ext unf_ext (0.0.8-x64-mingw32) unicode-display_width (1.8.0) webrick (1.7.0) word_wrap (1.0.0) xcodeproj (1.21.0) CFPropertyList (>= 2.3.3, < 4.0) atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) nanaimo (~> 0.3.0) rexml (~> 3.2.4) xcpretty (0.3.0) rouge (~> 2.0.7) xcpretty-travis-formatter (1.0.1) xcpretty (~> 0.2, >= 0.0.7) PLATFORMS x64-mingw32 DEPENDENCIES fastlane fastlane-plugin-flutter BUNDLED WITH 2.2.28
running bundle exec fastlane init
at my root folder(myExampleFlutterProject
) results in
[✔] Looking for iOS and Android projects in current directory...
[21:38:09]: It looks like there is no iOS project in the current directory, though we did find one in a sub-directory
[21:38:09]: Please `cd` into the directory of the intended Xcode project you wish to use.
[!] Please `cd` into the directory of the intended Xcode project you wish to use and run `fastlane init` again
The manual is legit, but my opinion is that it's heavily optimized towards very fast and easy initial setup, but not for long-term maintenance. In my case because of my background (few years of ruby + deep interest in CI) I have picked a different path, resorting to understanding how fastlane works with ios and android individually, increasing the learning curve but resulting in a more concise, easier to maintain configuration. Dir.chdir('..')
is only one of the things which will have to stay if you want to keep the structure suggested by the Flutter team. And again, it's not a bad structure, but it requires more maintenance for sure (think at least remembering that your Flutter fastlane config is in "android" directory, and also updating two fastlane gemfiles!)
But since this setup is so common, I can try to handle it as well (e.g. detect that current directory is named "android"
or "ios"
? Other ideas?).
Now to the more important issue... I have compared the versions and we are using the same fastlane. It's puzzling how the behavior is so different, but two ideas:
bundle exec fastlane run flutter args:test,--coverage
in the "android" directory? It's supposed to fail, but I wonder what error message you'll get.I like your approach in heaving it centralized in the root directory. could you elaborate more on how I can set this up or do you know a blogpost? I am planning to build an iOS and a web application too, so I try to make it as easy to maintain as possible.
Due to the fact, that I am quite new to the fastlane tool, you probably know better what is the best approach. But detecting the current directory should be sufficient.
Regarding 1, no, I don't have a lane named "flutter".
But I just saw, that flutter(args: ["test", "--coverage"])
is working when i use Dir.chdir("..")
in the line above. Sorry for the confusion.
default_platform(:android) platform :android do lane :bootstrap do flutter_bootstrap( flutter_channel: 'stable', android_licenses: { 'android-sdk-license' => '24333f8a63b6825ea9c5514f83c2829b004d1fee', }, ) end end platform :android do desc "Run tests, build and deploy to Google Play" lane :test_and_deploy do |options| test_only build_flutter_app deploy_to(track: options[:track]) end desc "Run only tests" lane :test_only do bootstrap run_flutter_analyze run_flutter_tests end desc "Runs flutter analyze" lane :run_flutter_analyze do flutter(args: %w(analyze)) end desc "Runs all the tests" lane :run_flutter_tests do Dir.chdir("..") flutter(args: ["test", "--coverage"]) end desc "Build Flutter App" lane :build_flutter_app do gi = google_play_track_version_codes(track: 'internal') version_updated = gi[0].to_i + 1 puts version_updated if(FastlaneCore::Helper.operating_system == "Linux") sh("export BUILD_NUMBER = \"#{version_updated.to_s}\"") end output_file = flutter_build( debug: false, build: 'appbundle', build_number: version_updated, build_name: 'Demo Skeleton App', ) UI.success("Built #{output_file}!") end desc "Deploy to internal test on Google Play" lane :deploy_to do |options| upload_to_play_store( track: options[:track], aab: '../build/app/outputs/bundle/release/app-release.aab', release_status: 'draft', ) end end
Here is the output from executing bundle exec fastlane run flutter args:test,--coverage
.
PS myFlutterProject\android> bundle exec fastlane run flutter args:test,--coverage
[✔] 🚀
+-------------------------+---------+---------------------------------+
| Used plugins |
+-------------------------+---------+---------------------------------+
| Plugin | Version | Action |
+-------------------------+---------+---------------------------------+
| fastlane-plugin-flutter | 0.7.0 | flutter, flutter_bootstrap, |
| | | flutter_build, flutter_generate |
+-------------------------+---------+---------------------------------+
[00:02:13]: ---------------------
[00:02:13]: --- Step: flutter ---
[00:02:13]: ---------------------
[00:02:13]: Determined Flutter location as C:\flutter because 'flutter' executable in PATH is located there (current directory is myFlutterProject/android).
[00:02:13]: $ C:/flutter/bin/flutter test --coverage
Looking for related GitHub issues on fastlane/fastlane...
➡️ Specify IPA path as a parameter to deliver beta
https://github.com/fastlane/fastlane/issues/244 [closed] 2 💬
22 Sep 2016
➡️ commit_version_bump error in-spite of expected and actual changes being same
https://github.com/fastlane/fastlane/issues/248 [closed] 2 💬
22 Sep 2016
➡️ Sigh: Lane specific `team_id` and `app_identifier` not used
https://github.com/fastlane/fastlane/issues/256 [closed] 23 💬
22 Sep 2016
and 18463 more at: https://github.com/fastlane/fastlane/search?q=The%20following%20command%20has%20failed%3A%0A%0A%24%20C%3A%2Fflutter%2Fbin%2Fflutter%20test%20--coverage%0A%5Bpid%208152%20exit%201%5D%0A%0ATest%20directory%20%22test%22%20not%20found.%0A%0A&type=Issues&utf8=✓
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane_core/lib/fastlane_core/ui/interface.rb:153:in `shell_error!': \e[31m[!] The following command has failed: (FastlaneCore::Interface::FastlaneShellError)
$ C:/flutter/bin/flutter test --coverage
[pid 8152 exit 1]
Test directory "test" not found.
\e[0m
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane_core/lib/fastlane_core/ui/ui.rb:17:in `method_missing'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-plugin-flutter-0.7.0/lib/fastlane/plugin/flutter/helper/flutter_helper.rb:105:in `block in execute'
from C:/Ruby30-x64/lib/ruby/3.0.0/open3.rb:227:in `popen_run'
from C:/Ruby30-x64/lib/ruby/3.0.0/open3.rb:102:in `popen3'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-plugin-flutter-0.7.0/lib/fastlane/plugin/flutter/helper/flutter_helper.rb:91:in `execute'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-plugin-flutter-0.7.0/lib/fastlane/plugin/flutter/helper/flutter_helper.rb:8:in `flutter'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-plugin-flutter-0.7.0/lib/fastlane/plugin/flutter/actions/flutter_action.rb:16:in `run'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/runner.rb:263:in `block (2 levels) in execute_action'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/actions/actions_helper.rb:69:in `execute_action'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/runner.rb:255:in `block in execute_action'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/runner.rb:229:in `chdir'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/runner.rb:229:in `execute_action'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/one_off.rb:42:in `run'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/one_off.rb:22:in `execute'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/commands_generator.rb:225:in `block (2 levels) in run'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/commander-4.6.0/lib/commander/command.rb:187:in `call'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/commander-4.6.0/lib/commander/command.rb:157:in `run'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/commander-4.6.0/lib/commander/runner.rb:444:in `run_active_command'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:117:in `run!'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/commander-4.6.0/lib/commander/delegates.rb:18:in `run!'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/commands_generator.rb:353:in `run'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/commands_generator.rb:42:in `start'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/cli_tools_distributor.rb:122:in `take_off'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/bin/fastlane:23:in `<top (required)>'
from C:/Ruby30-x64/bin/fastlane:23:in `load'
from C:/Ruby30-x64/bin/fastlane:23:in `<main>'
C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane_core/lib/fastlane_core/ui/interface.rb:153:in `shell_error!': The following command has failed: (FastlaneCore::Interface::FastlaneShellError)
$ C:/flutter/bin/flutter test --coverage
[pid 8152 exit 1]
Test directory "test" not found.
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane_core/lib/fastlane_core/ui/ui.rb:17:in `method_missing'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-plugin-flutter-0.7.0/lib/fastlane/plugin/flutter/helper/flutter_helper.rb:105:in `block in execute'
from C:/Ruby30-x64/lib/ruby/3.0.0/open3.rb:227:in `popen_run'
from C:/Ruby30-x64/lib/ruby/3.0.0/open3.rb:102:in `popen3'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-plugin-flutter-0.7.0/lib/fastlane/plugin/flutter/helper/flutter_helper.rb:91:in `execute'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-plugin-flutter-0.7.0/lib/fastlane/plugin/flutter/helper/flutter_helper.rb:8:in `flutter'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-plugin-flutter-0.7.0/lib/fastlane/plugin/flutter/actions/flutter_action.rb:16:in `run'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/runner.rb:263:in `block (2 levels) in execute_action'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/actions/actions_helper.rb:69:in `execute_action'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/runner.rb:255:in `block in execute_action'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/runner.rb:229:in `chdir'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/runner.rb:229:in `execute_action'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/one_off.rb:42:in `run'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/one_off.rb:22:in `execute'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/commands_generator.rb:225:in `block (2 levels) in run'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/commander-4.6.0/lib/commander/command.rb:187:in `call'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/commander-4.6.0/lib/commander/command.rb:157:in `run'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/commander-4.6.0/lib/commander/runner.rb:444:in `run_active_command'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:117:in `run!'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/commander-4.6.0/lib/commander/delegates.rb:18:in `run!'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/commands_generator.rb:353:in `run'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/commands_generator.rb:42:in `start'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/fastlane/lib/fastlane/cli_tools_distributor.rb:122:in `take_off'
from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/fastlane-2.195.0/bin/fastlane:23:in `<top (required)>'
from C:/Ruby30-x64/bin/fastlane:23:in `load'
from C:/Ruby30-x64/bin/fastlane:23:in `<main>'
Hi,
I tried running my
flutter test
suite. withflutter(args: %w(test))
andflutter(args: %w(test ..))
But all of them failed with this strange error messages:
How can I run my tests?