Module: Fastlane::Helper

Defined in:
lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb

Class Method Summary collapse

Class Method Details

.authenticate(gcloud_key_file) ⇒ Object



30
31
32
33
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 30

def self.authenticate(gcloud_key_file)
  UI.message "Authenticate with GCP"
  Action.sh("gcloud auth activate-service-account --key-file #{gcloud_key_file}")
end

.config(project_id) ⇒ Object



25
26
27
28
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 25

def self.config(project_id)
  UI.message "Set Google Cloud target project"
  Action.sh("gcloud config set project #{project_id}")
end

.copy_from_gcs(bucket_and_path, copy_to) ⇒ Object



41
42
43
44
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 41

def self.copy_from_gcs(bucket_and_path, copy_to)
  UI.message("Copy from gs://#{bucket_and_path}")
  Action.sh("gsutil -m cp -r gs://#{bucket_and_path} #{copy_to}")
end

.emoji_status(outcome) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 70

def self.emoji_status(outcome)
  # Github emoji list
  # https://github.com/ikatyang/emoji-cheat-sheet
  return case outcome
         when PASSED
           ":tada:"
         when FAILED
           ":fire:"
         when INCONCLUSIVE
           ":warning:"
         when SKIPPED
           ":expressionless:"
         else
           ":question:"
         end
end

.firebase_test_lab_histories_url(project_id) ⇒ Object



21
22
23
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 21

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

.gcs_object_url(bucket, path) ⇒ Object



17
18
19
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 17

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

.gcs_result_bucket_url(bucket, dir) ⇒ Object



13
14
15
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 13

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

.if_need_dir(path) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 55

def self.if_need_dir(path)
  dirname = File.dirname(path)
  unless File.directory?(dirname)
    UI.message("Crate directory: #{dirname}")
    FileUtils.mkdir_p(dirname)
  end
  path
end

.is_failure(outcome) ⇒ Object



51
52
53
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 51

def self.is_failure(outcome)
  outcome == FAILED || outcome == INCONCLUSIVE
end

.make_github_text(json, project_id, bucket, dir, test_type) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 113

def self.make_github_text(json, project_id, bucket, dir, test_type)
  prefix = "<img src=\"https://github.com/cats-oss/fastlane-plugin-firebase_test_lab_android/blob/master/art/firebase_test_lab_logo.png?raw=true\" width=\"65%\" loading=\"lazy\" />"
  cells = json.map { |data|
    axis = data["axis_value"]
    device = split_device_name(axis)
    outcome = data["outcome"]
    status = "#{emoji_status(outcome)} #{outcome}"
    message = data["test_details"]
    logcat = "<a href=\"#{gcs_object_url(bucket, "#{dir}/#{axis}/logcat")}\" target=\"_blank\" >#{random_emoji_cat}</a>"
    if test_type == "robo"
      sitemp = "<img src=\"#{gcs_object_url(bucket, "#{dir}/#{axis}/artifacts/sitemap.png")}\" height=\"64px\" loading=\"lazy\" target=\"_blank\" />"
    else
      sitemp = "--"
    end

    "| **#{device}** | #{status} | #{message} | #{logcat} | #{sitemp} |\n"
  }.inject(&:+)
  comment = <<~EOS
    #{prefix}

    ### Results
    Firebase console: [#{project_id}](#{Helper.firebase_test_lab_histories_url(project_id)})
    Test results: [#{dir}](#{Helper.gcs_result_bucket_url(bucket, dir)})

    | :iphone: Device | :thermometer: Status | :memo: Message | :eyes: Logcat | :japan: Sitemap |
    | --- | :---: | --- | :---: | :---: |
    #{cells}
  EOS
  return prefix, comment
end

.make_slack_text(json) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 93

def self.make_slack_text(json)
  success = true
  json.each do |status|
    success = !is_failure(status["outcome"])
    break unless success
  end

  body = json.map { |status|
    outcome = status["outcome"]
    emoji = emoji_status(outcome)
    device = split_device_name(status["axis_value"])
    "#{device}: #{emoji} #{outcome}\n"
  }.inject(&:+)
  return success, body
end

.random_emoji_catObject



87
88
89
90
91
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 87

def self.random_emoji_cat
  # Github emoji list
  # https://github.com/ikatyang/emoji-cheat-sheet#cat-face
  %w(:smiley_cat: :smile_cat: :joy_cat: :heart_eyes_cat: :smirk_cat: :kissing_cat:).sample
end

.run_tests(arguments) ⇒ Object



35
36
37
38
39
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 35

def self.run_tests(arguments)
  UI.message("Test running...")
#       Action.sh("set +e; gcloud #{gcloud_components_channel unless gcloud_components_channel == "stable"} firebase test android run #{arguments}; set -e")
  Action.sh("set +e; gcloud stable firebase test android run #{arguments}; set -e")
end

.set_public(bucket_and_path) ⇒ Object



46
47
48
49
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 46

def self.set_public(bucket_and_path)
  UI.message("Set public for reading gs://#{bucket_and_path}")
  Action.sh("gsutil -m acl -r set public-read gs://#{bucket_and_path}")
end

.split_device_name(axis_value) ⇒ Object



64
65
66
67
68
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 64

def self.split_device_name(axis_value)
  # Sample Nexus6P-23-ja_JP-portrait
  array = axis_value.split("-")
  "#{array[0]} (API #{array[1]})"
end

.swit_body_text(body_text) ⇒ Object



109
110
111
# File 'lib/fastlane/plugin/android_testlab_script_swit/helper/android_testlab_script_swit_helper.rb', line 109

def self.swit_body_text(body_text)

end