Class: Fastlane::Actions::UploadToChecksAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/checks/actions/upload_to_checks.rb

Class Method Summary collapse

Class Method Details

.authorsObject



107
108
109
# File 'lib/fastlane/plugin/checks/actions/upload_to_checks.rb', line 107

def self.authors
  ["boertel"]
end

.available_optionsObject



120
121
122
# File 'lib/fastlane/plugin/checks/actions/upload_to_checks.rb', line 120

def self.available_options
  Fastlane::Checks::Options.available_options
end

.descriptionObject



103
104
105
# File 'lib/fastlane/plugin/checks/actions/upload_to_checks.rb', line 103

def self.description
  "upload to checks"
end

.detailsObject



115
116
117
118
# File 'lib/fastlane/plugin/checks/actions/upload_to_checks.rb', line 115

def self.details
  # Optional:
  "upload to checks your mobile app"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


124
125
126
127
128
129
130
# File 'lib/fastlane/plugin/checks/actions/upload_to_checks.rb', line 124

def self.is_supported?(platform)
  # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
  # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
  #
  # [:ios, :mac, :android].include?(platform)
  true
end

.return_valueObject



111
112
113
# File 'lib/fastlane/plugin/checks/actions/upload_to_checks.rb', line 111

def self.return_value
  # If your method provides a return value, you can describe here what it does
end

.run(params) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/fastlane/plugin/checks/actions/upload_to_checks.rb', line 30

def self.run(params) # rubocop:disable Metrics/PerceivedComplexity
  # required parameters
   = params[:service_account_file_path]
  project_id = params[:project_id]
   = params[:account_id]
  app_id = params[:app_id]
  binary_path = params[:binary_path]

  # optional parameters
  fail_on = params[:fail_on]
  operation_id = params[:operation_id]
  generate_report = params[:generate_report]
  wait_for_report = params[:wait_for_report]
  severity_threshold = params[:severity_threshold]

  credentials = Fastlane::Checks::Credentials.new(key_file_path: )
  service = Fastlane::Checks::GoogleChecksService.new(credentials, project_id, , app_id)

  if generate_report
    if operation_id.nil?
      upload_spinner = TTY::Spinner.new("[:spinner] Uploading #{binary_path} to Google Checks...", format: :dots)
      upload_spinner.auto_spin
      begin
        upload_response = service.upload_binary(binary_path)
      rescue StandardError => e
        UI.error(e)
        UI.abort_with_message!("Error while uploading binary")
      end
      upload_spinner.success("Done")
    end

    if wait_for_report == false
      UI.success("Skipping waiting for the report. Please visit https://checks.google.com to see the report.")
    else
      if operation_id.nil?
        operation_id = Fastlane::Checks::GoogleChecksService.operation_id_from_name(upload_response["name"])
      end

      waiting_spinner = TTY::Spinner.new("[:spinner] Waiting for the report for operation id=#{operation_id}", format: :dots)
      waiting_spinner.auto_spin

      report_id, operation_response = service.wait_for_report(operation_id)

      if report_id.nil?
        waiting_spinner.error("Done")
        UI.abort_with_message!("Failed to fetch the report")
      else
        waiting_spinner.success("Done")
        report_response = service.report(report_id)
        report_parser = Fastlane::Checks::ReportParser.new(severity_threshold)
        failing_checks = report_parser.parse(report_response)
        if failing_checks.empty? # rubocop:disable Metrics/BlockNesting
          UI.success("No issues  # rubocop:disable Metrics/BlockNestingdetected")
          UI.success("Report console URL: #{operation_response['response']['resultsUri']}")
        else
          UI.error("#{failing_checks.length} issues detected:")
          failing_checks.each do |check|
            UI.error("Type: #{check['type']}. Details: #{check}")
          end
          if fail_on == 'all' # rubocop:disable Metrics/BlockNesting
            UI.test_failure!("Report console URL: #{operation_response['response']['resultsUri']}")
          else
            UI.important("Report console URL: #{operation_response['response']['resultsUri']}")
          end
        end
      end
    end
  else
    response = service.apps_list
    UI.message(response)
  end
end