This repository has been archived by the owner on May 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
step.rb
executable file
·219 lines (167 loc) · 8.28 KB
/
step.rb
1
2
3
4
5
6
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
33
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
require_relative 'params'
require_relative 'log/log'
require_relative 'lib/autoprovision'
begin
# Params
params = Params.new
params.print
params.validate
Log.verbose = (params.verbose_log == 'yes')
###
Log.warn("\n")
Log.warn('This Step has been deprecated in favour of the new automatic code signing options on Bitrise.')
Log.warn("
Option A)
The latest versions of the [Xcode Archive & Export for iOS](https://www.bitrise.io/integrations/steps/xcode-archive),
[Xcode Build for testing for iOS](https://www.bitrise.io/integrations/steps/xcode-build-for-test),
and the [Export iOS and tvOS Xcode archive](https://www.bitrise.io/integrations/steps/xcode-archive) Steps
have built-in automatic code signing.
We recommend removing this Step from your Workflow and using the automatic code signing feature in the Steps mentioned above.
Option B)
If you are not using any of the mentioned Xcode steps, then you can replace this iOS Auto Provision Step with
the [Manage iOS Code signing](https://www.bitrise.io/integrations/steps/manage-ios-code-signing) Step.
You can read more about these changes in our blog post:
https://blog.bitrise.io/post/simplifying-automatic-code-signing-on-bitrise
")
# Unset SPACESHIP_AVOID_XCODE_API
orig_spaceship_avoid_xcode_api = ENV['SPACESHIP_AVOID_XCODE_API']
Log.debug("\noriginal SPACESHIP_AVOID_XCODE_API: #{orig_spaceship_avoid_xcode_api}")
ENV['SPACESHIP_AVOID_XCODE_API'] = nil
Log.debug('SPACESHIP_AVOID_XCODE_API cleared')
###
# Developer Portal authentication
Log.info('Developer Portal authentication')
auth = AuthHelper.new
auth.login(params.build_url, params.build_api_token, params.team_id)
Log.success('authenticated')
###
# Download certificates
Log.info('Downloading Certificates')
certificate_urls = params.certificate_urls.reject(&:empty?)
raise 'no certificates provider' if certificate_urls.to_a.empty?
cert_helper = CertificateHelper.new
cert_helper.download_and_identify(certificate_urls, params.passphrases)
###
# Analyzing project
Log.info('Analyzing project')
project_helper = ProjectHelper.new(params.project_path, params.scheme, params.configuration)
codesign_identity = project_helper.project_codesign_identity
team_id = project_helper.project_team_id
Log.print("project codesign identity: #{codesign_identity}")
Log.print("project team id: #{team_id}")
Log.print("uses xcode managed signing: #{project_helper.uses_xcode_auto_codesigning?}")
Log.print("main target's platform: #{project_helper.platform}")
targets = project_helper.targets.collect(&:name)
targets.each_with_index do |target_name, idx|
bundle_id = project_helper.target_bundle_id(target_name)
entitlements = project_helper.target_entitlements(target_name) || {}
Log.print("target ##{idx}: #{target_name} (#{bundle_id}) with #{entitlements.length} services")
end
if !params.team_id.to_s.empty? && params.team_id != team_id
Log.warn("different team id defined: #{params.team_id} than the project's one: #{team_id}")
Log.warn("using defined team id: #{params.team_id}")
Log.warn("dropping project codesign identity: #{codesign_identity}")
team_id = params.team_id
codesign_identity = nil
end
raise 'failed to determine project development team' unless team_id
###
# Matching project codesign identity with the uploaded certificates
Log.info('Matching project codesign identity with the uploaded certificates')
cert_helper.ensure_certificate(codesign_identity, team_id, params.distribution_type)
# If development certificate is uploaded, do development auto code signing next to the specified distribution type.
distribution_types = [params.distribution_type]
distribution_types = ['development'].concat(distribution_types) if params.distribution_type != 'development' && cert_helper.certificate_info('development')
Log.debug("distribution_types: #{distribution_types}")
##
# Ensure test devices
dev_portal_devices = []
distribution_type_requires_device_list = !(%w[development ad-hoc] & distribution_types).empty?
if distribution_type_requires_device_list
Log.info('Ensure test devices on Developer Portal')
test_devices = params.register_test_devices == 'yes' ? auth.test_devices : []
dev_portal_devices = Portal::DeviceClient.ensure_test_devices(test_devices, project_helper.platform)
end
###
# Ensure Provisioning Profiles on Developer Portal
Log.info('Ensure Provisioning Profiles on Developer Portal')
profile_helper = ProfileHelper.new(project_helper, cert_helper)
xcode_managed_signing = profile_helper.ensure_profiles(distribution_types, dev_portal_devices, params.generate_profiles == 'yes', params.min_profile_days_valid)
###
unless xcode_managed_signing
# Apply code sign setting in project
Log.info('Apply code sign setting in project')
targets.each do |target_name|
bundle_id = project_helper.target_bundle_id(target_name)
puts
Log.success("configure target: #{target_name} (#{bundle_id})")
code_sign_identity = nil
provisioning_profile = nil
if cert_helper.development_certificate_info
certificate = cert_helper.development_certificate_info.certificate
code_sign_identity = certificate_common_name(certificate)
portal_profile = profile_helper.profiles_by_bundle_id('development')[bundle_id].portal_profile
provisioning_profile = portal_profile.uuid
elsif cert_helper.production_certificate_info
certificate = cert_helper.production_certificate_info.certificate
code_sign_identity = certificate_common_name(certificate)
portal_profile = profile_helper.profiles_by_bundle_id(params.distribution_type)[bundle_id].portal_profile
provisioning_profile = portal_profile.uuid
else
raise "no codesign settings generated for target: #{target_name} (#{bundle_id})"
end
project_helper.force_code_sign_properties(target_name, team_id, code_sign_identity, provisioning_profile)
end
###
end
# Install certificates
Log.info('Install certificates')
certificate_infos = []
certificate_infos.push(cert_helper.development_certificate_info) if cert_helper.development_certificate_info
certificate_infos.push(cert_helper.production_certificate_info) if cert_helper.production_certificate_info
certificate_path_passphrase_map = Hash[certificate_infos.map { |info| [info.path, info.passphrase] }]
keychain_helper = KeychainHelper.new(params.keychain_path, params.keychain_password)
keychain_helper.install_certificates(certificate_path_passphrase_map)
Log.success("#{certificate_path_passphrase_map.length} certificates installed")
###
# Export outputs
Log.info('Export outputs')
bundle_id = project_helper.target_bundle_id(project_helper.main_target)
outputs = {
'BITRISE_EXPORT_METHOD' => params.distribution_type,
'BITRISE_DEVELOPER_TEAM' => team_id
}
if cert_helper.development_certificate_info
certificate = cert_helper.development_certificate_info.certificate
code_sign_identity = certificate_common_name(certificate)
portal_profile = profile_helper.profiles_by_bundle_id('development')[bundle_id].portal_profile
provisioning_profile = portal_profile.uuid
outputs['BITRISE_DEVELOPMENT_CODESIGN_IDENTITY'] = code_sign_identity
outputs['BITRISE_DEVELOPMENT_PROFILE'] = provisioning_profile
end
if params.distribution_type != 'development' && cert_helper.production_certificate_info
certificate = cert_helper.production_certificate_info.certificate
code_sign_identity = certificate_common_name(certificate)
portal_profile = profile_helper.profiles_by_bundle_id(params.distribution_type)[bundle_id].portal_profile
provisioning_profile = portal_profile.uuid
outputs['BITRISE_PRODUCTION_CODESIGN_IDENTITY'] = code_sign_identity
outputs['BITRISE_PRODUCTION_PROFILE'] = provisioning_profile
end
outputs.each do |key, value|
`envman add --key "#{key}" --value "#{value}"`
Log.success("#{key}=#{value}")
end
###
# restore SPACESHIP_AVOID_XCODE_API
ENV['SPACESHIP_AVOID_XCODE_API'] = orig_spaceship_avoid_xcode_api
rescue => ex
# restore SPACESHIP_AVOID_XCODE_API
ENV['SPACESHIP_AVOID_XCODE_API'] = orig_spaceship_avoid_xcode_api
puts
Log.error('Error:')
Log.error(ex.to_s)
puts
Log.error('Stacktrace (for debugging):')
Log.error(ex.backtrace.join("\n").to_s)
exit 1
end