Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
macos: circleci/macos@2.5.2
Use macos
elements in your existing workflows and jobs.
In order to interact with the UI, a user must approve a manual dialog menu in the OS, which is not possible from a "headless" remote environment. Utilize the `add-uitest-permissions` command to disable this permissions check.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
version: '2.1'
orbs:
macos: circleci/macos@1.0
jobs:
build-test:
macos:
xcode: 11.7
steps:
- checkout
- run: echo 'chruby ruby-2.7' >> ~/.bash_profile
- macos/add-uitest-permissions
- run: bundle install
- run: bundle exec fastlane testandbuild
workflows:
verify:
jobs:
- build-test
Add a permission to the macOS permissions database
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
bundle-id | The Bundle ID of the app to grant permissions to | Yes | - | string |
permission-type | The type of permission to grant | Yes | - | string |
Add Safari automation permissions to the macOS permissions database and enable safaridriver testing
Enable common environment permissions for testing MacOS apps with Xcode.
Delete a permission in the macOS permissions database
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
bundle-id | The Bundle ID of the app to grant permissions to | Yes | - | string |
permission-type | The type of permission to grant | Yes | - | string |
Enables VNC and sets up an account for login. Re-run your job using the `Re-run with SSH` feature, set up SSH forwarding on your _local_ machine using `ssh -p 54782 <mac container ip> -L5901:localhost:5900 -N` and connect to the host using `localhost:5901` in your favourite VNC client.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
password | The password of the VNC login account | No | MAC_ORB_VNC_PASSWORD | env_var_name |
username | The username of the VNC login account | No | vncuser | string |
Lists the currently defined permissions in the permissions database.
Boots a paired iOS and watchOS simulator with the specified devices
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
iphone-device | The device type. E.g., "iPhone 13 Pro Max" | No | iPhone 13 Pro Max | string |
iphone-device-udid-var | The name of the variable to contain the iphone's UDID e.g. IPHONE_UDID | No | MACOS_ORB_IPHONE_UDID | env_var_name |
iphone-version | The OS version. E.g., "15.0" | No | '15.0' | string |
pair-udid-var | The name of the variable to contain the pair's UDID e.g. PAIR_UDID | No | MACOS_ORB_PAIR_UDID | env_var_name |
watch-device | The device type. E.g., "Apple Watch Series 7 - 45mm" | No | Apple Watch Series 7 - 45mm | string |
watch-device-udid-var | The name of the variable to contain the watch's UDID e.g. WATCH_UDID | No | MACOS_ORB_WATCH_UDID | env_var_name |
watch-version | The OS version. E.g., "8.0" | No | '8.0' | string |
Boots the iOS simulator with the specific device
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
device | The device type. E.g., "iPhone 12" | No | iPhone 12 | string |
device-udid-var | The name of the variable to contain the device's UDID e.g. IPHONE_UDID | No | MACOS_ORB_DEVICE_UDID | env_var_name |
platform | The platform type. Accepts only "iOS", "watchOS", "tvOS" | No | iOS | string |
version | The OS version. E.g., "14.5" | No | '14.5' | string |
Sets the simulator to a custom location
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
latitude | The latitude to set for the custom location | No | '51.5032973' | string |
longitude | The longitude to set for the custom location | No | '-0.1195537' | string |
Sets the Ruby version in the job
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
version | The version of Ruby to switch to | No | '2.7' | string |
Wait until the simulator has booted.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
device-udid-var | The UDID of the device to wait for | No | MACOS_ORB_DEVICE_UDID | env_var_name |
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
A macOS orb for CircleCI containing useful features and tools for macOS based jobs.
display:
source_url: https://github.com/CircleCI-Public/macos-orb
commands:
add-permission:
description: Add a permission to the macOS permissions database
parameters:
bundle-id:
description: The Bundle ID of the app to grant permissions to
type: string
permission-type:
description: The type of permission to grant
type: string
steps:
- run:
command: |
#!/usr/bin/env bash
if csrutil status | grep -q 'disabled'; then
epochdate=$(($(date +'%s * 1000 + %-N / 1000000')))
macos_major_version=$(sw_vers -productVersion | awk -F. '{ print $1 }')
if [[ $macos_major_version -le 10 ]]; then
tcc_update="replace into access (service,client,client_type,allowed,prompt_count,indirect_object_identifier,flags,last_modified) values (\"${ORB_VAL_PERMISSION_TYPE}\",\"${ORB_VAL_BUNDLE_ID}\",0,1,1,\"UNUSED\",0,$epochdate);"
else
tcc_update="replace into access (service,client,client_type,auth_value,auth_reason,auth_version,indirect_object_identifier,flags,last_modified) values (\"${ORB_VAL_PERMISSION_TYPE}\",\"${ORB_VAL_BUNDLE_ID}\",0,2,1,1,\"UNUSED\",0,$epochdate);"
fi
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_update"
sudo sqlite3 "/Users/$USER/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_update"
else
echo "Unable to add permissions! System Integrity Protection is enabled on this image"
echo "Please choose an image with SIP disabled. Documentation: https://circleci.com/docs/2.0/testing-macos"
exit 1
fi
environment:
ORB_VAL_BUNDLE_ID: << parameters.bundle-id >>
ORB_VAL_PERMISSION_TYPE: << parameters.permission-type >>
name: Granting << parameters.permission-type >> permissions to << parameters.bundle-id >>
add-safari-permissions:
description: Add Safari automation permissions to the macOS permissions database and enable safaridriver testing
steps:
- run:
command: |
#!/usr/bin/env bash
if csrutil status | grep -q 'disabled'; then
epochdate=$(($(date +'%s * 1000 + %-N / 1000000')))
macos_major_version=$(sw_vers -productVersion | awk -F. '{ print $1 }')
if [[ $macos_major_version -le 10 ]]; then
defaults write com.apple.Safari AllowRemoteAutomation 1
else
tcc_service_accessibility="replace into access (service,client,client_type,auth_value,auth_reason,auth_version,indirect_object_identifier_type,indirect_object_identifier,flags,last_modified) values (\"kTCCServiceAccessibility\",\"/usr/sbin/sshd\",1,2,4,1,0,\"UNUSED\",0,$epochdate);"
tcc_service_events="replace into access (service,client,client_type,auth_value,auth_reason,auth_version,indirect_object_identifier_type,indirect_object_identifier,flags,last_modified) values (\"kTCCServiceAppleEvents\",\"/usr/sbin/sshd\",1,2,4,1,0,\"com.apple.systemevents\",0,$epochdate);"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_accessibility"
sudo sqlite3 "/Users/$USER/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_accessibility"
sudo sqlite3 "/Users/$USER/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_events"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_events"
# enable remote browser automation tool
sudo safaridriver --enable
mkdir -p "$HOME/Library/WebDriver"
plist="$HOME/Library/WebDriver/com.apple.Safari.plist"
/usr/libexec/PlistBuddy -c 'delete AllowRemoteAutomation' "$plist" > /dev/null 2>&1 || true
/usr/libexec/PlistBuddy -c 'add AllowRemoteAutomation bool true' "$plist" > /dev/null 2>&1
fi
else
echo "Unable to add permissions! System Integrity Protection is enabled on this image"
echo "Please choose an image with SIP disabled. Documentation: https://circleci.com/docs/2.0/testing-macos"
exit 1
fi
name: Granting Safari permissions and enabling safaridriver
add-uitest-permissions:
description: |
Enable common environment permissions for testing MacOS apps with Xcode.
steps:
- run:
command: |
#!/usr/bin/env bash
if csrutil status | grep -q 'disabled'; then
epochdate=$(($(date +'%s * 1000 + %-N / 1000000')))
macos_major_version=$(sw_vers -productVersion | awk -F. '{ print $1 }')
if [[ $macos_major_version -le 10 ]]; then
tcc_service_accessibility="replace into access (service,client,client_type,allowed,prompt_count,indirect_object_identifier,flags,last_modified) values (\"kTCCServiceAccessibility\",\"com.apple.dt.Xcode-Helper\",0,1,1,\"UNUSED\",0,$epochdate);"
tcc_service_developer_tool="replace into access (service,client,client_type,allowed,prompt_count,indirect_object_identifier,flags,last_modified) values (\"kTCCServiceDeveloperTool\",\"com.apple.Terminal\",0,1,1,\"UNUSED\",0,$epochdate);"
else
tcc_service_accessibility="replace into access (service,client,client_type,auth_value,auth_reason,auth_version,indirect_object_identifier,flags,last_modified) values (\"kTCCServiceAccessibility\",\"com.apple.dt.Xcode-Helper\",0,2,1,1,\"UNUSED\",0,$epochdate);"
tcc_service_developer_tool="replace into access (service,client,client_type,auth_value,auth_reason,auth_version,indirect_object_identifier,flags,last_modified) values (\"kTCCServiceDeveloperTool\",\"com.apple.Terminal\",0,2,1,1,\"UNUSED\",0,$epochdate);"
fi
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_accessibility"
sudo sqlite3 "/Users/$USER/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_accessibility"
sudo sqlite3 "/Users/$USER/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_developer_tool"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_developer_tool"
else
echo "Unable to add permissions! System Integrity Protection is enabled on this image"
echo "Please choose an image with SIP disabled. Documentation: https://circleci.com/docs/2.0/testing-macos"
exit 1
fi
name: Setting up Xcode Helper and Terminal permissions
add-voiceover-permissions:
description: |
Enable VoiceOver permissions for testing MacOS apps.
steps:
- run:
command: |
#!/usr/bin/env bash
if csrutil status | grep -q 'disabled'; then
defaults write com.apple.VoiceOverTraining doNotShowSplashScreen -bool true
defaults write com.apple.VoiceOver4/default SCREnableAppleScript -bool true
sudo bash -c 'echo -n "a" > /private/var/db/Accessibility/.VoiceOverAppleScriptEnabled'
else
echo "Unable to add permissions! System Integrity Protection is enabled on this image"
echo "Please choose an image with SIP disabled. Documentation: https://circleci.com/docs/2.0/testing-macos"
exit 1
fi
name: Setting up VoiceOver permissions
delete-permission:
description: Delete a permission in the macOS permissions database
parameters:
bundle-id:
description: The Bundle ID of the app to grant permissions to
type: string
permission-type:
description: The type of permission to grant
type: string
steps:
- run:
command: |
#!/usr/bin/env bash
if csrutil status | grep -q 'disabled'; then
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "delete from access where (client = \"${ORB_VAL_BUNDLE_ID}\" and service = \"${ORB_VAL_PERMISSION_TYPE}\")"
sudo sqlite3 "/Users/$USER/Library/Application Support/com.apple.TCC/TCC.db" "delete from access where (client = \"${ORB_VAL_BUNDLE_ID}\" and service = \"${ORB_VAL_PERMISSION_TYPE}\")"
else
echo "Unable to add permissions! System Integrity Protection is enabled on this image"
echo "Please choose an image with SIP disabled. Documentation: https://circleci.com/docs/2.0/testing-macos"
exit 1
fi
environment:
ORB_VAL_BUNDLE_ID: << parameters.bundle-id >>
ORB_VAL_PERMISSION_TYPE: << parameters.permission-type >>
name: Deleting << parameters.permission-type >> permission for << parameters.bundle-id >>
enable-vnc:
description: Enables VNC and sets up an account for login. Re-run your job using the `Re-run with SSH` feature, set up SSH forwarding on your _local_ machine using `ssh -p 54782 <mac container ip> -L5901:localhost:5900 -N` and connect to the host using `localhost:5901` in your favourite VNC client.
parameters:
password:
default: MAC_ORB_VNC_PASSWORD
description: The password of the VNC login account
type: env_var_name
username:
default: vncuser
description: The username of the VNC login account
type: string
steps:
- run:
background: true
command: |
#!/usr/bin/env bash
printf '\nCreating the user account...'
sudo /usr/sbin/sysadminctl -addUser vncuser -fullName "${ORB_VAL_USERNAME}" -password "${!ORB_ENV_PASSWORD}" -admin
printf '\nGranting automation permissions...'
EPOCH=$(($(date +'%s * 1000 + %-N / 1000000')))
TCC="replace into access (service,client,client_type,auth_value,auth_reason,auth_version,indirect_object_identifier,flags,last_modified) values (\"kTCCServiceAccessibility\",\"/usr/sbin/sshd\",1,2,3,1,\"UNUSED\",0,$EPOCH);"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "$TCC"
sudo sqlite3 "$HOME/Library/Application Support/com.apple.TCC/TCC.db" "$TCC"
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart \
-activate -configure -access -on \
-clientopts -setvnclegacy -vnclegacy yes \
-restart -agent -privs -all
printf '\nDone! To Access VNC (SSH jobs only), run the following command to forward the VNC port:'
IP=$(dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed s/\"//g)
printf '\nssh -p 54782 %s -L5901:localhost:5900 -N' "$IP"
printf '\nThen point your VNC client to localhost:5901 and use username %s and' "$MAC_ORB_VNC_USERNAME"
printf '\nthe password set in your MAC_ORB_VNC_PASSWORD project environment variable'
printf '\n\nTo view the screen for the distiller user, we recommend using the Screen Sharing app'
printf '\nincluded with macOS and choose the "Share The Display" option when logging in to VNC'
environment:
ORB_ENV_PASSWORD: << parameters.password >>
ORB_VAL_USERNAME: << parameters.username >>
name: Enabling VNC and adding << parameters.username >> account for VNC login
install-rosetta:
description: Install Rosetta 2 on Apple Silicon executors
steps:
- run:
command: |
#!/usr/bin/env bash
if [ "$(uname -m)" = "arm64" ]; then
/usr/sbin/softwareupdate --install-rosetta --agree-to-license
else
echo "Rosetta 2 can only be installed on Apple Silicon!"
exit 1
fi
name: Installing Rosetta 2
list-permission-types:
description: Lists the types of permissions that can be set.
steps:
- run:
command: |
#!/usr/bin/env bash
MAC_VER=$(sw_vers -productVersion | cut -d. -f1)
if (( "$MAC_VER" >= 12 )); then
sudo strings /System/Library/PrivateFrameworks/TCC.framework/Support/tccd | grep "^kTCCService[A-Z a-z]"
else
sudo strings /System/Library/PrivateFrameworks/TCC.framework/Versions/Current/Resources/tccd | grep "^kTCCService[A-Z a-z]"
fi
name: Listing permission types
list-permissions:
description: Lists the currently defined permissions in the permissions database.
steps:
- run:
command: |-
#!/usr/bin/env bash
macos_major_version=$(sw_vers -productVersion | awk -F. '{ print $1 }')
if [[ $macos_major_version -le 10 ]]; then
select_query="select client,service,allowed from access"
else
select_query="select client,service,auth_value from access"
fi
sudo sqlite3 -column -header "/Users/$USER/Library/Application Support/com.apple.TCC/TCC.db" "$select_query"
name: Listing currently defined permissions in user database
- run:
command: |
#!/usr/bin/env bash
macos_major_version=$(sw_vers -productVersion | awk -F. '{ print $1 }')
if [[ $macos_major_version -le 10 ]]; then
select_query="select client,service,allowed from access"
else
select_query="select client,service,auth_value from access"
fi
sudo sqlite3 -column -header "/Library/Application Support/com.apple.TCC/TCC.db" "$select_query"
name: Listing currently defined permissions in system database
preboot-paired-simulator:
description: Boots a paired iOS and watchOS simulator with the specified devices
parameters:
iphone-device:
default: iPhone 13 Pro Max
description: The device type. E.g., "iPhone 13 Pro Max"
type: string
iphone-device-udid-var:
default: MACOS_ORB_IPHONE_UDID
description: The name of the variable to contain the iphone's UDID e.g. IPHONE_UDID
type: env_var_name
iphone-version:
default: "15.0"
description: The OS version. E.g., "15.0"
type: string
pair-udid-var:
default: MACOS_ORB_PAIR_UDID
description: The name of the variable to contain the pair's UDID e.g. PAIR_UDID
type: env_var_name
watch-device:
default: Apple Watch Series 7 - 45mm
description: The device type. E.g., "Apple Watch Series 7 - 45mm"
type: string
watch-device-udid-var:
default: MACOS_ORB_WATCH_UDID
description: The name of the variable to contain the watch's UDID e.g. WATCH_UDID
type: env_var_name
watch-version:
default: "8.0"
description: The OS version. E.g., "8.0"
type: string
steps:
- run:
command: |
#!/usr/bin/env bash
UDID_not_found() {
# arguments: requested simulator, device
PAIRS=$(xcrun simctl list pairs | tail -n +2)
echo "ERROR!: UDID not found, check Platform, Version and Device"
echo "Requested: Simulator: ${1}, Device: ${2}"
echo "Available:"
echo "${PAIRS}"
exit 1
}
xcode_major=$(/usr/bin/xcodebuild -version | awk 'NR==1{print $2}' | cut -d. -f1)
if [[ $xcode_major -ge "12" ]]; then
ESCAPED_IPHONE_VER=$(echo "${ORB_VAL_IPHONE_VERSION}" | tr '.' '-')
ESCAPED_WATCHOS_VER=$(echo "${ORB_VAL_WATCH_VERSION}" | tr '.' '-')
SIMLIST=$(xcrun simctl list -j)
IPHONE_UDID=$(echo "${SIMLIST}" | jq -r ".devices.\"com.apple.CoreSimulator.SimRuntime.iOS-${ESCAPED_IPHONE_VER}\"[] | select(.name==\"${ORB_VAL_IPHONE_DEVICE}\").udid")
if [ -z "${IPHONE_UDID}" ]; then
UDID_not_found "iOS-${ESCAPED_IPHONE_VER}" "${ORB_VAL_IPHONE_DEVICE}"
fi
echo "export ${ORB_ENV_IPHONE_UDID}=${IPHONE_UDID}" >> "${BASH_ENV}"
WATCH_UDID=$(echo "${SIMLIST}" | jq -r ".devices.\"com.apple.CoreSimulator.SimRuntime.watchOS-${ESCAPED_WATCHOS_VER}\"[] | select(.name==\"${ORB_VAL_WATCH_DEVICE}\").udid")
if [ -z "${WATCH_UDID}" ]; then
UDID_not_found "watchOS-${ESCAPED_WATCHOS_VER}" "${ORB_VAL_WATCH_DEVICE}"
fi
echo "export ${ORB_ENV_WATCH_UDID}=${WATCH_UDID}" >> "${BASH_ENV}"
PAIR_UDID=$(xcrun simctl pair "${WATCH_UDID} ${IPHONE_UDID}" 2> /dev/null) || true
echo "export ${ORB_ENV_PAIR_UDID}=${PAIR_UDID}" >> "${BASH_ENV}"
if [ -z "${PAIR_UDID}" ]; then
PAIR_UDID=$(echo "${SIMLIST}" | jq -r ".pairs | to_entries[] | select(.value.watch.udid==\"${WATCH_UDID}\" and .value.phone.udid==\"${IPHONE_UDID}\") | .key")
fi
xcrun simctl boot "${PAIR_UDID}"
else
xcrun instruments -w "${ORB_VAL_IPHONE_DEVICE} (${ORB_VAL_IPHONE_VERSION}) + ${ORB_VAL_WATCH_DEVICE} (${ORB_VAL_WATCH_VERSION}) [" || true
fi
environment:
ORB_ENV_IPHONE_UDID: << parameters.iphone-device-udid-var >>
ORB_ENV_PAIR_UDID: << parameters.pair-udid-var >>
ORB_ENV_WATCH_UDID: << parameters.watch-device-udid-var >>
ORB_VAL_IPHONE_DEVICE: << parameters.iphone-device >>
ORB_VAL_IPHONE_VERSION: << parameters.iphone-version >>
ORB_VAL_WATCH_DEVICE: << parameters.watch-device >>
ORB_VAL_WATCH_VERSION: << parameters.watch-version >>
name: Pre-booting paired << parameters.iphone-device >> << parameters.iphone-version >> simulator with << parameters.watch-device >> << parameters.watch-version >>
preboot-simulator:
description: Boots the iOS simulator with the specific device
parameters:
device:
default: iPhone 12
description: The device type. E.g., "iPhone 12"
type: string
device-udid-var:
default: MACOS_ORB_DEVICE_UDID
description: The name of the variable to contain the device's UDID e.g. IPHONE_UDID
type: env_var_name
platform:
default: iOS
description: The platform type. Accepts only "iOS", "watchOS", "tvOS"
type: string
version:
default: "14.5"
description: The OS version. E.g., "14.5"
type: string
steps:
- run:
command: |
#!/usr/bin/env bash
UDID_not_found() {
# arguments: requested simulator, device
SIMS=$(xcrun simctl list devices | tail -n +2)
echo "ERROR!: UDID not found, check Platform, Version and Device"
echo "Requested: Simulator: ${1}, Device: ${2}"
echo "Available:"
echo "${SIMS}"
exit 1
}
xcode_major=$(/usr/bin/xcodebuild -version | awk 'NR==1{print $2}' | cut -d. -f1)
if [[ $xcode_major -ge "12" ]]; then
ESCAPED_VER=$(echo "$ORB_VAL_VERSION" | tr '.' '-')
SIMREQ="${ORB_VAL_PLATFORM}-${ESCAPED_VER}"
SIMLIST=$(xcrun simctl list -j)
UDID=$(echo "${SIMLIST}" | jq -r ".devices.\"com.apple.CoreSimulator.SimRuntime.${SIMREQ}\"[] | select(.name==\"${ORB_VAL_DEVICE}\").udid")
if [[ -z "${UDID}" ]]; then
UDID_not_found "${SIMREQ}" "${ORB_VAL_DEVICE}"
fi
echo "export ${ORB_ENV_DEVICE_UDID}=${UDID}" >> "${BASH_ENV}"
xcrun simctl boot "${UDID}"
else
xcrun instruments -w "${ORB_VAL_DEVICE} (${ORB_VAL_VERSION}) [" || true
fi
environment:
ORB_ENV_DEVICE_UDID: << parameters.device-udid-var >>
ORB_VAL_DEVICE: << parameters.device >>
ORB_VAL_PLATFORM: << parameters.platform >>
ORB_VAL_VERSION: << parameters.version >>
name: Pre-booting << parameters.device >> << parameters.platform >> << parameters.version >> simulator
set-sim-location:
description: Sets the simulator to a custom location
parameters:
latitude:
default: "51.5032973"
description: The latitude to set for the custom location
type: string
longitude:
default: "-0.1195537"
description: The longitude to set for the custom location
type: string
steps:
- run:
command: |-
#!/usr/bin/env bash
xcode_major=$(/usr/bin/xcodebuild -version | awk 'NR==1{print $2}' | cut -d. -f1)
xcode_minor=$(/usr/bin/xcodebuild -version | awk 'NR==1{print $2}' | cut -d. -f2)
epochdate=$(($(date +'%s * 1000 + %-N / 1000000')))
if [[ xcode_major -ge "12" ]] || [[ xcode_major -eq "11" && xcode_minor -ge "4" ]]; then
tcc_service_accessibility="replace into access (service,client,client_type,auth_value,auth_reason,auth_version,indirect_object_identifier_type,indirect_object_identifier,flags,last_modified) values (\"kTCCServiceAccessibility\",\"/usr/sbin/sshd\",1,2,4,1,0,\"UNUSED\",0,$epochdate);"
tcc_service_events="replace into access (service,client,client_type,auth_value,auth_reason,auth_version,indirect_object_identifier_type,indirect_object_identifier,flags,last_modified) values (\"kTCCServiceAppleEvents\",\"/usr/sbin/sshd\",1,2,4,1,0,\"com.apple.systemevents\",0,$epochdate);"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_accessibility"
sudo sqlite3 "/Users/$USER/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_accessibility"
sudo sqlite3 "/Users/$USER/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_events"
sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" "$tcc_service_events"
osascript -e "
tell application \"System Events\"
tell application \"/Applications/Xcode.app/Contents/Developer/Applications/Simulator.app\" to activate
repeat until window 1 of process \"Simulator\" exists
delay 5
end repeat
tell process \"Simulator\"
set frontmost to true
click menu item \"Custom Location…\" of menu of menu item \"Location\" of menu \"Features\" of menu bar 1
tell window 1
set value of text field 1 to \"$ORB_VAL_LATITUDE\"
set value of text field 2 to \"$ORB_VAL_LONGITUDE\"
click button \"OK\"
end tell
end tell
end tell"
else
echo "This command is only supported from Xcode 11.4 and higher"
exit 1
fi
environment:
ORB_VAL_LATITUDE: << parameters.latitude >>
ORB_VAL_LONGITUDE: << parameters.longitude >>
name: Setting simulator location
switch-ruby:
description: Sets the Ruby version in the job
parameters:
version:
default: "2.7"
description: The version of Ruby to switch to
type: string
steps:
- run:
command: "#!/usr/bin/env bash\n\nif command -v rbenv >/dev/null 2>&1; then\n ruby_ver=\"$ORB_VAL_RUBY_VERSION\"\n if [[ \"$ruby_ver\" != \"system\" ]]; then\n ruby_version=$(rbenv versions --bare | grep \"$ORB_VAL_RUBY_VERSION\" | head -n 1)\n if [[ -z \"$ruby_version\" ]]; then\n printf \"\\nNo Rubies installed that match version %s\\n\" \"$ORB_VAL_RUBY_VERSION\"\n printf \"\\nInstalled versions:\\n\"\n rbenv versions\n exit 1\n fi\n else\n ruby_version=\"system\"\n fi\n\n rbenv global \"$ruby_version\"\n rbenv rehash\n\n printf \"\\nSet Ruby version succesfully:\\n\"\n rbenv versions\nelse\n xcode_major=$(/usr/bin/xcodebuild -version | awk 'NR==1{print $2}' | cut -d. -f1)\n xcode_minor=$(/usr/bin/xcodebuild -version | awk 'NR==1{print $2}' | cut -d. -f2)\n ruby_ver=\"$ORB_VAL_RUBY_VERSION\"\n\n if [[ \"$ruby_ver\" != \"system\" ]]; then\n ruby_version=\"ruby-$ORB_VAL_RUBY_VERSION\"\n else\n ruby_version=\"system\"\n fi\n \n if [[ $xcode_major -ge \"12\" ]] || [[ $xcode_major -eq \"11\" && $xcode_minor -ge \"7\" ]]; then\n sed -i '' \"s/^chruby.*/chruby ${ruby_version}/g\" ~/.bash_profile\n elif [[ $xcode_major -eq \"11\" && $xcode_minor -le \"1\" ]]; then\n echo \"$ruby_version\" > ~/.ruby-version\n else\n echo \"chruby $ruby_version\" >> ~/.bash_profile\n fi\nfi\n"
environment:
ORB_VAL_RUBY_VERSION: << parameters.version >>
name: Setting Ruby version to << parameters.version >>
wait-until-simulator-booted:
description: Wait until the simulator has booted.
parameters:
device-udid-var:
default: MACOS_ORB_DEVICE_UDID
description: The UDID of the device to wait for
type: env_var_name
steps:
- run:
command: |
#!/usr/bin/env bash
DEVICE_UDID="${!ORB_EVAL_DEVICE_UDID}"
xcrun simctl bootstatus "${DEVICE_UDID}"
environment:
ORB_EVAL_DEVICE_UDID: << parameters.device-udid-var >>
name: Waiting until simulator is booted
examples:
enable_settings_for_ui_testing:
description: |
In order to interact with the UI, a user must approve a manual dialog menu in the OS, which is not possible from a "headless" remote environment. Utilize the `add-uitest-permissions` command to disable this permissions check.
usage:
version: "2.1"
orbs:
macos: circleci/macos@1.0
jobs:
build-test:
macos:
xcode: 11.7
steps:
- checkout
- run: echo 'chruby ruby-2.7' >> ~/.bash_profile
- macos/add-uitest-permissions
- run: bundle install
- run: bundle exec fastlane testandbuild
workflows:
verify:
jobs:
- build-test