Skip to content
This repository was archived by the owner on May 3, 2023. It is now read-only.

Commit 9633ba5

Browse files
authored
Ignore device registration errors (#142)
* Supress device registration errors due to invalid UDID or registering Mac device
1 parent 12b58e2 commit 9633ba5

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

.rubocop_todo.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2021-02-08 17:52:56 +0100 using RuboCop version 0.61.1.
3+
# on 2021-02-23 11:55:14 +0100 using RuboCop version 0.61.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -16,7 +16,7 @@ Layout/AlignHash:
1616
Exclude:
1717
- 'lib/autoprovision/portal/app_client.rb'
1818

19-
# Offense count: 16
19+
# Offense count: 15
2020
# Cop supports --auto-correct.
2121
Layout/EmptyLineAfterGuardClause:
2222
Exclude:
@@ -25,7 +25,6 @@ Layout/EmptyLineAfterGuardClause:
2525
- 'lib/autoprovision/device.rb'
2626
- 'lib/autoprovision/portal/app_client.rb'
2727
- 'lib/autoprovision/portal/common.rb'
28-
- 'lib/autoprovision/portal/device_client.rb'
2928
- 'lib/autoprovision/project_helper.rb'
3029
- 'log/log.rb'
3130
- 'params.rb'
@@ -56,11 +55,11 @@ Layout/TrailingBlankLines:
5655
Metrics/AbcSize:
5756
Max: 65
5857

59-
# Offense count: 1
58+
# Offense count: 2
6059
# Configuration parameters: CountComments, ExcludedMethods.
6160
# ExcludedMethods: refine
6261
Metrics/BlockLength:
63-
Max: 28
62+
Max: 32
6463

6564
# Offense count: 4
6665
# Configuration parameters: CountComments.
@@ -81,7 +80,7 @@ Metrics/MethodLength:
8180
Metrics/ParameterLists:
8281
Max: 8
8382

84-
# Offense count: 14
83+
# Offense count: 13
8584
Metrics/PerceivedComplexity:
8685
Max: 22
8786

@@ -124,7 +123,7 @@ Style/StringLiterals:
124123
Exclude:
125124
- 'main.rb'
126125

127-
# Offense count: 231
126+
# Offense count: 234
128127
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
129128
# URISchemes: http, https
130129
Metrics/LineLength:

lib/autoprovision/portal/device_client.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Portal
77
class DeviceClient
88
def self.ensure_test_devices(test_devices, device_client = Spaceship::Portal.device)
99
if test_devices.to_a.empty?
10-
Log.success('no test devices registered on bitrise')
10+
Log.success('No test devices registered on Bitrise.')
1111
return
1212
end
1313

@@ -26,6 +26,7 @@ def self.ensure_test_devices(test_devices, device_client = Spaceship::Portal.dev
2626
portal_devices = fetch_devices(device_client)
2727

2828
new_device_registered = false
29+
valid_devices = []
2930
test_devices.each do |test_device|
3031
registered_test_device = nil
3132

@@ -43,20 +44,22 @@ def self.ensure_test_devices(test_devices, device_client = Spaceship::Portal.dev
4344
registered_test_device = device_client.create!(name: test_device.name, udid: test_device.udid)
4445
rescue Spaceship::Client::UnexpectedResponse => ex
4546
message = result_string(ex)
46-
raise ex unless message
47-
raise message
47+
Log.warn("Failed to register device with name: #{test_device.name} udid: #{test_device.udid} error: #{message}")
48+
next
4849
rescue
49-
raise "Failed to register device with name: #{test_device.name} udid: #{test_device.udid}"
50+
Log.warn("Failed to register device with name: #{test_device.name} udid: #{test_device.udid}")
51+
next
5052
end
5153

5254
Log.success("registering test device #{registered_test_device.name} (#{registered_test_device.udid})")
5355
end
5456

57+
valid_devices = valid_devices.append(test_device)
5558
raise 'failed to find or create device' unless registered_test_device
5659
end
5760

58-
Log.success("every test devices (#{test_devices.length}) registered on bitrise are registered on developer portal")
59-
[new_device_registered, portal_devices]
61+
Log.success("#{valid_devices.length} Bitrise test devices are present on Apple Developer Portal.")
62+
valid_devices
6063
end
6164

6265
def self.fetch_devices(device_client = Spaceship::Portal.device)

spec/device_client_spec.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@
1717
allow(fake_portal_client).to receive(:all).and_return(nil)
1818
allow(fake_portal_client).to receive(:create!).and_return(fake_portal_device)
1919

20-
Portal::DeviceClient.ensure_test_devices([device], fake_portal_client)
20+
valid_devices = Portal::DeviceClient.ensure_test_devices([device], fake_portal_client)
21+
22+
expect(valid_devices).to eq([device])
23+
end
24+
25+
it 'supresses error due to invalid od mac device UDID' do
26+
existing_device = Device.new(
27+
'device_identifier' => '123456',
28+
'title' => 'Existing Device'
29+
)
30+
invalid_device = Device.new(
31+
'device_identifier' => 'invalid-udid',
32+
'title' => 'Invalid Device'
33+
)
34+
35+
fake_portal_device = double
36+
allow(fake_portal_device).to receive(:name).and_return(existing_device.name)
37+
allow(fake_portal_device).to receive(:udid).and_return(existing_device.udid)
38+
39+
fake_portal_client = double
40+
allow(fake_portal_client).to receive(:all).and_return([fake_portal_device])
41+
allow(fake_portal_client).to receive(:create!).and_raise('error')
42+
43+
valid_devices = Portal::DeviceClient.ensure_test_devices([existing_device, invalid_device], fake_portal_client)
44+
45+
expect(valid_devices).to eq([existing_device])
2146
end
2247
end

step.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,18 @@
7777
###
7878

7979
# Ensure test devices
80+
valid_devices = []
8081
if ['development', 'ad-hoc'].include?(params.distribution_type)
8182
Log.info('Ensure test devices on Developer Portal')
82-
Portal::DeviceClient.ensure_test_devices(auth.test_devices)
83+
valid_devices = Portal::DeviceClient.ensure_test_devices(auth.test_devices)
8384
end
8485
###
8586

8687
# Ensure Provisioning Profiles on Developer Portal
8788
Log.info('Ensure Provisioning Profiles on Developer Portal')
8889

8990
profile_helper = ProfileHelper.new(project_helper, cert_helper)
90-
xcode_managed_signing = profile_helper.ensure_profiles(params.distribution_type, auth.test_devices, params.generate_profiles == 'yes', params.min_profile_days_valid)
91+
xcode_managed_signing = profile_helper.ensure_profiles(params.distribution_type, valid_devices, params.generate_profiles == 'yes', params.min_profile_days_valid)
9192
###
9293

9394
unless xcode_managed_signing

0 commit comments

Comments
 (0)