Class: FastlaneCore::UpdateChecker
- Inherits:
-
Object
- Object
- FastlaneCore::UpdateChecker
- Defined in:
- lib/fastlane_core/update_checker.rb
Overview
Verifies, the user runs the latest version of this gem
Constant Summary collapse
- UPDATE_URL =
This web service is fully open source: github.com/fastlane/refresher
"https://fastlane-refresher.herokuapp.com/"
Class Method Summary collapse
- .fetch_latest(url) ⇒ Object
- .finished_running(gem_name) ⇒ Object
-
.generate_fetch_url(gem_name) ⇒ Object
Generate the URL on the main thread (since we’re switching directory).
-
.p_hash ⇒ Object
To not count the same projects multiple time for the number of launches More information: github.com/fastlane/refresher Use the ‘FASTLANE_OPT_OUT_USAGE` variable to opt out The resulting value is e.g.
- .server_results ⇒ Object
- .show_update_message(gem_name, current_version) ⇒ Object
- .show_update_status(gem_name, current_version) ⇒ Object
- .start_looking_for_update(gem_name) ⇒ Object
- .update_available?(gem_name, current_version) ⇒ Boolean
Class Method Details
.fetch_latest(url) ⇒ Object
69 70 71 |
# File 'lib/fastlane_core/update_checker.rb', line 69 def self.fetch_latest(url) JSON.parse(Excon.post(url).body).fetch("version", nil) end |
.finished_running(gem_name) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/fastlane_core/update_checker.rb', line 73 def self.finished_running(gem_name) time = (Time.now - @start_time).to_i url = UPDATE_URL + "time/#{gem_name}" url += "?time=#{time}" url += "&ci=1" if Helper.is_ci? Excon.post(url) end |
.generate_fetch_url(gem_name) ⇒ Object
Generate the URL on the main thread (since we’re switching directory)
60 61 62 63 64 65 66 67 |
# File 'lib/fastlane_core/update_checker.rb', line 60 def self.generate_fetch_url(gem_name) url = UPDATE_URL + gem_name params = {} params["ci"] = "1" if Helper.is_ci? params["p_hash"] = p_hash if p_hash url += "?" + URI.encode_www_form(params) if params.count > 0 return url end |
.p_hash ⇒ Object
To not count the same projects multiple time for the number of launches More information: github.com/fastlane/refresher Use the ‘FASTLANE_OPT_OUT_USAGE` variable to opt out The resulting value is e.g. ce12f8371df11ef6097a83bdf2303e4357d6f5040acc4f76019489fa5deeae0d
86 87 88 89 90 91 92 93 94 |
# File 'lib/fastlane_core/update_checker.rb', line 86 def self.p_hash return nil if ENV["FASTLANE_OPT_OUT_USAGE"] require 'credentials_manager' value = CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier) return Digest::SHA256.hexdigest("p" + value + "fastlan3_SAlt") if value # hashed + salted the bundle identifier return nil rescue return nil end |
.server_results ⇒ Object
25 26 27 |
# File 'lib/fastlane_core/update_checker.rb', line 25 def self.server_results @@results ||= {} end |
.show_update_message(gem_name, current_version) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fastlane_core/update_checker.rb', line 48 def self.(gem_name, current_version) available = server_results[gem_name] puts "" puts '#######################################################################'.green puts "# #{gem_name} #{available} is available. You are on #{current_version}.".green puts "# It is recommended to use the latest version.".green puts "# Update using 'sudo gem update #{gem_name.downcase}'.".green puts "# To see what's new, open https://github.com/KrauseFx/#{gem_name}/releases.".green puts '#######################################################################'.green end |
.show_update_status(gem_name, current_version) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fastlane_core/update_checker.rb', line 34 def self.show_update_status(gem_name, current_version) fork do begin finished_running(gem_name) rescue # we don't want to show a stack trace if something goes wrong end end if update_available?(gem_name, current_version) (gem_name, current_version) end end |
.start_looking_for_update(gem_name) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/fastlane_core/update_checker.rb', line 10 def self.start_looking_for_update(gem_name) return if Helper.is_test? return if ENV["FASTLANE_SKIP_UPDATE_CHECK"] @start_time = Time.now url = generate_fetch_url(gem_name) Thread.new do begin server_results[gem_name] = fetch_latest(url) rescue end end end |
.update_available?(gem_name, current_version) ⇒ Boolean
29 30 31 32 |
# File 'lib/fastlane_core/update_checker.rb', line 29 def self.update_available?(gem_name, current_version) latest = server_results[gem_name] return (latest and Gem::Version.new(latest) > Gem::Version.new(current_version)) end |