Class: Precheck::Runner
- Inherits:
-
Object
- Object
- Precheck::Runner
- Defined in:
- precheck/lib/precheck/runner.rb
Instance Attribute Summary collapse
-
#spaceship ⇒ Object
Returns the value of attribute spaceship.
Instance Method Summary collapse
- #app ⇒ Object
- #build_items_not_checked_table(items_not_checked: nil) ⇒ Object
- #build_potential_problems_table(processor_result: nil) ⇒ Object
- #check_for_rule_violations(app: nil, app_version: nil) ⇒ Object
-
#ensure_app_exists! ⇒ Object
Makes sure the current App ID exists.
- #latest_app_version ⇒ Object
- #print_items_not_checked(processor_result: nil) ⇒ Object
- #rendered_failed_results_table(failed_results: nil) ⇒ Object
- #rendered_rules_checked_table(rules_checked: nil) ⇒ Object
- #rendered_skipped_rules_table(skipped_rules: nil) ⇒ Object
-
#run ⇒ Object
Uses the spaceship to download app metadata and then run all rule checkers.
Instance Attribute Details
#spaceship ⇒ Object
Returns the value of attribute spaceship.
11 12 13 |
# File 'precheck/lib/precheck/runner.rb', line 11 def spaceship @spaceship end |
Instance Method Details
#app ⇒ Object
187 188 189 |
# File 'precheck/lib/precheck/runner.rb', line 187 def app Spaceship::ConnectAPI::App.find(Precheck.config[:app_identifier]) end |
#build_items_not_checked_table(items_not_checked: nil) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'precheck/lib/precheck/runner.rb', line 174 def build_items_not_checked_table(items_not_checked: nil) rows = [] items_not_checked.each do |item| rows << [item.item_name, item.friendly_name] end return Terminal::Table.new( title: "Not analyzed".yellow, headings: ["Name", "Friendly name"], rows: FastlaneCore::PrintTable.transform_output(rows) ).to_s end |
#build_potential_problems_table(processor_result: nil) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'precheck/lib/precheck/runner.rb', line 90 def build_potential_problems_table(processor_result: nil) error_results = processor_result.error_results warning_results = processor_result.warning_results rows = [] warning_results.each do |rule, results| results.each do |result| rows << [result.item.friendly_name, result.rule_return.failure_data.yellow] end end error_results.each do |rule, results| results.each do |result| rows << [result.item.friendly_name, result.rule_return.failure_data.red] end end if rows.length == 0 return nil else title_text = "Potential problems" if error_results.length > 0 title_text = title_text.red else title_text = title_text.yellow end return Terminal::Table.new( title: title_text, headings: ["Field", "Failure reason"], rows: FastlaneCore::PrintTable.transform_output(rows) ).to_s end end |
#check_for_rule_violations(app: nil, app_version: nil) ⇒ Object
125 126 127 128 129 130 131 |
# File 'precheck/lib/precheck/runner.rb', line 125 def check_for_rule_violations(app: nil, app_version: nil) Precheck::RuleProcessor.process_app_and_version( app: app, app_version: app_version, rules: Precheck::Options.rules ) end |
#ensure_app_exists! ⇒ Object
Makes sure the current App ID exists. If not, it will show an appropriate error message
197 198 199 200 |
# File 'precheck/lib/precheck/runner.rb', line 197 def ensure_app_exists! return if app UI.user_error!("Could not find app with App Identifier '#{Precheck.config[:app_identifier]}'") end |
#latest_app_version ⇒ Object
191 192 193 194 |
# File 'precheck/lib/precheck/runner.rb', line 191 def latest_app_version platform = Spaceship::ConnectAPI::Platform.map(Precheck.config[:platform]) @latest_version ||= Precheck.config[:use_live] ? app.get_live_app_store_version(platform: platform) : app.get_latest_app_store_version(platform: platform) end |
#print_items_not_checked(processor_result: nil) ⇒ Object
85 86 87 88 |
# File 'precheck/lib/precheck/runner.rb', line 85 def print_items_not_checked(processor_result: nil) names = processor_result.items_not_checked.map(&:friendly_name) UI.("😶 Metadata fields not checked by any rule: #{names.join(', ')}".yellow) if names.length > 0 end |
#rendered_failed_results_table(failed_results: nil) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'precheck/lib/precheck/runner.rb', line 133 def rendered_failed_results_table(failed_results: nil) rows = [] failed_results.each do |failed_result| rows << [failed_result.rule.key, failed_result.item.friendly_name] end return Terminal::Table.new( title: "Failed rules".red, headings: ["Name", "App metadata field: (language code)"], rows: FastlaneCore::PrintTable.transform_output(rows) ).to_s end |
#rendered_rules_checked_table(rules_checked: nil) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'precheck/lib/precheck/runner.rb', line 146 def rendered_rules_checked_table(rules_checked: nil) rows = [] rules_checked.each do |rule| rows << [rule.key, rule.description] end return Terminal::Table.new( title: "Enabled rules".green, headings: ["Name", "Description"], rows: FastlaneCore::PrintTable.transform_output(rows) ).to_s end |
#rendered_skipped_rules_table(skipped_rules: nil) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'precheck/lib/precheck/runner.rb', line 159 def rendered_skipped_rules_table(skipped_rules: nil) return nil if skipped_rules.empty? rows = [] skipped_rules.each do |rule| rows << [rule.key, rule.description] end return Terminal::Table.new( title: "Skipped rules".yellow, headings: ["Name", "Description"], rows: FastlaneCore::PrintTable.transform_output(rows) ).to_s end |
#run ⇒ Object
Uses the spaceship to download app metadata and then run all rule checkers
14 15 16 17 18 19 20 21 22 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 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 |
# File 'precheck/lib/precheck/runner.rb', line 14 def run Precheck.config.load_configuration_file(Precheck.precheckfile_name) FastlaneCore::PrintTable.print_values(config: Precheck.config, hide_keys: [:output_path], title: "Summary for precheck #{Fastlane::VERSION}") api_token = if (token = Spaceship::ConnectAPI::Token.from(hash: Precheck.config[:api_key], filepath: Precheck.config[:api_key_path])) UI.("Creating authorization token for App Store Connect API") token elsif (token = Spaceship::ConnectAPI.token) UI.("Using existing authorization token for App Store Connect API") token end if api_token # As of 2020-09-15, App Store Connect API does not have support for IAPs yet # This means that API Key will fail if checking for IAPs. # # There is also a check in Deliver::Runner for this. # Please remove check in Deliver when the API support IAPs. if Precheck.config[:include_in_app_purchases] UI.user_error!("Precheck cannot check In-app purchases with the App Store Connect API Key (yet). Exclude In-app purchases from precheck, disable the precheck step in your build step, or use Apple ID login") end Spaceship::ConnectAPI.token = api_token elsif Spaceship::Tunes.client.nil? # Username is now optional since addition of App Store Connect API Key # Force asking for username to prompt user if not already set Precheck.config.fetch(:username, force_ask: true) # Team selection passed though FASTLANE_ITC_TEAM_ID and FASTLANE_ITC_TEAM_NAME environment variables # Prompts select team if multiple teams and none specified UI.("Starting login with user '#{Precheck.config[:username]}'") Spaceship::ConnectAPI.login(Precheck.config[:username], use_portal: false, use_tunes: true) UI.("Successfully logged in") end UI.("Checking app for precheck rule violations") ensure_app_exists! processor_result = check_for_rule_violations(app: app, app_version: latest_app_version) if processor_result.items_not_checked? print_items_not_checked(processor_result: processor_result) end if processor_result.has_errors_or_warnings? summary_table = build_potential_problems_table(processor_result: processor_result) puts(summary_table) end if processor_result.should_trigger_user_error? UI.user_error!("precheck 👮♀️ 👮 found one or more potential problems that must be addressed before submitting to review") return false end if processor_result.has_errors_or_warnings? UI.important("precheck 👮♀️ 👮 found one or more potential metadata problems, but this won't prevent fastlane from completing 👍".yellow) end if !processor_result.has_errors_or_warnings? && !processor_result.items_not_checked? UI.("precheck 👮♀️ 👮 finished without detecting any potential problems 🛫".green) end return true end |