fastlane-plugin-appcenter 1.7.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba75670e59a7a2ba066a788088aeb05d96991bcc1ab693633bb0fca27fc821c5
4
- data.tar.gz: b11523450e225a2ec2b596d0a4db135cf1dd1a5acefd4a0a0bc0136cf42c8917
3
+ metadata.gz: 1c1262b958ae0ddbf9a6bfa6d63b4f032f1518c706154e6c70b35adbe2c441e2
4
+ data.tar.gz: c2ffa81d7a6e4c8fb369c5d4612a0aea7c02c2cd589a3fdcb900d8b407f2eaae
5
5
  SHA512:
6
- metadata.gz: ffd5e3de2a289e28e264a679fb286bb25ecc830a8c36d15c0d044291bc891f9eb17e76e8e4ea76682bf84b19c18db86d475c20b6cdab5f223fd85d7e207b8d85
7
- data.tar.gz: d8c07796377fb096fa566c35435e208d22de2dbd3bac1e5901fbff0b432ea7a7ecfdf77b60a5726ff30a87865062602544bd4f0f980c5a96dead0dd1d825855f
6
+ metadata.gz: eb06867a95f13d484796bd47be5cad11df03e949ffffbcbf8cbe14d675c8577506e184176248ba8102fc338ab934e9d03e06938030591d9d9a72beec557f7894
7
+ data.tar.gz: b1fadb157505f3138621dffd8e95a64d306f89439ab25259c60c6a9e08d9a9dbe97d0b09b4c1daf8db70e2c9241d87225523784cb3f9c5e900c98d3a85b0b05f
data/README.md CHANGED
@@ -21,6 +21,8 @@ With [App Center](https://appcenter.ms) you can continuously build, test, releas
21
21
 
22
22
  `appcenter_upload` allows you to upload and [distribute](https://docs.microsoft.com/en-us/appcenter/distribution/uploading) apps to your testers on App Center as well as to upload .dSYM files to [collect detailed crash reports](https://docs.microsoft.com/en-us/appcenter/crashes/ios) in App Center.
23
23
 
24
+ `appcenter_fetch_version_number` allows you to obtain the latest version number (short or full) for an app. This is useful for tasks such as getting the latest version of an app so that an increment action can take place on CI, or checking that an upload has been successful.
25
+
24
26
  ## Usage
25
27
 
26
28
  To get started, first, [obtain an API token](https://appcenter.ms/settings/apitokens) in App Center. The API Token is used to authenticate with the App Center API in each call.
@@ -29,7 +31,6 @@ To get started, first, [obtain an API token](https://appcenter.ms/settings/apito
29
31
  appcenter_fetch_devices(
30
32
  api_token: "<appcenter token>",
31
33
  owner_name: "<appcenter account name of the owner of the app (username or organization URL name)>",
32
- owner_type: "user", # Default is user - set to organization for appcenter organizations
33
34
  app_name: "<appcenter app name>",
34
35
  destinations: "*", # Default is 'Collaborators', use '*' for all distribution groups
35
36
  devices_file: "devices.txt" # Default. If you customize, the extension must be .txt
@@ -47,6 +48,21 @@ appcenter_upload(
47
48
  )
48
49
  ```
49
50
 
51
+ ```ruby
52
+ appcenter_fetch_version_number(
53
+ api_token: "<appcenter token>",
54
+ owner_name: "<appcenter account name of the owner of the app (username or organization URL name)>",
55
+ app_name: "<appcenter app name (as seen in app URL)>",
56
+ version: "a specific version to get the last release for" # optional, don't set this value to get the last upload of all versions
57
+ )
58
+ ```
59
+
60
+ The `appcenter_fetch_version_number` returns a hash that contains the id, the version number, and the build number. The version corresponds to the `short_version` and the build number to the `version` known by App Center for a given release:
61
+ ```ruby
62
+ {"id"=>1, "version"=>"1.0.0", "build_number"=>"1.0.0.1234"} # iOS apps contain the full version plus build number due to the way that Apple use CFBundleVersion for this value
63
+ {"id"=>588, "version"=>"1.2.0", "build_number"=>"1615"}
64
+ ```
65
+
50
66
  ### Help
51
67
 
52
68
  Once installed, information and help for an action can be printed out with this command:
@@ -74,7 +90,6 @@ Here is the list of all existing parameters:
74
90
  | Key & Env Var | Description |
75
91
  |-----------------|--------------------|
76
92
  | `api_token` <br/> `APPCENTER_API_TOKEN` | API Token for App Center |
77
- | `owner_type` <br/> `APPCENTER_OWNER_TYPE` | Owner type, either 'user' or 'organization' (default: `user`) |
78
93
  | `owner_name` <br/> `APPCENTER_OWNER_NAME` | Owner name, as found in the App's URL in App Center |
79
94
  | `destinations` <br/> `APPCENTER_DISTRIBUTE_DESTINATIONS` | Comma separated list of distribution group names. Default is 'Collaborators', use '*' for all distribution groups |
80
95
  | `devices_file` <br/> `FL_REGISTER_DEVICES_FILE` | File to save the devices list to. Same environment variable as _fastlane_'s `register_devices` action |
@@ -88,7 +103,7 @@ Here is the list of all existing parameters:
88
103
  | `owner_name` <br/> `APPCENTER_OWNER_NAME` | Owner name as found in the App's URL in App Center |
89
104
  | `app_name` <br/> `APPCENTER_APP_NAME` | App name as found in the App's URL in App Center. If there is no app with such name, you will be prompted to create one |
90
105
  | `app_display_name` <br/> `APPCENTER_APP_DISPLAY_NAME` | App display name to use when creating a new app |
91
- | `app_os` <br/> `APPCENTER_APP_OS` | App OS. Used for new app creation, if app 'app_name' was not found |
106
+ | `app_os` <br/> `APPCENTER_APP_OS` | App OS can be Android, iOS, macOS, Windows, Custom. Used for new app creation, if app 'app_name' was not found |
92
107
  | `app_platform` <br/> `APPCENTER_APP_PLATFORM` | App Platform. Used for new app creation, if app 'app_name' was not found |
93
108
  | `file` <br/> `APPCENTER_DISTRIBUTE_FILE` | File path to the release build to publish |
94
109
  | `upload_build_only` <br/> `APPCENTER_DISTRIBUTE_UPLOAD_BUILD_ONLY` | Flag to upload only the build to App Center. Skips uploading symbols or mapping (default: `false`) |
@@ -96,7 +111,7 @@ Here is the list of all existing parameters:
96
111
  | `upload_dsym_only` <br/> `APPCENTER_DISTRIBUTE_UPLOAD_DSYM_ONLY` | Flag to upload only the dSYM file to App Center (default: `false`) |
97
112
  | `mapping` <br/> `APPCENTER_DISTRIBUTE_ANDROID_MAPPING` | Path to your Android mapping.txt |
98
113
  | `upload_mapping_only` <br/> `APPCENTER_DISTRIBUTE_UPLOAD_ANDROID_MAPPING_ONLY` | Flag to upload only the mapping.txt file to App Center (default: `false`) |
99
- | `destinations` <br/> `APPCENTER_DISTRIBUTE_DESTINATIONS` | Comma separated list of destination names. Both distribution groups and stores are supported. All names are required to be of the same destination type (default: `Collaborators`) |
114
+ | `destinations` <br/> `APPCENTER_DISTRIBUTE_DESTINATIONS` | Comma separated list of destination names, use '*' for all distribution groups if destination type is 'group'. Both distribution groups and stores are supported. All names are required to be of the same destination type (default: `Collaborators`) |
100
115
  | `destination_type` <br/> `APPCENTER_DISTRIBUTE_DESTINATION_TYPE` | Destination type of distribution destination. 'group' and 'store' are supported (default: `group`) |
101
116
  | `mandatory_update` <br/> `APPCENTER_DISTRIBUTE_MANDATORY_UPDATE` | Require users to update to this release. Ignored if destination type is 'store' (default: `false`) |
102
117
  | `notify_testers` <br/> `APPCENTER_DISTRIBUTE_NOTIFY_TESTERS` | Send email notification about release. Ignored if destination type is 'store' (default: `false`) |
@@ -105,10 +120,19 @@ Here is the list of all existing parameters:
105
120
  | `release_notes_link` <br/> `APPCENTER_DISTRIBUTE_RELEASE_NOTES_LINK` | Additional release notes link |
106
121
  | `build_number` <br/> `APPCENTER_DISTRIBUTE_BUILD_NUMBER` | The build number, required for macOS .pkg and .dmg builds, as well as Android ProGuard `mapping.txt` when using `upload_mapping_only` |
107
122
  | `version` <br/> `APPCENTER_DISTRIBUTE_VERSION` | The build version, required for .pkg, .dmg, .zip and .msi builds, as well as Android ProGuard `mapping.txt` when using `upload_mapping_only` |
108
- | `timeout` <br/> `APPCENTER_DISTRIBUTE_TIMEOUT` | Request timeout in seconds |
123
+ | `timeout` <br/> `APPCENTER_DISTRIBUTE_TIMEOUT` | Request timeout in seconds applied to individual HTTP requests. Some commands use multiple HTTP requests, large file uploads are also split in multiple HTTP requests |
109
124
  | `dsa_signature` <br/> `APPCENTER_DISTRIBUTE_DSA_SIGNATURE` | DSA signature of the macOS or Windows release for Sparkle update feed |
125
+ | `ed_signature` <br/> `APPCENTER_DISTRIBUTE_ED_SIGNATURE` | EdDSA signature of the macOS or Windows release for Sparkle update feed |
110
126
  | `strict` <br/> `APPCENTER_STRICT_MODE` | Strict mode, set to 'true' to fail early in case a potential error was detected |
111
127
 
128
+ #### `appcenter_fetch_version_number`
129
+
130
+ | Key & Env Var | Description |
131
+ |-----------------|--------------------|
132
+ | `api_token` <br/> `APPCENTER_API_TOKEN` | API Token for App Center |
133
+ | `owner_name` <br/> `APPCENTER_OWNER_NAME` | Owner name, as found in the App's URL in App Center |
134
+ | `app_name` <br/> `APPCENTER_APP_NAME` | App name as found in the App's URL in App Center. If there is no app with such name, you will be prompted to create one |
135
+ | `version` <br/> `APPCENTER_APP_VERSION` | App version to get the last release for instead of the last release of all versions |
112
136
 
113
137
  ## Example
114
138
 
@@ -162,4 +186,4 @@ Check out [SECURITY.md](SECURITY.md) for any security concern with this project.
162
186
 
163
187
  ## Contact
164
188
 
165
- We're on Twitter as [@vsappcenter](https://www.twitter.com/vsappcenter). Additionally you can reach out to us on the [App Center](https://appcenter.ms/apps) portal by using the blue Intercom button on the bottom right to start a conversation.
189
+ We're on Twitter as [@vsappcenter](https://www.twitter.com/vsappcenter). Additionally you can reach out to us on the [App Center](https://appcenter.ms/apps) portal. Open the "?" menu on the top right corner of screen, then use "Contact support" to file a support ticket. Our support team is there to answer your questions and help you solve your problems.
@@ -0,0 +1,103 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "fastlane_core/ui/ui"
4
+
5
+ module Fastlane
6
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
7
+
8
+ module Actions
9
+ class AppcenterFetchVersionNumberAction < Action
10
+ def self.description
11
+ "Fetches the latest version number of an app or the last build number of a version from App Center"
12
+ end
13
+
14
+ def self.authors
15
+ ["jspargo", "ShopKeep", "Qutaibah"]
16
+ end
17
+
18
+ def self.run(params)
19
+ api_token = params[:api_token]
20
+ app_name = params[:app_name]
21
+ owner_name = params[:owner_name]
22
+ version = params[:version]
23
+
24
+ releases = Helper::AppcenterHelper.fetch_releases(
25
+ api_token: api_token,
26
+ owner_name: owner_name,
27
+ app_name: app_name,
28
+ )
29
+
30
+ UI.abort_with_message!("No versions found for '#{app_name}' owned by #{owner_name}") unless releases
31
+
32
+ sorted_releases = releases
33
+
34
+ if version.nil?
35
+ sorted_releases = releases.sort_by { |release| release["id"] }
36
+ else
37
+ sorted_releases = releases.select { |release| release["short_version"] == version }.sort_by { |release| release["id"] }
38
+ end
39
+
40
+ latest_release = sorted_releases.last
41
+
42
+ if latest_release.nil?
43
+ if version.nil?
44
+ UI.user_error!("This app has no releases yet")
45
+ return nil
46
+ end
47
+ UI.user_error!("The provided version (#{version}) has no releases yet")
48
+ return nil
49
+ end
50
+
51
+ return {
52
+ "id" => latest_release["id"],
53
+ "version" => latest_release["short_version"],
54
+ "build_number" => latest_release["version"],
55
+ }
56
+ end
57
+
58
+ def self.available_options
59
+ [
60
+ FastlaneCore::ConfigItem.new(key: :api_token,
61
+ env_name: "APPCENTER_API_TOKEN",
62
+ description: "API Token for App Center Access",
63
+ verify_block: proc do |value|
64
+ UI.user_error!("No API token for App Center given, pass using `api_token: 'token'`") unless value && !value.empty?
65
+ end),
66
+ FastlaneCore::ConfigItem.new(key: :owner_name,
67
+ env_name: "APPCENTER_OWNER_NAME",
68
+ description: "Name of the owner of the application on App Center",
69
+ verify_block: proc do |value|
70
+ UI.user_error!("No owner name for App Center given, pass using `owner_name: 'owner name'`") unless value && !value.empty?
71
+ end),
72
+ FastlaneCore::ConfigItem.new(key: :app_name,
73
+ env_name: "APPCENTER_APP_NAME",
74
+ description: "Name of the application on App Center",
75
+ verify_block: proc do |value|
76
+ UI.user_error!("No app name for App Center given, pass using `app_name: 'app name'`") unless value && !value.empty?
77
+ end),
78
+ FastlaneCore::ConfigItem.new(key: :version,
79
+ env_name: "APPCENTER_APP_VERSION",
80
+ description: "The version to get the latest release for",
81
+ optional: true,
82
+ type: String),
83
+
84
+ ]
85
+ end
86
+
87
+ def self.is_supported?(platform)
88
+ [:ios, :android].include?(platform)
89
+ end
90
+
91
+ def self.get_apps(api_token)
92
+ host_uri = URI.parse("https://api.appcenter.ms")
93
+ http = Net::HTTP.new(host_uri.host, host_uri.port)
94
+ http.use_ssl = true
95
+ apps_request = Net::HTTP::Get.new("/v0.1/apps")
96
+ apps_request["X-API-Token"] = api_token
97
+ apps_response = http.request(apps_request)
98
+ return [] unless apps_response.kind_of?(Net::HTTPOK)
99
+ return JSON.parse(apps_response.body)
100
+ end
101
+ end
102
+ end
103
+ end
@@ -9,6 +9,23 @@ module Fastlane
9
9
  windows: %w(.appx .appxbundle .appxupload .msix .msixbundle .msixupload .zip .msi),
10
10
  custom: %w(.zip)
11
11
  }
12
+ CONTENT_TYPES = {
13
+ apk: "application/vnd.android.package-archive",
14
+ aab: "application/vnd.android.package-archive",
15
+ msi: "application/x-msi",
16
+ plist: "application/xml",
17
+ aetx: "application/c-x509-ca-cert",
18
+ cer: "application/pkix-cert",
19
+ xap: "application/x-silverlight-app",
20
+ appx: "application/x-appx",
21
+ appxbundle: "application/x-appxbundle",
22
+ appxupload: "application/x-appxupload",
23
+ appxsym: "application/x-appxupload",
24
+ msix: "application/x-msix",
25
+ msixbundle: "application/x-msixbundle",
26
+ msixupload: "application/x-msixupload",
27
+ msixsym: "application/x-msixupload",
28
+ }
12
29
  ALL_SUPPORTED_EXTENSIONS = SUPPORTED_EXTENSIONS.values.flatten.sort!.uniq!
13
30
  STORE_ONLY_EXTENSIONS = %w(.aab)
14
31
  STORE_SUPPORTED_EXTENSIONS = %w(.aab .apk .ipa)
@@ -22,6 +39,13 @@ module Fastlane
22
39
  end
23
40
 
24
41
  class AppcenterUploadAction < Action
42
+ def self.is_apple_build(file)
43
+ return false unless file
44
+
45
+ file_ext = Helper::AppcenterHelper.file_extname_full(file)
46
+ ((Constants::SUPPORTED_EXTENSIONS[:ios] + Constants::SUPPORTED_EXTENSIONS[:mac])).include? file_ext
47
+ end
48
+
25
49
  # run whole upload process for dSYM files
26
50
  def self.run_dsym_upload(params)
27
51
  values = params.values
@@ -35,8 +59,9 @@ module Fastlane
35
59
 
36
60
  dsym_path = nil
37
61
  if dsym
38
- # we can use dsym parameter only if build file is ipa
39
- dsym_path = dsym if !file || File.extname(file) == '.ipa'
62
+ # we can use dsym parameter for all apple builds
63
+ self.optional_error("dsym parameter can only be used with Apple builds (ios, mac)") unless !file || self.is_apple_build(file)
64
+ dsym_path = dsym
40
65
  else
41
66
  # if dsym is not set, but build is ipa - check default path
42
67
  if file && File.exist?(file) && File.extname(file) == '.ipa'
@@ -118,6 +143,7 @@ module Fastlane
118
143
  build_number = params[:build_number]
119
144
  version = params[:version]
120
145
  dsa_signature = params[:dsa_signature]
146
+ ed_signature = params[:ed_signature]
121
147
 
122
148
  if release_notes.length >= Constants::MAX_RELEASE_NOTES_LENGTH
123
149
  unless should_clip
@@ -172,25 +198,40 @@ module Fastlane
172
198
  File.delete zip_file
173
199
  end
174
200
  UI.message("Creating zip archive: #{zip_file}")
175
- file = Actions::ZipAction.run(path: file, output_path: zip_file)
201
+ file = Actions::ZipAction.run(path: file, output_path: zip_file, symlinks: true)
176
202
  end
177
203
 
178
204
  UI.message("Starting release upload...")
179
205
  upload_details = Helper::AppcenterHelper.create_release_upload(api_token, owner_name, app_name, release_upload_body)
180
206
  if upload_details
181
- upload_id = upload_details['upload_id']
182
- upload_url = upload_details['upload_url']
207
+ upload_id = upload_details['id']
208
+
209
+ UI.message("Setting Metadata...")
210
+ content_type = Constants::CONTENT_TYPES[File.extname(file)&.delete('.').downcase.to_sym] || "application/octet-stream"
211
+ set_metadata_url = "#{upload_details['upload_domain']}/upload/set_metadata/#{upload_details['package_asset_id']}?file_name=#{File.basename(file)}&file_size=#{File.size(file)}&token=#{upload_details['url_encoded_token']}&content_type=#{content_type}"
212
+ chunk_size = Helper::AppcenterHelper.set_release_upload_metadata(set_metadata_url, api_token, owner_name, app_name, upload_id, timeout)
213
+ UI.abort_with_message!("Upload aborted") unless chunk_size
183
214
 
184
215
  UI.message("Uploading release binary...")
185
- uploaded = Helper::AppcenterHelper.upload_build(api_token, owner_name, app_name, file, upload_id, upload_url, timeout)
216
+ upload_url = "#{upload_details['upload_domain']}/upload/upload_chunk/#{upload_details['package_asset_id']}?token=#{upload_details['url_encoded_token']}"
217
+ uploaded = Helper::AppcenterHelper.upload_build(api_token, owner_name, app_name, file, upload_id, upload_url, content_type, chunk_size, timeout)
218
+ UI.abort_with_message!("Upload aborted") unless uploaded
219
+
220
+ UI.message("Finishing release...")
221
+ finish_url = "#{upload_details['upload_domain']}/upload/finished/#{upload_details['package_asset_id']}?token=#{upload_details['url_encoded_token']}"
222
+ finished = Helper::AppcenterHelper.finish_release_upload(finish_url, api_token, owner_name, app_name, upload_id, timeout)
223
+ UI.abort_with_message!("Upload aborted") unless finished
186
224
 
187
- if uploaded
188
- release_id = uploaded['release_id']
225
+ UI.message("Waiting for release to be ready...")
226
+ release_status_url = "v0.1/apps/#{owner_name}/#{app_name}/uploads/releases/#{upload_id}"
227
+ release_id = Helper::AppcenterHelper.poll_for_release_id(api_token, release_status_url)
228
+
229
+ if release_id.is_a? Integer
189
230
  release_url = Helper::AppcenterHelper.get_release_url(owner_type, owner_name, app_name, release_id)
190
231
  UI.message("Release '#{release_id}' committed: #{release_url}")
191
232
 
192
233
  release = Helper::AppcenterHelper.update_release(api_token, owner_name, app_name, release_id, release_notes)
193
- Helper::AppcenterHelper.update_release_metadata(api_token, owner_name, app_name, release_id, dsa_signature)
234
+ Helper::AppcenterHelper.update_release_metadata(api_token, owner_name, app_name, release_id, dsa_signature, ed_signature)
194
235
 
195
236
  destinations_array = []
196
237
  if destinations == '*'
@@ -244,10 +285,11 @@ module Fastlane
244
285
  app_platform = params[:app_platform]
245
286
 
246
287
  platforms = {
247
- Android: %w[Java React-Native Xamarin],
248
- iOS: %w[Objective-C-Swift React-Native Xamarin],
288
+ Android: %w[Java React-Native Xamarin Unity],
289
+ iOS: %w[Objective-C-Swift React-Native Xamarin Unity],
249
290
  macOS: %w[Objective-C-Swift],
250
- Windows: %w[UWP WPF WinForms Unity]
291
+ Windows: %w[UWP WPF WinForms Unity],
292
+ Custom: %w[Custom]
251
293
  }
252
294
 
253
295
  begin
@@ -276,6 +318,30 @@ module Fastlane
276
318
  end
277
319
  end
278
320
 
321
+ def self.add_app_to_distribution_group_if_needed(params)
322
+ return unless params[:destination_type] == 'group' && params[:owner_type] == 'organization' && params[:destinations] != '*'
323
+
324
+ app_distribution_groups = Helper::AppcenterHelper.fetch_distribution_groups(
325
+ api_token: params[:api_token],
326
+ owner_name: params[:owner_name],
327
+ app_name: params[:app_name]
328
+ )
329
+
330
+ group_names = app_distribution_groups.map { |g| g['name'] }
331
+ destination_names = params[:destinations].split(',').map(&:strip)
332
+
333
+ destination_names.each do |destination_name|
334
+ unless group_names.include? destination_name
335
+ Helper::AppcenterHelper.add_new_app_to_distribution_group(
336
+ api_token: params[:api_token],
337
+ owner_name: params[:owner_name],
338
+ app_name: params[:app_name],
339
+ destination_name: destination_name
340
+ )
341
+ end
342
+ end
343
+ end
344
+
279
345
  def self.run(params)
280
346
  values = params.values
281
347
  upload_build_only = params[:upload_build_only]
@@ -286,10 +352,10 @@ module Fastlane
286
352
 
287
353
  # if app found or successfully created
288
354
  if self.get_or_create_app(params)
355
+ self.add_app_to_distribution_group_if_needed(params)
289
356
  release = self.run_release_upload(params) unless upload_dsym_only || upload_mapping_only
290
357
  params[:version] = release['short_version'] if release
291
358
  params[:build_number] = release['version'] if release
292
-
293
359
  self.run_dsym_upload(params) unless upload_mapping_only || upload_build_only
294
360
  self.run_mapping_upload(params) unless upload_dsym_only || upload_build_only
295
361
  end
@@ -360,7 +426,7 @@ module Fastlane
360
426
 
361
427
  FastlaneCore::ConfigItem.new(key: :app_os,
362
428
  env_name: "APPCENTER_APP_OS",
363
- description: "App OS. Used for new app creation, if app 'app_name' was not found",
429
+ description: "App OS can be Android, iOS, macOS, Windows, Custom. Used for new app creation, if app 'app_name' was not found",
364
430
  optional: true,
365
431
  type: String),
366
432
 
@@ -569,7 +635,7 @@ module Fastlane
569
635
 
570
636
  FastlaneCore::ConfigItem.new(key: :timeout,
571
637
  env_name: "APPCENTER_DISTRIBUTE_TIMEOUT",
572
- description: "Request timeout in seconds",
638
+ description: "Request timeout in seconds applied to individual HTTP requests. Some commands use multiple HTTP requests, large file uploads are also split in multiple HTTP requests",
573
639
  optional: true,
574
640
  type: Integer),
575
641
 
@@ -578,7 +644,13 @@ module Fastlane
578
644
  description: "DSA signature of the macOS or Windows release for Sparkle update feed",
579
645
  optional: true,
580
646
  type: String),
581
-
647
+
648
+ FastlaneCore::ConfigItem.new(key: :ed_signature,
649
+ env_name: "APPCENTER_DISTRIBUTE_ED_SIGNATURE",
650
+ description: "EdDSA signature of the macOS or Windows release for Sparkle update feed",
651
+ optional: true,
652
+ type: String),
653
+
582
654
  FastlaneCore::ConfigItem.new(key: :strict,
583
655
  env_name: "APPCENTER_STRICT_MODE",
584
656
  description: "Strict mode, set to 'true' to fail early in case a potential error was detected",
@@ -1,7 +1,22 @@
1
+ class File
2
+ def each_chunk(chunk_size)
3
+ yield read(chunk_size) until eof?
4
+ end
5
+ end
6
+
1
7
  module Fastlane
2
8
  module Helper
3
9
  class AppcenterHelper
4
10
 
11
+ # Time to wait between 2 status polls in seconds
12
+ RELEASE_UPLOAD_STATUS_POLL_INTERVAL = 1
13
+
14
+ # Maximum number of retries for a request
15
+ MAX_REQUEST_RETRIES = 2
16
+
17
+ # Delay between retries in seconds
18
+ REQUEST_RETRY_INTERVAL = 5
19
+
5
20
  # basic utility method to check file types that App Center will accept,
6
21
  # accounting for file types that can and should be zip-compressed
7
22
  # before they are uploaded
@@ -18,10 +33,16 @@ module Fastlane
18
33
  require 'faraday'
19
34
  require 'faraday_middleware'
20
35
 
36
+ default_api_url = "https://api.appcenter.ms"
37
+ if ENV['APPCENTER_ENV']&.upcase == 'INT'
38
+ default_api_url = "https://api-gateway-core-integration.dev.avalanch.es"
39
+ end
21
40
  options = {
22
- url: upload_url || ENV.fetch('APPCENTER_UPLOAD_URL', "https://api.appcenter.ms")
41
+ url: upload_url || default_api_url
23
42
  }
24
43
 
44
+ UI.message("DEBUG: BASE URL #{options[:url]}") if ENV['DEBUG']
45
+
25
46
  Faraday.new(options) do |builder|
26
47
  if upload_url
27
48
  builder.request :multipart unless dsym
@@ -41,16 +62,20 @@ module Fastlane
41
62
  # upload_url
42
63
  def self.create_release_upload(api_token, owner_name, app_name, body)
43
64
  connection = self.connection
65
+ url = "v0.1/apps/#{owner_name}/#{app_name}/uploads/releases"
66
+ body ||= {}
44
67
 
45
- response = connection.post("v0.1/apps/#{owner_name}/#{app_name}/release_uploads") do |req|
68
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
69
+ UI.message("DEBUG: POST body: #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
70
+ response = connection.post(url) do |req|
46
71
  req.headers['X-API-Token'] = api_token
47
72
  req.headers['internal-request-source'] = "fastlane"
48
- req.body = body.nil? && {} || body
73
+ req.body = body
49
74
  end
50
75
 
76
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
51
77
  case response.status
52
78
  when 200...300
53
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
54
79
  response.body
55
80
  when 401
56
81
  UI.user_error!("Auth Error, provided invalid token")
@@ -59,7 +84,7 @@ module Fastlane
59
84
  UI.error("Not found, invalid owner or application name")
60
85
  false
61
86
  when 500...600
62
- UI.crash!("Internal Service Error, please try again later")
87
+ UI.abort_with_message!("Internal Service Error, please try again later")
63
88
  else
64
89
  UI.error("Error #{response.status}: #{response.body}")
65
90
  false
@@ -74,20 +99,27 @@ module Fastlane
74
99
  def self.create_mapping_upload(api_token, owner_name, app_name, file_name, build_number, version)
75
100
  connection = self.connection
76
101
 
77
- response = connection.post("v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads") do |req|
102
+ url = "v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads"
103
+ body = {
104
+ symbol_type: "AndroidProguard",
105
+ file_name: file_name,
106
+ build: build_number,
107
+ version: version,
108
+ }
109
+
110
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
111
+ UI.message("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
112
+
113
+ response = connection.post(url) do |req|
78
114
  req.headers['X-API-Token'] = api_token
79
115
  req.headers['internal-request-source'] = "fastlane"
80
- req.body = {
81
- symbol_type: "AndroidProguard",
82
- file_name: file_name,
83
- build: build_number,
84
- version: version,
85
- }
116
+ req.body = body
86
117
  end
87
118
 
119
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
120
+
88
121
  case response.status
89
122
  when 200...300
90
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
91
123
  response.body
92
124
  when 401
93
125
  UI.user_error!("Auth Error, provided invalid token")
@@ -109,17 +141,24 @@ module Fastlane
109
141
  def self.create_dsym_upload(api_token, owner_name, app_name)
110
142
  connection = self.connection
111
143
 
112
- response = connection.post("v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads") do |req|
144
+ url = "v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads"
145
+ body = {
146
+ symbol_type: 'Apple'
147
+ }
148
+
149
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
150
+ UI.message("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
151
+
152
+ response = connection.post(url) do |req|
113
153
  req.headers['X-API-Token'] = api_token
114
154
  req.headers['internal-request-source'] = "fastlane"
115
- req.body = {
116
- symbol_type: 'Apple'
117
- }
155
+ req.body = body
118
156
  end
119
157
 
158
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
159
+
120
160
  case response.status
121
161
  when 200...300
122
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
123
162
  response.body
124
163
  when 401
125
164
  UI.user_error!("Auth Error, provided invalid token")
@@ -137,17 +176,24 @@ module Fastlane
137
176
  def self.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, status)
138
177
  connection = self.connection
139
178
 
140
- response = connection.patch("v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads/#{symbol_upload_id}") do |req|
179
+ url = "v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads/#{symbol_upload_id}"
180
+ body = {
181
+ status: status
182
+ }
183
+
184
+ UI.message("DEBUG: PATCH #{url}") if ENV['DEBUG']
185
+ UI.message("DEBUG: PATCH body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
186
+
187
+ response = connection.patch(url) do |req|
141
188
  req.headers['X-API-Token'] = api_token
142
189
  req.headers['internal-request-source'] = "fastlane"
143
- req.body = {
144
- "status" => status
145
- }
190
+ req.body = body
146
191
  end
147
192
 
193
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
194
+
148
195
  case response.status
149
196
  when 200...300
150
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
151
197
  response.body
152
198
  when 401
153
199
  UI.user_error!("Auth Error, provided invalid token")
@@ -164,6 +210,9 @@ module Fastlane
164
210
  def self.upload_symbol(api_token, owner_name, app_name, symbol, symbol_type, symbol_upload_id, upload_url)
165
211
  connection = self.connection(upload_url, true)
166
212
 
213
+ UI.message("DEBUG: PUT #{upload_url}") if ENV['DEBUG']
214
+ UI.message("DEBUG: PUT body <data>\n") if ENV['DEBUG']
215
+
167
216
  response = connection.put do |req|
168
217
  req.headers['x-ms-blob-type'] = "BlockBlob"
169
218
  req.headers['Content-Length'] = File.size(symbol).to_s
@@ -171,77 +220,183 @@ module Fastlane
171
220
  req.body = Faraday::UploadIO.new(symbol, 'application/octet-stream') if symbol && File.exist?(symbol)
172
221
  end
173
222
 
174
- logType = "dSYM" if (symbol_type == "Apple")
175
- logType = "mapping" if (symbol_type == "Android")
223
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
224
+
225
+ log_type = "dSYM" if symbol_type == "Apple"
226
+ log_type = "mapping" if symbol_type == "Android"
176
227
 
177
228
  case response.status
178
229
  when 200...300
179
230
  self.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, 'committed')
180
- UI.success("#{logType} uploaded")
231
+ UI.success("#{log_type} uploaded")
181
232
  when 401
182
233
  UI.user_error!("Auth Error, provided invalid token")
183
234
  false
184
235
  else
185
- UI.error("Error uploading #{logType} #{response.status}: #{response.body}")
236
+ UI.error("Error uploading #{log_type} #{response.status}: #{response.body}")
186
237
  self.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, 'aborted')
187
- UI.error("#{logType} upload aborted")
238
+ UI.error("#{log_type} upload aborted")
188
239
  false
189
240
  end
190
241
  end
191
242
 
192
- # upload binary for specified upload_url
193
- # if succeed, then commits the release
194
- # otherwise aborts
195
- def self.upload_build(api_token, owner_name, app_name, file, upload_id, upload_url, timeout)
196
- connection = self.connection(upload_url)
243
+ # sets metadata for new upload in App Center
244
+ # returns:
245
+ # chunk size
246
+ def self.set_release_upload_metadata(set_metadata_url, api_token, owner_name, app_name, upload_id, timeout)
247
+ connection = self.connection(set_metadata_url)
197
248
 
198
- options = {}
199
- options[:upload_id] = upload_id
200
- # ipa field is used for .apk, .aab and .ipa files
201
- options[:ipa] = Faraday::UploadIO.new(file, 'application/octet-stream') if file && File.exist?(file)
249
+ UI.message("DEBUG: POST #{set_metadata_url}") if ENV['DEBUG']
250
+ UI.message("DEBUG: POST body <data>\n") if ENV['DEBUG']
251
+ response = connection.post do |req|
252
+ req.options.timeout = timeout
253
+ req.headers['internal-request-source'] = "fastlane"
254
+ end
255
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
202
256
 
257
+ case response.status
258
+ when 200...300
259
+ chunk_size = response.body['chunk_size']
260
+ unless chunk_size.is_a? Integer
261
+ UI.error("Set metadata didn't return chunk size: #{response.status}: #{response.body}")
262
+ false
263
+ else
264
+ UI.message("Metadata set")
265
+ chunk_size
266
+ end
267
+ when 401
268
+ UI.user_error!("Auth Error, provided invalid token")
269
+ false
270
+ else
271
+ UI.error("Error setting metadata: #{response.status}: #{response.body}")
272
+ false
273
+ end
274
+ end
275
+
276
+ # Verifies a successful upload to App Center
277
+ # returns:
278
+ # successful upload response body.
279
+ def self.finish_release_upload(finish_url, api_token, owner_name, app_name, upload_id, timeout)
280
+ connection = self.connection(finish_url)
281
+
282
+ UI.message("DEBUG: POST #{finish_url}") if ENV['DEBUG']
203
283
  response = connection.post do |req|
204
284
  req.options.timeout = timeout
205
285
  req.headers['internal-request-source'] = "fastlane"
206
- req.body = options
207
286
  end
287
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
208
288
 
209
289
  case response.status
210
290
  when 200...300
211
- UI.message("Binary uploaded")
212
- self.update_release_upload(api_token, owner_name, app_name, upload_id, 'committed')
291
+ if response.body['error'] == false
292
+ UI.message("Upload finished")
293
+ self.update_release_upload(api_token, owner_name, app_name, upload_id, 'uploadFinished')
294
+ else
295
+ UI.error("Error finishing upload: #{response.body['message']}")
296
+ false
297
+ end
213
298
  when 401
214
299
  UI.user_error!("Auth Error, provided invalid token")
215
300
  false
216
301
  else
217
- UI.error("Error uploading binary #{response.status}: #{response.body}")
218
- self.update_release_upload(api_token, owner_name, app_name, upload_id, 'aborted')
219
- UI.error("Release aborted")
302
+ UI.error("Error finishing upload: #{response.status}: #{response.body}")
220
303
  false
221
304
  end
222
305
  end
223
306
 
307
+ # upload binary for specified upload_url
308
+ # if succeed, then commits the release
309
+ # otherwise aborts
310
+ def self.upload_build(api_token, owner_name, app_name, file, upload_id, upload_url, content_type, chunk_size, timeout)
311
+ block_number = 1
312
+
313
+ File.open(file).each_chunk(chunk_size) do |chunk|
314
+ upload_chunk_url = "#{upload_url}&block_number=#{block_number}"
315
+ retries = 0
316
+
317
+ while retries <= MAX_REQUEST_RETRIES
318
+ begin
319
+ connection = self.connection(upload_chunk_url, true)
320
+
321
+ UI.message("DEBUG: POST #{upload_chunk_url}") if ENV['DEBUG']
322
+ UI.message("DEBUG: POST body <data>\n") if ENV['DEBUG']
323
+ response = connection.post do |req|
324
+ req.options.timeout = timeout
325
+ req.headers['internal-request-source'] = "fastlane"
326
+ req.headers['Content-Length'] = chunk.length.to_s
327
+ req.headers['Content-Type'] = 'application/octet-stream'
328
+ req.body = chunk
329
+ end
330
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
331
+ status = response.status
332
+ message = response.body
333
+ rescue Faraday::Error => e
334
+
335
+ # Low level HTTP errors, we will retry them
336
+ status = 0
337
+ message = e.message
338
+ end
339
+
340
+ case status
341
+ when 200...300
342
+ if response.body['error'] == false
343
+ UI.message("Chunk uploaded")
344
+ block_number += 1
345
+ break
346
+ else
347
+ UI.error("Error uploading binary #{response.body['message']}")
348
+ return false
349
+ end
350
+ when 401
351
+ UI.user_error!("Auth Error, provided invalid token")
352
+ return false
353
+ when 400...407, 409...428, 430...499
354
+ UI.user_error!("Client error: #{response.status}: #{response.body}")
355
+ return false
356
+ else
357
+ if retries < MAX_REQUEST_RETRIES
358
+ UI.message("DEBUG: Retryable error uploading binary #{status}: #{message}")
359
+ retries += 1
360
+ sleep(REQUEST_RETRY_INTERVAL)
361
+ else
362
+ UI.error("Error uploading binary #{status}: #{message}")
363
+ return false
364
+ end
365
+ end
366
+ end
367
+ end
368
+ UI.message("Binary uploaded")
369
+ end
370
+
224
371
  # Commits or aborts the upload process for a release
225
372
  def self.update_release_upload(api_token, owner_name, app_name, upload_id, status)
226
373
  connection = self.connection
227
374
 
228
- response = connection.patch("v0.1/apps/#{owner_name}/#{app_name}/release_uploads/#{upload_id}") do |req|
375
+ url = "v0.1/apps/#{owner_name}/#{app_name}/uploads/releases/#{upload_id}"
376
+ body = {
377
+ upload_status: status,
378
+ id: upload_id
379
+ }
380
+
381
+ UI.message("DEBUG: PATCH #{url}") if ENV['DEBUG']
382
+ UI.message("DEBUG: PATCH body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
383
+
384
+ response = connection.patch(url) do |req|
229
385
  req.headers['X-API-Token'] = api_token
230
386
  req.headers['internal-request-source'] = "fastlane"
231
- req.body = {
232
- "status" => status
233
- }
387
+ req.body = body
234
388
  end
235
389
 
390
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
391
+
236
392
  case response.status
237
393
  when 200...300
238
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
239
394
  response.body
240
395
  when 401
241
396
  UI.user_error!("Auth Error, provided invalid token")
242
397
  false
243
398
  when 500...600
244
- UI.crash!("Internal Service Error, please try again later")
399
+ UI.abort_with_message!("Internal Service Error, please try again later")
245
400
  else
246
401
  UI.error("Error #{response.status}: #{response.body}")
247
402
  false
@@ -251,15 +406,21 @@ module Fastlane
251
406
  # get existing release
252
407
  def self.get_release(api_token, owner_name, app_name, release_id)
253
408
  connection = self.connection
254
- response = connection.get("v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}") do |req|
409
+
410
+ url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}"
411
+
412
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
413
+
414
+ response = connection.get(url) do |req|
255
415
  req.headers['X-API-Token'] = api_token
256
416
  req.headers['internal-request-source'] = "fastlane"
257
417
  end
258
418
 
419
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
420
+
259
421
  case response.status
260
422
  when 200...300
261
423
  release = response.body
262
- UI.message("DEBUG: #{JSON.pretty_generate(release)}") if ENV['DEBUG']
263
424
  release
264
425
  when 404
265
426
  UI.error("Not found, invalid release url")
@@ -273,19 +434,58 @@ module Fastlane
273
434
  end
274
435
  end
275
436
 
437
+ # Polls the upload for a release id. When a release is uploaded, we have to check
438
+ # for a successful extraction before we can continue.
439
+ # returns:
440
+ # release_distinct_id
441
+ def self.poll_for_release_id(api_token, url)
442
+ connection = self.connection
443
+
444
+ while true
445
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
446
+ response = connection.get(url) do |req|
447
+ req.headers['X-API-Token'] = api_token
448
+ req.headers['internal-request-source'] = "fastlane"
449
+ end
450
+
451
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
452
+
453
+ case response.status
454
+ when 200...300
455
+ case response.body['upload_status']
456
+ when "readyToBePublished"
457
+ return response.body['release_distinct_id']
458
+ when "error"
459
+ UI.error("Error fetching release: #{response.body['error_details']}")
460
+ return false
461
+ else
462
+ sleep(RELEASE_UPLOAD_STATUS_POLL_INTERVAL)
463
+ end
464
+ else
465
+ UI.error("Error fetching information about release #{response.status}: #{response.body}")
466
+ return false
467
+ end
468
+ end
469
+ end
470
+
276
471
  # get distribution group or store
277
472
  def self.get_destination(api_token, owner_name, app_name, destination_type, destination_name)
278
473
  connection = self.connection
279
474
 
280
- response = connection.get("v0.1/apps/#{owner_name}/#{app_name}/distribution_#{destination_type}s/#{ERB::Util.url_encode(destination_name)}") do |req|
475
+ url = "v0.1/apps/#{owner_name}/#{app_name}/distribution_#{destination_type}s/#{ERB::Util.url_encode(destination_name)}"
476
+
477
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
478
+
479
+ response = connection.get(url) do |req|
281
480
  req.headers['X-API-Token'] = api_token
282
481
  req.headers['internal-request-source'] = "fastlane"
283
482
  end
284
483
 
484
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
485
+
285
486
  case response.status
286
487
  when 200...300
287
488
  destination = response.body
288
- UI.message("DEBUG: received #{destination_type} #{JSON.pretty_generate(destination)}") if ENV['DEBUG']
289
489
  destination
290
490
  when 404
291
491
  UI.error("Not found, invalid distribution #{destination_type} name")
@@ -303,14 +503,22 @@ module Fastlane
303
503
  def self.update_release(api_token, owner_name, app_name, release_id, release_notes = '')
304
504
  connection = self.connection
305
505
 
306
- response = connection.put("v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}") do |req|
506
+ url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}"
507
+ body = {
508
+ release_notes: release_notes
509
+ }
510
+
511
+ UI.message("DEBUG: PUT #{url}") if ENV['DEBUG']
512
+ UI.message("DEBUG: PUT body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
513
+
514
+ response = connection.put(url) do |req|
307
515
  req.headers['X-API-Token'] = api_token
308
516
  req.headers['internal-request-source'] = "fastlane"
309
- req.body = {
310
- release_notes: release_notes
311
- }
517
+ req.body = body
312
518
  end
313
519
 
520
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
521
+
314
522
  case response.status
315
523
  when 200...300
316
524
  # get full release info
@@ -319,8 +527,6 @@ module Fastlane
319
527
 
320
528
  download_url = release['download_url']
321
529
 
322
- UI.message("DEBUG: #{JSON.pretty_generate(release)}") if ENV['DEBUG']
323
-
324
530
  Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_DOWNLOAD_LINK] = download_url
325
531
  Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_BUILD_INFORMATION] = release
326
532
 
@@ -340,22 +546,33 @@ module Fastlane
340
546
  end
341
547
 
342
548
  # updates release metadata
343
- def self.update_release_metadata(api_token, owner_name, app_name, release_id, dsa_signature)
344
- return if dsa_signature.to_s == ''
549
+ def self.update_release_metadata(api_token, owner_name, app_name, release_id, dsa_signature = '', ed_signature = '')
550
+ return if dsa_signature.to_s == '' && ed_signature.to_s == ''
345
551
 
346
- release_metadata = {
347
- dsa_signature: dsa_signature
552
+ url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}"
553
+ body = {
554
+ metadata: {}
348
555
  }
556
+
557
+ if dsa_signature.to_s != ''
558
+ body[:metadata]["dsa_signature"] = dsa_signature
559
+ end
560
+ if ed_signature.to_s != ''
561
+ body[:metadata]["ed_signature"] = ed_signature
562
+ end
563
+
564
+ UI.message("DEBUG: PATCH #{url}") if ENV['DEBUG']
565
+ UI.message("DEBUG: PATCH body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
349
566
 
350
567
  connection = self.connection
351
- response = connection.patch("v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}") do |req|
568
+ response = connection.patch(url) do |req|
352
569
  req.headers['X-API-Token'] = api_token
353
570
  req.headers['internal-request-source'] = "fastlane"
354
- req.body = {
355
- metadata: release_metadata
356
- }
571
+ req.body = body
357
572
  end
358
573
 
574
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
575
+
359
576
  case response.status
360
577
  when 200...300
361
578
  UI.message("Release Metadata was successfully updated for release '#{release_id}'")
@@ -370,25 +587,32 @@ module Fastlane
370
587
  false
371
588
  end
372
589
  end
373
-
590
+
374
591
  # add release to distribution group or store
375
592
  def self.add_to_destination(api_token, owner_name, app_name, release_id, destination_type, destination_id, mandatory_update = false, notify_testers = false)
376
593
  connection = self.connection
377
594
 
378
- UI.message("DEBUG: getting #{release_id}") if ENV['DEBUG']
595
+ url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}/#{destination_type}s"
596
+ body = {
597
+ id: destination_id
598
+ }
379
599
 
380
- body = { "id" => destination_id }
381
600
  if destination_type == "group"
382
601
  body["mandatory_update"] = mandatory_update
383
602
  body["notify_testers"] = notify_testers
384
603
  end
385
604
 
386
- response = connection.post("v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}/#{destination_type}s") do |req|
605
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
606
+ UI.message("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
607
+
608
+ response = connection.post(url) do |req|
387
609
  req.headers['X-API-Token'] = api_token
388
610
  req.headers['internal-request-source'] = "fastlane"
389
611
  req.body = body
390
612
  end
391
613
 
614
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
615
+
392
616
  case response.status
393
617
  when 200...300
394
618
  # get full release info
@@ -397,8 +621,6 @@ module Fastlane
397
621
 
398
622
  download_url = release['download_url']
399
623
 
400
- UI.message("DEBUG: received release #{JSON.pretty_generate(release)}") if ENV['DEBUG']
401
-
402
624
  Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_DOWNLOAD_LINK] = download_url
403
625
  Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_BUILD_INFORMATION] = release
404
626
 
@@ -421,11 +643,17 @@ module Fastlane
421
643
  def self.get_app(api_token, owner_name, app_name)
422
644
  connection = self.connection
423
645
 
424
- response = connection.get("v0.1/apps/#{owner_name}/#{app_name}") do |req|
646
+ url = "v0.1/apps/#{owner_name}/#{app_name}"
647
+
648
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
649
+
650
+ response = connection.get(url) do |req|
425
651
  req.headers['X-API-Token'] = api_token
426
652
  req.headers['internal-request-source'] = "fastlane"
427
653
  end
428
654
 
655
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
656
+
429
657
  case response.status
430
658
  when 200...300
431
659
  UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
@@ -446,23 +674,28 @@ module Fastlane
446
674
  def self.create_app(api_token, owner_type, owner_name, app_name, app_display_name, os, platform)
447
675
  connection = self.connection
448
676
 
449
- endpoint = owner_type == "user" ? "v0.1/apps" : "v0.1/orgs/#{owner_name}/apps"
677
+ url = owner_type == "user" ? "v0.1/apps" : "v0.1/orgs/#{owner_name}/apps"
678
+ body = {
679
+ display_name: app_display_name,
680
+ name: app_name,
681
+ os: os,
682
+ platform: platform
683
+ }
684
+
685
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
686
+ UI.message("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
450
687
 
451
- response = connection.post(endpoint) do |req|
688
+ response = connection.post(url) do |req|
452
689
  req.headers['X-API-Token'] = api_token
453
690
  req.headers['internal-request-source'] = "fastlane"
454
- req.body = {
455
- "display_name" => app_display_name,
456
- "name" => app_name,
457
- "os" => os,
458
- "platform" => platform
459
- }
691
+ req.body = body
460
692
  end
461
693
 
694
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
695
+
462
696
  case response.status
463
697
  when 200...300
464
698
  created = response.body
465
- UI.message("DEBUG: #{JSON.pretty_generate(created)}") if ENV['DEBUG']
466
699
  UI.success("Created #{os}/#{platform} app with name \"#{created['name']}\" and display name \"#{created['display_name']}\" for #{owner_type} \"#{owner_name}\"")
467
700
  true
468
701
  when 401
@@ -477,16 +710,19 @@ module Fastlane
477
710
  def self.fetch_distribution_groups(api_token:, owner_name:, app_name:)
478
711
  connection = self.connection
479
712
 
480
- endpoint = "/v0.1/apps/#{owner_name}/#{app_name}/distribution_groups"
713
+ url = "/v0.1/apps/#{owner_name}/#{app_name}/distribution_groups"
481
714
 
482
- response = connection.get(endpoint) do |req|
715
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
716
+
717
+ response = connection.get(url) do |req|
483
718
  req.headers['X-API-Token'] = api_token
484
719
  req.headers['internal-request-source'] = "fastlane"
485
720
  end
486
721
 
722
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
723
+
487
724
  case response.status
488
725
  when 200...300
489
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
490
726
  response.body
491
727
  when 401
492
728
  UI.user_error!("Auth Error, provided invalid token")
@@ -503,16 +739,19 @@ module Fastlane
503
739
  def self.fetch_devices(api_token:, owner_name:, app_name:, distribution_group:)
504
740
  connection = self.connection(nil, false, true)
505
741
 
506
- endpoint = "/v0.1/apps/#{owner_name}/#{app_name}/distribution_groups/#{ERB::Util.url_encode(distribution_group)}/devices/download_devices_list"
742
+ url = "/v0.1/apps/#{owner_name}/#{app_name}/distribution_groups/#{ERB::Util.url_encode(distribution_group)}/devices/download_devices_list"
743
+
744
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
507
745
 
508
- response = connection.get(endpoint) do |req|
746
+ response = connection.get(url) do |req|
509
747
  req.headers['X-API-Token'] = api_token
510
748
  req.headers['internal-request-source'] = "fastlane"
511
749
  end
512
750
 
751
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
752
+
513
753
  case response.status
514
754
  when 200...300
515
- UI.message("DEBUG: #{response.body.inspect}") if ENV['DEBUG']
516
755
  response.body
517
756
  when 401
518
757
  UI.user_error!("Auth Error, provided invalid token")
@@ -526,17 +765,87 @@ module Fastlane
526
765
  end
527
766
  end
528
767
 
529
- # Note: This does not support testing environment (INT)
768
+ def self.fetch_releases(api_token:, owner_name:, app_name:)
769
+ connection = self.connection(nil, false, true)
770
+
771
+ url = "/v0.1/apps/#{owner_name}/#{app_name}/releases"
772
+
773
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
774
+
775
+ response = connection.get(url) do |req|
776
+ req.headers['X-API-Token'] = api_token
777
+ req.headers['internal-request-source'] = "fastlane"
778
+ end
779
+
780
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
781
+
782
+ case response.status
783
+ when 200...300
784
+ JSON.parse(response.body)
785
+ when 401
786
+ UI.user_error!("Auth Error, provided invalid token")
787
+ false
788
+ when 404
789
+ UI.error("Not found, invalid owner or application name")
790
+ false
791
+ else
792
+ UI.error("Error #{response.status}: #{response.body}")
793
+ false
794
+ end
795
+ end
796
+
530
797
  def self.get_release_url(owner_type, owner_name, app_name, release_id)
531
798
  owner_path = owner_type == "user" ? "users/#{owner_name}" : "orgs/#{owner_name}"
799
+ if ENV['APPCENTER_ENV']&.upcase == 'INT'
800
+ return "https://portal-server-core-integration.dev.avalanch.es/#{owner_path}/apps/#{app_name}/distribute/releases/#{release_id}"
801
+ end
802
+
532
803
  return "https://appcenter.ms/#{owner_path}/apps/#{app_name}/distribute/releases/#{release_id}"
533
804
  end
534
805
 
535
- # Note: This does not support testing environment (INT)
536
806
  def self.get_install_url(owner_type, owner_name, app_name)
537
807
  owner_path = owner_type == "user" ? "users/#{owner_name}" : "orgs/#{owner_name}"
808
+ if ENV['APPCENTER_ENV']&.upcase == 'INT'
809
+ return "https://install.portal-server-core-integration.dev.avalanch.es/#{owner_path}/apps/#{app_name}"
810
+ end
811
+
538
812
  return "https://install.appcenter.ms/#{owner_path}/apps/#{app_name}"
539
813
  end
814
+
815
+ # add new created app to existing distribution group
816
+ def self.add_new_app_to_distribution_group(api_token:, owner_name:, app_name:, destination_name:)
817
+ url = URI.escape("/v0.1/orgs/#{owner_name}/distribution_groups/#{destination_name}/apps")
818
+ body = {
819
+ apps: [
820
+ { name: app_name }
821
+ ]
822
+ }
823
+
824
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
825
+ UI.message("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
826
+
827
+ response = connection.post(url) do |req|
828
+ req.headers['X-API-Token'] = api_token
829
+ req.headers['internal-request-source'] = "fastlane"
830
+ req.body = body
831
+ end
832
+
833
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
834
+
835
+ case response.status
836
+ when 200...300
837
+ created = response.body
838
+ UI.success("Added new app #{app_name} to distribution group #{destination_name}")
839
+ when 401
840
+ UI.user_error!("Auth Error, provided invalid token")
841
+ when 404
842
+ UI.error("Not found, invalid distribution group name #{destination_name}")
843
+ when 409
844
+ UI.success("App already added to distribution group #{destination_name}")
845
+ else
846
+ UI.error("Error adding app to distribution group #{response.status}: #{response.body}")
847
+ end
848
+ end
540
849
  end
541
850
  end
542
851
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Appcenter
3
- VERSION = "1.7.1"
3
+ VERSION = "1.11.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-appcenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Microsoft Corporation
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-04 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,8 +108,22 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.77.0
111
- description:
112
- email:
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
113
127
  executables: []
114
128
  extensions: []
115
129
  extra_rdoc_files: []
@@ -118,6 +132,7 @@ files:
118
132
  - README.md
119
133
  - lib/fastlane/plugin/appcenter.rb
120
134
  - lib/fastlane/plugin/appcenter/actions/appcenter_fetch_devices_action.rb
135
+ - lib/fastlane/plugin/appcenter/actions/appcenter_fetch_version_number.rb
121
136
  - lib/fastlane/plugin/appcenter/actions/appcenter_upload_action.rb
122
137
  - lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb
123
138
  - lib/fastlane/plugin/appcenter/version.rb
@@ -125,7 +140,7 @@ homepage: https://github.com/microsoft/fastlane-plugin-appcenter
125
140
  licenses:
126
141
  - MIT
127
142
  metadata: {}
128
- post_install_message:
143
+ post_install_message:
129
144
  rdoc_options: []
130
145
  require_paths:
131
146
  - lib
@@ -140,8 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
155
  - !ruby/object:Gem::Version
141
156
  version: '0'
142
157
  requirements: []
143
- rubygems_version: 3.0.4
144
- signing_key:
158
+ rubygems_version: 3.0.3
159
+ signing_key:
145
160
  specification_version: 4
146
161
  summary: Fastlane plugin for App Center
147
162
  test_files: []