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

Commit 00801c9

Browse files
authored
Step 204 mac device registration (#145)
* Ignore device registration errors due to invalid UDID or mac device.
1 parent 13ead42 commit 00801c9

File tree

4 files changed

+55
-17
lines changed

4 files changed

+55
-17
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-24 19:09:31 +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: 38
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: 235
128127
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
129128
# URISchemes: http, https
130129
Metrics/LineLength:

lib/autoprovision/portal/device_client.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ module Portal
66
# DeviceClient ...
77
class DeviceClient
88
def self.ensure_test_devices(test_devices, device_client = Spaceship::Portal.device)
9+
valid_devices = []
910
if test_devices.to_a.empty?
10-
Log.success('no test devices registered on bitrise')
11-
return
11+
Log.success('No test devices registered on Bitrise.')
12+
13+
valid_devices
1214
end
1315

1416
# Log the duplicated devices (by udid)
@@ -43,20 +45,22 @@ def self.ensure_test_devices(test_devices, device_client = Spaceship::Portal.dev
4345
registered_test_device = device_client.create!(name: test_device.name, udid: test_device.udid)
4446
rescue Spaceship::Client::UnexpectedResponse => ex
4547
message = result_string(ex)
46-
raise ex unless message
47-
raise message
48+
Log.warn("Failed to register device with name: #{test_device.name} udid: #{test_device.udid} error: #{message}")
49+
next
4850
rescue
49-
raise "Failed to register device with name: #{test_device.name} udid: #{test_device.udid}"
51+
Log.warn("Failed to register device with name: #{test_device.name} udid: #{test_device.udid}")
52+
next
5053
end
5154

5255
Log.success("registering test device #{registered_test_device.name} (#{registered_test_device.udid})")
5356
end
5457

58+
valid_devices = valid_devices.append(test_device)
5559
raise 'failed to find or create device' unless registered_test_device
5660
end
5761

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

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

spec/device_client_spec.rb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
require_relative '../log/log'
44

55
RSpec.describe '.ensure_test_devices' do
6+
it 'returns empty array for empty input' do
7+
fake_portal_client = double
8+
allow(fake_portal_client).to receive(:all).and_return(nil)
9+
10+
valid_devices = Portal::DeviceClient.ensure_test_devices([], fake_portal_client)
11+
12+
expect(valid_devices).to eq([])
13+
end
14+
615
it 'it registers new device' do
716
device = Device.new(
817
'device_identifier' => '123456',
@@ -17,6 +26,31 @@
1726
allow(fake_portal_client).to receive(:all).and_return(nil)
1827
allow(fake_portal_client).to receive(:create!).and_return(fake_portal_device)
1928

20-
Portal::DeviceClient.ensure_test_devices([device], fake_portal_client)
29+
valid_devices = Portal::DeviceClient.ensure_test_devices([device], fake_portal_client)
30+
31+
expect(valid_devices).to eq([device])
32+
end
33+
34+
it 'supresses error due to invalid or mac device UDID' do
35+
existing_device = Device.new(
36+
'device_identifier' => '123456',
37+
'title' => 'Existing Device'
38+
)
39+
invalid_device = Device.new(
40+
'device_identifier' => 'invalid-udid',
41+
'title' => 'Invalid Device'
42+
)
43+
44+
fake_portal_device = double
45+
allow(fake_portal_device).to receive(:name).and_return(existing_device.name)
46+
allow(fake_portal_device).to receive(:udid).and_return(existing_device.udid)
47+
48+
fake_portal_client = double
49+
allow(fake_portal_client).to receive(:all).and_return([fake_portal_device])
50+
allow(fake_portal_client).to receive(:create!).and_raise('error')
51+
52+
valid_devices = Portal::DeviceClient.ensure_test_devices([existing_device, invalid_device], fake_portal_client)
53+
54+
expect(valid_devices).to eq([existing_device])
2155
end
2256
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)