Class: Fastlane::Helper::WaldoHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::WaldoHelper
- Defined in:
- lib/fastlane/plugin/waldo/helper/waldo_helper.rb
Class Method Summary collapse
- .determine_asset_name ⇒ Object
- .download(uri, path, retryAllowed) ⇒ Object
- .download_binary ⇒ Object
- .extract_build_id(output) ⇒ Object
- .filter_parameters(in_params) ⇒ Object
- .shouldRetry?(response) ⇒ Boolean
- .upload_build(params) ⇒ Object
Class Method Details
.determine_asset_name ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fastlane/plugin/waldo/helper/waldo_helper.rb', line 7 def self.determine_asset_name platform = RUBY_PLATFORM.downcase if platform.include?('linux') ext = '' os = 'linux' elsif platform.include?('darwin') ext = '' os = 'macos' elsif platform.include?('mswin') ext = '.exe' os = 'windows' else UI.error("Unsupported platform: #{platform}") end if platform.include?('arm64') arch = 'arm64' elsif platform.include?('x86_64') arch = 'x86_64' else UI.error("Unsupported platform: #{platform}") end "waldo-agent-#{os}-#{arch}#{ext}" end |
.download(uri, path, retryAllowed) ⇒ Object
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 |
# File 'lib/fastlane/plugin/waldo/helper/waldo_helper.rb', line 34 def self.download(uri, path, retryAllowed) begin request_uri = uri.request_uri response = nil loop do response = Net::HTTP.get_response(uri) break unless response.is_a?(Net::HTTPRedirection) uri = URI.parse(response['location']) end code = response.code.to_i if code < 200 || code > 299 UI.error("Unable to download #{request_uri}, HTTP status: #{response.code}") return retryAllowed && shouldRetry?(response) end fp = File.open(path, 'wb') fp.write(response.body) rescue => exc UI.error("Unable to download #{request_uri}: #{exc.inspect.to_s}") return retryAllowed ensure fp.close if fp end return false end |
.download_binary ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fastlane/plugin/waldo/helper/waldo_helper.rb', line 69 def self.download_binary asset_name = determine_asset_name uri_string = 'https://github.com/waldoapp/waldo-go-agent/releases/latest/download/' uri_string += asset_name binary_path = File.join(Dir.tmpdir, 'waldo-agent') maxDownloadAttempts = 2 for attempts in 1..maxDownloadAttempts do doRetry = download(URI(uri_string), binary_path, attempts < maxDownloadAttempts) break unless doRetry UI.("Failed download attempts: #{attempts} -- retrying…") end File.chmod(0755, binary_path) binary_path end |
.extract_build_id(output) ⇒ Object
93 94 95 96 97 |
# File 'lib/fastlane/plugin/waldo/helper/waldo_helper.rb', line 93 def self.extract_build_id(output) last_line = output.lines(chomp: true).last JSON.parse(last_line, {symbolize_names: true})[:appVersionID] end |
.filter_parameters(in_params) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/fastlane/plugin/waldo/helper/waldo_helper.rb', line 99 def self.filter_parameters(in_params) out_params = {} apk_path = in_params[:apk_path] app_path = in_params[:app_path] git_branch = in_params[:git_branch] git_commit = in_params[:git_commit] upload_token = in_params[:upload_token] variant_name = in_params[:variant_name] || Actions.lane_context[Actions::SharedValues::GRADLE_BUILD_TYPE] apk_path.gsub!('\\ ', ' ') if apk_path app_path.gsub!('\\ ', ' ') if app_path out_params[:apk_path] = apk_path if apk_path out_params[:app_path] = app_path if app_path out_params[:git_branch] = git_branch if git_branch out_params[:git_commit] = git_commit if git_commit out_params[:upload_token] = upload_token if upload_token out_params[:variant_name] = variant_name if variant_name out_params end |
.shouldRetry?(response) ⇒ Boolean
122 123 124 |
# File 'lib/fastlane/plugin/waldo/helper/waldo_helper.rb', line 122 def self.shouldRetry?(response) [408, 429, 500, 502, 503, 504].include?(response.code.to_i) end |
.upload_build(params) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/fastlane/plugin/waldo/helper/waldo_helper.rb', line 126 def self.upload_build(params) apk_path = params[:apk_path] app_path = params[:app_path] if apk_path build_path = apk_path elsif app_path build_path = app_path else build_path = '' end command = [] command << "WALDO_WRAPPER_NAME_OVERRIDE='Waldo Fastlane Plugin'" command << "WALDO_WRAPPER_VERSION_OVERRIDE='#{Fastlane::Waldo::VERSION}'" command << download_binary.shellescape command << 'upload' if params[:git_branch] command << '--git_branch' command << params[:git_branch] end if params[:git_commit] command << '--git_commit' command << params[:git_commit] end if params[:upload_token] command << '--upload_token' command << params[:upload_token] end if params[:variant_name] command << '--variant_name' command << params[:variant_name] end command << '--verbose' if FastlaneCore::Globals.verbose? command << build_path.shellescape output = Actions.sh_control_output(command.join(' '), print_command: FastlaneCore::Globals.verbose?, print_command_output: true) Actions.lane_context[Actions::SharedValues::WALDO_BUILD_ID] = extract_build_id(output) end |