fastlane-plugin-waldo 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f32ec479ee63b1ab4f8927cb26ee7b49562c5ea8
4
- data.tar.gz: 42c8849320d5ff492788e542866c71b45a9b3773
3
+ metadata.gz: 0312eb8f82f68eaaa890579f32df69021f403e15
4
+ data.tar.gz: 517fa6efaa6b61874e22cf5ef28446e28fcebf63
5
5
  SHA512:
6
- metadata.gz: 49ea9aef680aa191a35d3b3a6a0bdf2f9ce809ffc4ce69e373e2b0d8ca2462547b1a806a92ca0669528a3c9ff4c565251f81d688ebb8c1ec6592339368d0a361
7
- data.tar.gz: 2bd510d3f86f923f9ac982b26e90032e678f4aaed3bff69f4f9413c3f628cdaca7c2c4898224dbaf0cf31382d23465b482b9097637354b8a17465537f79762e4
6
+ metadata.gz: 96627fe481183b67111d6e3d61e6bd2c6f77e916f562308f0c9d7ad486667890ae438affcf41d8982bc9feb7b359732c93b971bacbc4ed8dd7cba962f1cd9528
7
+ data.tar.gz: d644bb93a1f79e0f4d30f5495df16ed71234e142c4c01d1a2c8af45b26b751028731c3b42f4a0575dd85775455a949418796c6bb57cfdaf36ff976ce7ada6400
@@ -2,34 +2,23 @@ module Fastlane
2
2
  module Actions
3
3
  class WaldoAction < Action
4
4
  def self.run(params)
5
- params.values # validate all inputs
6
-
7
- platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
8
-
9
- if platform == :android
10
- UI.error("You must pass an APK path to the Waldo action") and return unless params[:apk_path]
11
- elsif platform == :ios || platform.nil?
12
- UI.error("You must pass an IPA or app path to the Waldo action") and return unless params[:ipa_path] || params[:app_path]
13
- end
14
-
15
- UI.error("You must pass an upload token to the Waldo action") and return unless params[:upload_token]
5
+ return unless Helper::WaldoHelper.validate_parameters(params)
16
6
 
17
7
  FastlaneCore::PrintTable.print_values(config: params,
18
8
  title: "Summary for waldo #{Fastlane::Waldo::VERSION.to_s}")
19
9
 
20
- Helper::WaldoHelper.upload_build(params)
10
+ Helper::WaldoHelper.upload_build
21
11
  end
22
12
 
23
13
  def self.authors
24
- ["eBardX"]
14
+ ['eBardX']
25
15
  end
26
16
 
27
17
  def self.available_options
28
- platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
29
-
30
- if platform == :android
31
- apk_path_default = Dir["*.apk"].last || Dir[File.join("app", "build", "outputs", "apk", "app-release.apk")].last
32
- elsif platform == :ios || platform.nil?
18
+ case Helper::WaldoHelper.get_platform
19
+ when :android
20
+ apk_path_default = Dir["*.apk"].last || Dir[File.join('app', 'build', 'outputs', 'apk', 'app-release.apk')].last
21
+ when :ios
33
22
  app_path_default = Dir["*.app"].sort_by { |x| File.mtime(x) }.last
34
23
  ipa_path_default = Dir["*.ipa"].sort_by { |x| File.mtime(x) }.last
35
24
  end
@@ -37,50 +26,35 @@ module Fastlane
37
26
  [
38
27
  # iOS-specific
39
28
  FastlaneCore::ConfigItem.new(key: :app_path,
40
- env_name: "WALDO_APP_PATH",
41
- description: "Path to your app file",
29
+ env_name: 'WALDO_APP_PATH',
30
+ description: 'Path to your app file',
42
31
  default_value: app_path_default,
43
32
  default_value_dynamic: true,
44
- optional: true,
45
- verify_block: proc do |value|
46
- UI.error("Unable to find app file at path '#{value.to_s}'") unless File.exist?(value)
47
- end),
33
+ optional: true),
48
34
  FastlaneCore::ConfigItem.new(key: :ipa_path,
49
- env_name: "WALDO_IPA_PATH",
50
- description: "Path to your IPA file (optional if you use the _gym_ or _xcodebuild_ action)",
35
+ env_name: 'WALDO_IPA_PATH',
36
+ description: 'Path to your IPA file (optional if you use the _gym_ or _xcodebuild_ action)',
51
37
  default_value: Actions.lane_context[Actions::SharedValues::IPA_OUTPUT_PATH] || ipa_path_default,
52
38
  default_value_dynamic: true,
53
- optional: true,
54
- verify_block: proc do |value|
55
- UI.error("Unable to find IPA file at path '#{value.to_s}'") unless File.exist?(value)
56
- end),
39
+ optional: true),
57
40
  # Android-specific
58
41
  FastlaneCore::ConfigItem.new(key: :apk_path,
59
- env_name: "WALDO_APK_PATH",
60
- description: "Path to your APK file (optional if you use the _gradle_ action)",
42
+ env_name: 'WALDO_APK_PATH',
43
+ description: 'Path to your APK file (optional if you use the _gradle_ action)',
61
44
  default_value: Actions.lane_context[Actions::SharedValues::GRADLE_APK_OUTPUT_PATH] || apk_path_default,
62
45
  default_value_dynamic: true,
63
- optional: true,
64
- verify_block: proc do |value|
65
- UI.error("Unable to find APK file at path '#{value.to_s}'") unless File.exist?(value)
66
- end),
46
+ optional: true),
67
47
  # General
68
48
  FastlaneCore::ConfigItem.new(key: :upload_token,
69
- env_name: "WALDO_UPLOAD_TOKEN",
70
- description: "Waldo upload token",
49
+ env_name: 'WALDO_UPLOAD_TOKEN',
50
+ description: 'Waldo upload token',
71
51
  optional: true,
72
- sensitive: true,
73
- verify_block: proc do |value|
74
- UI.error("No upload token for Waldo given, pass using `upload_token: 'value'`") unless value && !value.empty?
75
- end),
52
+ sensitive: true),
76
53
  FastlaneCore::ConfigItem.new(key: :variant_name,
77
- env_name: "WALDO_VARIANT_NAME",
78
- description: "Waldo variant name",
54
+ env_name: 'WALDO_VARIANT_NAME',
55
+ description: 'Waldo variant name',
79
56
  optional: true,
80
- sensitive: true,
81
- verify_block: proc do |value|
82
- UI.error("No variant name for Waldo given, pass using `variant_name: 'value'`") unless value && !value.empty?
83
- end)
57
+ sensitive: true)
84
58
  ]
85
59
  end
86
60
 
@@ -89,27 +63,27 @@ module Fastlane
89
63
  end
90
64
 
91
65
  def self.description
92
- "Upload a new build to [Waldo](https://www.waldo.io)"
66
+ 'Upload a new build to [Waldo](https://www.waldo.io)'
93
67
  end
94
68
 
95
69
  def self.example_code
96
70
  [
97
71
  'waldo',
98
- 'waldo(
99
- upload_token: "..."
100
- )',
101
- 'waldo(
102
- apk_path: "./YourApp.apk",
103
- upload_token: "..."
104
- )',
105
- 'waldo(
106
- ipa_path: "./YourApp.ipa",
107
- upload_token: "..."
108
- )',
109
- 'waldo(
110
- app_path: "./YourApp.app",
111
- upload_token: "..."
112
- )'
72
+ "waldo(
73
+ upload_token: '...'
74
+ )",
75
+ "waldo(
76
+ apk_path: './YourApp.apk',
77
+ upload_token: '...'
78
+ )",
79
+ "waldo(
80
+ ipa_path: './YourApp.ipa',
81
+ upload_token: '...'
82
+ )",
83
+ "waldo(
84
+ app_path: './YourApp.app',
85
+ upload_token: '...'
86
+ )"
113
87
  ]
114
88
  end
115
89
 
@@ -3,63 +3,86 @@ require 'net/http'
3
3
  module Fastlane
4
4
  module Helper
5
5
  class WaldoHelper
6
- def self.upload_build(params)
7
- UI.success('Uploading the build to Waldo. This could take a while…')
6
+ def self.dump_request(request)
7
+ len = request.body ? request.body.length : 0
8
8
 
9
- begin
10
- variant_name = params[:variant_name] || Actions.lane_context[Actions::SharedValues::GRADLE_BUILD_TYPE]
11
- uri_string = 'https://api.waldo.io/versions'
9
+ puts "Request: #{request.method} #{request.path} (#{len} bytes)"
12
10
 
13
- uri_string += "?variantName=#{variant_name}" if variant_name
11
+ request.each_capitalized do |key, value|
12
+ puts " #{key}: #{value}"
13
+ end
14
14
 
15
- uri = URI(uri_string)
15
+ puts '-------'
16
+ end
16
17
 
17
- request = build_request(uri, params)
18
+ def self.dump_response(response)
19
+ puts "Response: #{response.code} #{response.message} (#{response.body.length} bytes)"
18
20
 
19
- dump_request(request) if FastlaneCore::Globals.verbose?
21
+ response.each_capitalized do |key, value|
22
+ puts " #{key}: #{value}"
23
+ end
20
24
 
21
- Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
22
- http.read_timeout = 120 # 2 minutes
25
+ puts "#{response.body}"
26
+ end
23
27
 
24
- parse_response(http.request(request))
25
- end
26
- rescue Net::ReadTimeout
27
- UI.error("Upload to Waldo timed out!")
28
- rescue => exc
29
- UI.error("Something went wrong uploading to Waldo: #{exc.inspect.to_s}")
30
- ensure
31
- request.body_stream.close if request && request.body_stream
28
+ def self.get_authorization
29
+ "Upload-Token #{@upload_token}"
30
+ end
31
+
32
+ def self.get_flavor
33
+ case get_platform
34
+ when :android
35
+ "Android"
36
+ when :ios
37
+ "iOS"
38
+ else
39
+ "unknown"
32
40
  end
33
41
  end
34
42
 
35
- def self.build_request(uri, params)
36
- platform = Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
43
+ def self.get_platform
44
+ Actions.lane_context[Actions::SharedValues::PLATFORM_NAME] || :ios
45
+ end
37
46
 
38
- if platform == :android
39
- body_path = params[:apk_path]
40
- flavor = "Android"
41
- elsif platform == :ios || platform.nil?
42
- if params[:app_path]
43
- app_dir_path = File.dirname(params[:app_path])
44
- app_name = File.basename(params[:app_path])
45
- body_path = File.join(Dir.tmpdir, "#{app_name}.zip")
47
+ def self.get_user_agent
48
+ "Waldo fastlane/#{get_flavor} v#{Fastlane::Waldo::VERSION}"
49
+ end
46
50
 
47
- Actions.sh(%(cd "#{app_dir_path}" && zip -qry "#{body_path}" "#{app_name}"))
48
- else
49
- body_path = params[:ipa_path]
51
+ def self.handle_error(message)
52
+ UI.error(message)
53
+
54
+ UI.error('No token for error report upload to Waldo!') unless @upload_token
55
+
56
+ upload_error(message) if @upload_token
57
+ end
58
+
59
+ def self.make_build_request(uri)
60
+ if @apk_path
61
+ body_path = @apk_path
62
+ elsif @ipa_path
63
+ body_path = @ipa_path
64
+ else
65
+ app_basename = File.basename(@app_path)
66
+ app_dirname = File.dirname(@app_path)
67
+
68
+ body_path = File.join(Dir.tmpdir, "#{app_basename}.zip")
69
+
70
+ unless zip(src_path: app_basename,
71
+ zip_path: body_path,
72
+ cd_path: app_dirname)
73
+ return nil
50
74
  end
51
- flavor = "iOS"
52
75
  end
53
76
 
54
77
  request = Net::HTTP::Post.new(uri.request_uri)
55
78
 
56
- request['Authorization'] = "Upload-Token #{params[:upload_token]}"
79
+ request['Authorization'] = get_authorization
57
80
  request['Transfer-Encoding'] = 'chunked'
58
- request['User-Agent'] = "Waldo fastlane/#{flavor} v#{Fastlane::Waldo::VERSION}"
81
+ request['User-Agent'] = get_user_agent
59
82
 
60
83
  request.body_stream = WaldoReadIO.new(body_path)
61
84
 
62
- if params[:app_path]
85
+ if @app_path
63
86
  request.content_type = 'application/zip'
64
87
  else
65
88
  request.content_type = 'application/octet-stream'
@@ -68,39 +91,213 @@ module Fastlane
68
91
  request
69
92
  end
70
93
 
71
- def self.dump_request(request)
72
- len = request.body ? request.body.length : 0
94
+ def self.make_build_uri
95
+ uri_string = 'https://api.waldo.io/versions'
73
96
 
74
- puts "Request: #{request.method} #{request.path} (#{len} bytes)"
97
+ uri_string += "?variantName=#{@variant_name}" if @variant_name
75
98
 
76
- request.each_capitalized do |key, value|
77
- puts " #{key}: #{value}"
78
- end
79
-
80
- puts "-------"
99
+ URI(uri_string)
81
100
  end
82
101
 
83
- def self.dump_response(response)
84
- puts "Response: #{response.code} #{response.message} (#{response.body.length} bytes)"
102
+ def self.make_error_request(uri, message)
103
+ request = Net::HTTP::Post.new(uri.request_uri)
85
104
 
86
- response.each_capitalized do |key, value|
87
- puts " #{key}: #{value}"
88
- end
105
+ request['Authorization'] = get_authorization
106
+ request['User-Agent'] = get_user_agent
89
107
 
90
- puts "#{response.body}"
108
+ request.body = { "message": message }.to_json
109
+ request.content_type = 'application/json'
110
+
111
+ request
112
+ end
113
+
114
+ def self.make_error_uri
115
+ uri_string = 'https://api.waldo.io/uploadError'
116
+
117
+ URI(uri_string)
91
118
  end
92
119
 
93
- def self.parse_response(response)
120
+ def self.parse_build_response(response)
94
121
  dump_response(response) if FastlaneCore::Globals.verbose?
95
122
 
96
123
  case response.code.to_i
97
124
  when 200..299
98
125
  UI.success('Build successfully uploaded to Waldo!')
99
126
  when 401
100
- UI.error("Upload token is invalid or missing!")
127
+ handle_error('Token is invalid or missing for build upload to Waldo!')
128
+ else
129
+ handle_error("Build failed to upload to Waldo: #{response.code} #{response.message}")
130
+ end
131
+ end
132
+
133
+ def self.parse_error_response(response)
134
+ dump_response(response) if FastlaneCore::Globals.verbose?
135
+
136
+ case response.code.to_i
137
+ when 200..299
138
+ UI.success('Error report successfully uploaded to Waldo!')
139
+ when 401
140
+ UI.error('Token is invalid or missing for error report upload to Waldo!')
141
+ else
142
+ UI.error("Error report failed to upload to Waldo: #{response.code} #{response.message}")
143
+ end
144
+ end
145
+
146
+ def self.upload_build
147
+ begin
148
+ @variant_name ||= Actions.lane_context[Actions::SharedValues::GRADLE_BUILD_TYPE]
149
+
150
+ uri = make_build_uri
151
+
152
+ request = make_build_request(uri)
153
+
154
+ return unless request
155
+
156
+ UI.success('Uploading the build to Waldo. This could take a while…')
157
+
158
+ dump_request(request) if FastlaneCore::Globals.verbose?
159
+
160
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
161
+ http.read_timeout = 120 # 2 minutes
162
+
163
+ parse_build_response(http.request(request))
164
+ end
165
+ rescue Net::ReadTimeout => exc
166
+ handle_error('Build upload to Waldo timed out!')
167
+ rescue => exc
168
+ handle_error("Something went wrong uploading build to Waldo: #{exc.inspect.to_s}")
169
+ ensure
170
+ request.body_stream.close if request && request.body_stream
171
+ end
172
+ end
173
+
174
+ def self.upload_error(message)
175
+ begin
176
+ uri = make_error_uri
177
+
178
+ request = make_error_request(uri, message)
179
+
180
+ UI.error('Uploading error report to Waldo…')
181
+
182
+ dump_request(request) if FastlaneCore::Globals.verbose?
183
+
184
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
185
+ http.read_timeout = 30 # seconds
186
+
187
+ parse_error_response(http.request(request))
188
+ end
189
+ rescue Net::ReadTimeout => exc
190
+ UI.error('Error report upload to Waldo timed out!')
191
+ rescue => exc
192
+ UI.error("Something went wrong uploading error report to Waldo: #{exc.inspect.to_s}")
193
+ end
194
+ end
195
+
196
+ def self.validate_parameters(params)
197
+ @apk_path = params[:apk_path]
198
+ @app_path = params[:app_path]
199
+ @ipa_path = params[:ipa_path]
200
+ @upload_token = params[:upload_token]
201
+ @variant_name = params[:variant_name]
202
+
203
+ if @upload_token && @upload_token.empty?
204
+ @upload_token = nil # easier to test
205
+ end
206
+
207
+ unless @upload_token
208
+ handle_error('You must pass a nonempty upload token to the Waldo action')
209
+
210
+ return false
211
+ end
212
+
213
+ case get_platform
214
+ when :android
215
+ unless @apk_path
216
+ handle_error('You must pass an APK path to the Waldo action')
217
+
218
+ return false
219
+ end
220
+
221
+ @apk_path.gsub!("\\ ", ' ')
222
+
223
+ unless File.exist?(@apk_path)
224
+ handle_error("Unable to find APK at path '#{@apk_path.to_s}'")
225
+
226
+ return false
227
+ end
228
+
229
+ unless File.file?(@apk_path) && File.readable?(@apk_path)
230
+ handle_error("Unable to read APK at path '#{@apk_path.to_s}'")
231
+
232
+ return false
233
+ end
234
+ when :ios
235
+ unless @app_path || @ipa_path
236
+ handle_error('You must pass an IPA or app path to the Waldo action')
237
+
238
+ return false
239
+ end
240
+
241
+ if @app_path
242
+ @app_path.gsub!("\\ ", ' ')
243
+
244
+ unless File.exist?(@app_path)
245
+ handle_error("Unable to find app at path '#{@app_path.to_s}'")
246
+
247
+ return false
248
+ end
249
+
250
+ unless File.directory?(@app_path) && File.readable?(@app_path)
251
+ handle_error("Unable to read app at path '#{@app_path.to_s}'")
252
+
253
+ return false
254
+ end
255
+ elsif @ipa_path
256
+ @ipa_path.gsub!("\\ ", ' ')
257
+
258
+ unless File.exist?(@ipa_path)
259
+ handle_error("Unable to find IPA at path '#{@ipa_path.to_s}'")
260
+
261
+ return false
262
+ end
263
+
264
+ unless File.file?(@ipa_path) && File.readable?(@ipa_path)
265
+ handle_error("Unable to read IPA at path '#{@ipa_path.to_s}'")
266
+
267
+ return false
268
+ end
269
+ end
101
270
  else
102
- UI.error("Build failed to upload to Waldo: #{response.code} #{response.message}")
271
+ handle_error("Unsupported platform: '#{get_platform.to_s}'")
272
+
273
+ return false
103
274
  end
275
+
276
+ if @variant_name && @variant_name.empty?
277
+ handle_error('Empty variant name for Waldo given')
278
+
279
+ return false
280
+ end
281
+
282
+ return true
283
+ end
284
+
285
+ def self.zip(src_path:, zip_path:, cd_path:)
286
+ unless FastlaneCore::CommandExecutor.which('zip')
287
+ handle_error("Command not found: 'zip'")
288
+
289
+ return false
290
+ end
291
+
292
+ FileUtils.cd(cd_path) do
293
+ unless Actions.sh(%(zip -qry "#{zip_path}" "#{src_path}")).empty?
294
+ handle_error("Unable to zip app at path '#{src_path.to_s}' into '#{zip_path.to_s}'")
295
+
296
+ return false
297
+ end
298
+ end
299
+
300
+ return true
104
301
  end
105
302
  end
106
303
 
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Waldo
3
- VERSION = "1.2.0"
3
+ VERSION = "1.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-waldo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. G. Pusey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-30 00:00:00.000000000 Z
11
+ date: 2019-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler