Class: Fastlane::FirebaseTestRunner
- Inherits:
-
Object
- Object
- Fastlane::FirebaseTestRunner
- Defined in:
- lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb
Constant Summary collapse
- VALID_TEST_TYPES =
%w[instrumentation robo].freeze
Class Method Summary collapse
-
.download_file(file:, destination:) ⇒ Object
Download a Google Cloud Storage file to the local machine, creating intermediate directories as needed.
-
.download_result_files(result:, destination:, project_id:, key_file_path:) ⇒ Object
Downloads all files associated with a Firebase Test Run to the local machine.
- .preflight(verify_gcloud_binary: true, verify_logged_in: true) ⇒ Object
-
.run_tests(project_id:, apk_path:, test_apk_path:, device:, test_targets: nil, type: 'instrumentation') ⇒ Object
Run a given APK and Test Bundle on the given device type.
- .verify_has_gcloud_binary! ⇒ Object
- .verify_logged_in! ⇒ Object
Class Method Details
.download_file(file:, destination:) ⇒ Object
Download a Google Cloud Storage file to the local machine, creating intermediate directories as needed.
85 86 87 88 89 90 91 92 93 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb', line 85 def self.download_file(file:, destination:) destination = File.join(destination, file.name) FileUtils.mkdir_p(File.dirname(destination)) # Print our progress UI.(file.name) file.download(destination) end |
.download_result_files(result:, destination:, project_id:, key_file_path:) ⇒ Object
Downloads all files associated with a Firebase Test Run to the local machine.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb', line 58 def self.download_result_files(result:, destination:, project_id:, key_file_path:) UI.user_error! 'You must pass a `FirebaseTestLabResult` to this method' unless result.is_a? Fastlane::FirebaseTestLabResult paths = result.raw_results_paths UI.user_error! "Log File doesn't contain a raw results URL" if paths.nil? FileUtils.mkdir_p(destination) unless File.directory?(destination) storage = Google::Cloud::Storage.new( project_id: project_id, credentials: key_file_path ) # Set up the download bucket = storage.bucket(paths[:bucket]) files_to_download = bucket.files(prefix: paths[:prefix]) # Download the files UI.header "Downloading Results Files to #{destination}" files_to_download.each { |file| download_file(file: file, destination: destination) } end |
.preflight(verify_gcloud_binary: true, verify_logged_in: true) ⇒ Object
10 11 12 13 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb', line 10 def self.preflight(verify_gcloud_binary: true, verify_logged_in: true) verify_has_gcloud_binary! if verify_gcloud_binary verify_logged_in! if verify_logged_in end |
.run_tests(project_id:, apk_path:, test_apk_path:, device:, test_targets: nil, type: 'instrumentation') ⇒ Object
Run a given APK and Test Bundle on the given device type.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb', line 23 def self.run_tests(project_id:, apk_path:, test_apk_path:, device:, test_targets: nil, type: 'instrumentation') raise "Unable to find apk: #{apk_path}" unless File.file?(apk_path) raise "Unable to find apk: #{test_apk_path}" unless File.file?(test_apk_path) raise "Invalid Type: #{type}" unless VALID_TEST_TYPES.include?(type) params = { project: project_id, type: type, app: apk_path, test: test_apk_path, 'test-targets': test_targets, device: device.to_s, verbosity: 'info' }.compact.flat_map { |k, v| ["--#{k}", v] } command = Shellwords.join(['gcloud', 'firebase', 'test', 'android', 'run', *params]) log_file_path = Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE_PATH] UI. "Streaming log output to #{log_file_path}" Action.sh("#{command} 2>&1 | tee #{log_file_path}") # Make the file object available to other tasks result = FirebaseTestLabResult.new(log_file_path: log_file_path) Fastlane::Actions.lane_context[:FIREBASE_TEST_LOG_FILE] = result result end |
.verify_has_gcloud_binary! ⇒ Object
95 96 97 98 99 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb', line 95 def self.verify_has_gcloud_binary! Action.sh('command', '-v', 'gcloud', print_command: false, print_command_output: false) rescue StandardError UI.user_error!("The `gcloud` binary isn't available on this machine. Unable to continue.") end |
.verify_logged_in! ⇒ Object
101 102 103 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/models/firebase_test_runner.rb', line 101 def self.verify_logged_in! UI.user_error!('You are not logged into Firebase on this machine. Unable to continue.') unless FirebaseAccount.authenticated? end |