Class: FirebaseTestLabIntegration::Helper::GcloudHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/firebase_test_lab_integration/helper/gcloud_helper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform, project_id, gcloud_key_file, gcloud_channel, results_bucket, results_dir, log_file_name, download_dir, timeout, quiet) ⇒ GcloudHelper



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fastlane/plugin/firebase_test_lab_integration/helper/gcloud_helper.rb', line 11

def initialize(platform, project_id, gcloud_key_file, gcloud_channel, results_bucket, results_dir, log_file_name, download_dir, timeout, quiet)
  @platform = platform
  @project_id = project_id
  @gcloud_key_file = gcloud_key_file
  @gcloud_channel = gcloud_channel
  @results_bucket = results_bucket || "#{project_id}_firebase_testlab"
  @results_dir = results_dir
  @log_file_name = log_file_name
  @download_dir = download_dir
  @timeout = timeout
  @quiet = quiet

  self.authenticate
end

Instance Attribute Details

#results_bucketObject (readonly)

Returns the value of attribute results_bucket.



9
10
11
# File 'lib/fastlane/plugin/firebase_test_lab_integration/helper/gcloud_helper.rb', line 9

def results_bucket
  @results_bucket
end

#results_dirObject (readonly)

Returns the value of attribute results_dir.



9
10
11
# File 'lib/fastlane/plugin/firebase_test_lab_integration/helper/gcloud_helper.rb', line 9

def results_dir
  @results_dir
end

Class Method Details

.firebase_test_lab_history_url(project_id) ⇒ Object



68
69
70
# File 'lib/fastlane/plugin/firebase_test_lab_integration/helper/gcloud_helper.rb', line 68

def self.firebase_test_lab_history_url(project_id)
  "https://console.firebase.google.com/u/0/project/#{project_id}/testlab/histories/"
end

.gcloud_bucket_object_url(bucket, path) ⇒ Object



64
65
66
# File 'lib/fastlane/plugin/firebase_test_lab_integration/helper/gcloud_helper.rb', line 64

def self.gcloud_bucket_object_url(bucket, path)
  "https://storage.googleapis.com/#{bucket}/#{CGI.escape(path)}"
end

.gcloud_result_bucket_url(bucket, dir) ⇒ Object



60
61
62
# File 'lib/fastlane/plugin/firebase_test_lab_integration/helper/gcloud_helper.rb', line 60

def self.gcloud_result_bucket_url(bucket, dir)
  "https://console.developers.google.com/storage/browser/#{bucket}/#{CGI.escape(dir)}"
end

Instance Method Details

#authenticateObject

Performs gcloud authentication and project setup



73
74
75
76
77
78
79
80
81
# File 'lib/fastlane/plugin/firebase_test_lab_integration/helper/gcloud_helper.rb', line 73

def authenticate
  FastlaneCore::UI.message("Configuring GCP project.")
  Fastlane::Action.sh("gcloud config set project #{@project_id}")
  FastlaneCore::UI.message("Configured GCP project.")

  FastlaneCore::UI.message("Authenticating with GCP.")
  Fastlane::Action.sh("gcloud auth activate-service-account --key-file #{@gcloud_key_file} #{'--no-user-output-enabled' if @quiet}")
  FastlaneCore::UI.message("Authenticated with GCP.")
end

#download_test_resultsObject

This method is one that perfroms the core action of downloading the test results from Firebase Test Lab that were uploaded to Google Cloud Storage It also sets results as public to be accessible from outside It also returns the URL to the results to be used in Github PR comment



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/fastlane/plugin/firebase_test_lab_integration/helper/gcloud_helper.rb', line 45

def download_test_results
  if @download_dir
    FastlaneCore::UI.message("Fetch results from Firebase Test Lab results bucket")
    json = JSON.parse(File.read(@log_file_name))
    json.each do |status|
      axis = status["axis_value"]
      generate_directory("#{@download_dir}/#{axis}")
      download_from_gc_storage("#{@results_bucket}/#{@results_dir}/#{axis}", @download_dir)
      gcloud_storage_path_public("#{@results_bucket}/#{@results_dir}/#{axis}")
    end
  else
    FastlaneCore::UI.message("Not fetching results from Firebase Test Lab results bucket")
  end
end

#run_tests(type, app_path, app_path_test, devices, extra_options) ⇒ Object

This method is one that perfroms the core action of running the test suite on Firebase Test Lab



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fastlane/plugin/firebase_test_lab_integration/helper/gcloud_helper.rb', line 27

def run_tests(type, app_path, app_path_test, devices, extra_options)
  FastlaneCore::UI.message("Running tests.")
  arguments = "#{"--type #{type} " unless type.nil?}" \
              "#{"--app #{app_path} " unless app_path.nil?}" \
              "#{"--test #{app_path_test} " unless app_path_test.nil?}" \
              "#{devices.map { |d| "--device model=#{d[:model]},version=#{d[:version]},locale=#{d[:locale]},orientation=#{d[:orientation]} " }.join}" \
              "--timeout #{@timeout} " \
              "--results-bucket #{@results_bucket} " \
              "--results-dir #{@results_dir} " \
              "#{extra_options} " \
              "--format=json 1>#{generate_directory(@log_file_name)}"
  Fastlane::Action.sh("set +e; gcloud #{@gcloud_channel unless @gcloud_channel == 'stable'} firebase test #{@platform} run #{arguments}; set -e")
  FastlaneCore::UI.message("Testing completed.")
end