-
-
Notifications
You must be signed in to change notification settings - Fork 324
358 lines (304 loc) · 12.8 KB
/
test.yml
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
name: Test
on:
push:
branches:
- main
- release/**
pull_request:
paths:
- "Sources/**"
- "Tests/**"
- "test-server/**"
- "Samples/**"
- ".github/workflows/test.yml"
- "fastlane/**"
- "scripts/tests-with-thread-sanitizer.sh"
- "scripts/ci-select-xcode.sh"
- "scripts/xcode-test.sh"
- ".codecov.yml"
- Sentry.xcodeproj
# run the workflow any time an Xcode scheme changes for a sample app
- "Samples/tvOS-Swift/tvOS-Swift.xcodeproj/xcshareddata/xcschemes/tvOS-Swift.xcscheme"
- "Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS13-Swift.xcscheme"
- "Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-SwiftUITests.xcscheme"
- "Samples/iOS-Swift/iOS-Swift.xcodeproj/xcshareddata/xcschemes/iOS-Swift.xcscheme"
- "Samples/macOS-Swift/macOS-Swift.xcodeproj/xcshareddata/xcschemes/macOS-Swift.xcscheme"
- "Samples/iOS-ObjectiveC/iOS-ObjectiveC.xcodeproj/xcshareddata/xcschemes/iOS-ObjectiveC.xcscheme"
jobs:
build-test-server:
name: Build test server
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- name: Cache for Test Server
id: cache_test_server
uses: actions/cache@v3
with:
path: ./test-server/.build
key: test-server-${{ hashFiles('./test-server') }}
restore-keys: |
test-server-${{ hashFiles('./test-server') }}
test-server-
- name: Build Test Server
if: steps.cache_test_server.outputs.cache-hit != 'true'
working-directory: test-server
run: >-
swift build -c release 2>&1 | tee test-server-build.log
- name: Copy exec
working-directory: test-server
run: cp $(swift build --show-bin-path -c release)/Run test-server-exec
- name: Archiving DerivedData
uses: actions/upload-artifact@v3
with:
name: test-server
path: |
./test-server/test-server-exec
- name: Archiving Raw Test Logs
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: test-server-build-log-${{matrix.platform}}-xcode-${{matrix.xcode}}-os-${{matrix.test-destination-os}}
path: |
raw-test-output.log
unit-tests:
name: Unit ${{matrix.platform}} - Xcode ${{matrix.xcode}} - OS ${{matrix.test-destination-os}}
runs-on: ${{matrix.runs-on}}
timeout-minutes: 20
needs: build-test-server
strategy:
fail-fast: false
matrix:
# Can't run tests on watchOS because XCTest is not available
include:
# iOS 13.7
- runs-on: macos-11
platform: "iOS"
xcode: "13.2.1"
test-destination-os: "13.7"
# iOS 14
- runs-on: macos-11
platform: "iOS"
xcode: "13.2.1"
test-destination-os: "14.5"
# iOS 15
- runs-on: macos-12
platform: "iOS"
xcode: "13.4.1"
test-destination-os: "latest"
# iOS 16
- runs-on: macos-13
platform: "iOS"
xcode: "14.3"
test-destination-os: "latest"
# macOS 11
- runs-on: macos-11
platform: "macOS"
xcode: "13.2.1"
test-destination-os: "latest"
# macOS 12
- runs-on: macos-12
platform: "macOS"
xcode: "13.4.1"
test-destination-os: "latest"
# macOS 13
- runs-on: macos-13
platform: "macOS"
xcode: "14.3"
test-destination-os: "latest"
# Catalyst. We only test the latest version, as
# the risk something breaking on Catalyst and not
# on an older iOS or macOS version is low.
- runs-on: macos-13
platform: "Catalyst"
xcode: "14.3"
test-destination-os: "latest"
# tvOS 15
- runs-on: macos-12
platform: "tvOS"
xcode: "13.4.1"
test-destination-os: "latest"
# tvOS 16
- runs-on: macos-13
platform: "tvOS"
xcode: "14.3"
test-destination-os: "latest"
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: test-server
- name: Print hardware info
run: system_profiler SPHardwareDataType
- name: Allow test-server to run
run: chmod +x ./test-server-exec
- run: ./test-server-exec &
- run: ./scripts/ci-select-xcode.sh ${{matrix.xcode}}
# Workaround with a symlink pointed out in: https://github.com/actions/virtual-environments/issues/551#issuecomment-637344435
- name: Prepare iOS 13.7 simulator
if: ${{ matrix.platform == 'iOS' && matrix.test-destination-os == '13.7'}}
run: |
sudo mkdir -p /Library/Developer/CoreSimulator/Profiles/Runtimes
sudo ln -s /Applications/Xcode_11.7.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 13.7.simruntime
xcrun simctl create custom-test-device "iPhone 8" "com.apple.CoreSimulator.SimRuntime.iOS-13-7"
# Workaround with a symlink pointed out in: https://github.com/actions/virtual-environments/issues/551#issuecomment-637344435
- name: Prepare iOS 14.5 simulator
if: ${{ matrix.platform == 'iOS' && matrix.test-destination-os == '14.5'}}
run: |
sudo mkdir -p /Library/Developer/CoreSimulator/Profiles/Runtimes
sudo ln -s /Applications/Xcode_12.5.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 14.5.simruntime
xcrun simctl create custom-test-device "iPhone 8" "com.apple.CoreSimulator.SimRuntime.iOS-14-5"
- name: Install Slather
run: gem install slather
# We split building and running tests in two steps so we know how long running the tests takes.
- name: Build tests
id: build_tests
run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME ci build-for-testing
- name: Run tests
# We call a script with the platform so the destination
# passed to xcodebuild doesn't end up in the job name,
# because GitHub Actions don't provide an easy way of
# manipulating string in expressions.
run: ./scripts/xcode-test.sh ${{matrix.platform}} ${{matrix.test-destination-os}} $GITHUB_REF_NAME ci test-without-building
- name: Slowest Tests
if: ${{ always() }}
run: ./scripts/xcode-slowest-tests.sh
- name: Archiving DerivedData Logs
uses: actions/upload-artifact@v3
if: steps.build_tests.outcome == 'failure'
with:
name: derived-data-${{matrix.platform}}-xcode-${{matrix.xcode}}-os-${{matrix.test-destination-os}}
path: |
/Users/runner/Library/Developer/Xcode/DerivedData/**/Logs/**
- name: Archiving Raw Test Logs
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: raw-test-output-${{matrix.platform}}-xcode-${{matrix.xcode}}-os-${{matrix.test-destination-os}}
path: |
raw-test-output.log
- name: Archiving Crash Logs
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: crash-logs-${{matrix.platform}}-xcode-${{matrix.xcode}}-os-${{matrix.test-destination-os}}
path: |
~/Library/Logs/DiagnosticReports/**
# We can upload all coverage reports, because codecov merges them.
# See https://docs.codecov.io/docs/merging-reports
# Checkout .codecov.yml to see the config of Codecov
# We don't upload codecov for release branches, as we don't want a failing coverage check to block a release.
# We don't upload codecov for scheduled runs as CodeCov only accepts a limited amount of uploads per commit.
- name: Push code coverage to codecov
id: codecov_1
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # [email protected]
if: ${{ contains(matrix.platform, 'iOS') && !contains(github.ref, 'release') && github.event.schedule == '' }}
with:
# Although public repos should not have to specify a token there seems to be a bug with the Codecov GH action, which can
# be solved by specifying the token, see https://github.com/codecov/codecov-action/issues/557#issuecomment-1224970469
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
verbose: true
# Sometimes codecov uploads etc can fail. Retry one time to rule out e.g. intermittent network failures.
- name: Push code coverage to codecov
id: codecov_2
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # [email protected]
if: ${{ steps.codecov_1.outcome == 'failure' && contains(matrix.platform, 'iOS') && !contains(github.ref, 'release') && github.event.schedule == '' }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
# We don't run all unit tests with Thread Sanitizer enabled because
# that adds a significant overhead.
thread-sanitizer:
# Disabled for now, see https://github.com/getsentry/sentry-cocoa/issues/3200
if: false
name: Unit iOS - Thread Sanitizer
runs-on: macos-13
# When there are threading issues the tests sometimes keep hanging
timeout-minutes: 20
needs: [build-test-server]
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: test-server
- name: Allow test-server to run
run: chmod +x ./test-server-exec
- run: ./test-server-exec &
- run: ./scripts/ci-select-xcode.sh
- name: Running tests with ThreadSanitizer
run: ./scripts/tests-with-thread-sanitizer.sh
- name: Archiving Test Logs
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: thread-sanitizer
path: thread-sanitizer.log
ui-tests:
name: UI Tests for ${{matrix.target}} on Simulators
runs-on: macos-13
strategy:
matrix:
target: ["ios_swift", "ios_objc", "tvos_swift"]
steps:
- uses: actions/checkout@v3
- run: ./scripts/ci-select-xcode.sh
# GitHub Actions sometimes fail to launch the UI tests. Therefore we retry
- name: Run Fastlane
run: for i in {1..2}; do fastlane ui_tests_${{matrix.target}} && break ; done
shell: sh
- name: Archiving Raw Test Logs
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: raw-uitest-output-${{matrix.target}}
path: |
~/Library/Logs/scan/*.log
./fastlane/test_output/**
# SwiftUI only supports iOS 14+ so we run it in a separate matrix here
ui-tests-swift-ui:
name: UI Tests for SwiftUI on ${{matrix.device}} Simulator
runs-on: ${{matrix.runs-on}}
strategy:
fail-fast: false
matrix:
include:
- runs-on: macos-12
xcode: "13.4.1"
device: "iPhone 8 (15.2)"
- runs-on: macos-13
xcode: "14.3"
device: "iPhone 8 (16.1)"
steps:
- uses: actions/checkout@v3
- run: ./scripts/ci-select-xcode.sh ${{matrix.xcode}}
# GitHub Actions sometimes fail to launch the UI tests. Therefore we retry
- name: Run Fastlane
run: for i in {1..2}; do fastlane ui_tests_ios_swiftui device:"${{matrix.device}}" && break ; done
shell: sh
- name: Archiving Raw Test Logs
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: raw-swiftui-test-output-${{matrix.platform}}-xcode-${{matrix.xcode}}-os-${{matrix.test-destination-os}}
path: |
~/Library/Logs/scan/*.log
./fastlane/test_output/**
ui-tests-address-sanitizer:
name: UI Tests with Address Sanitizer
runs-on: macos-13
steps:
- uses: actions/checkout@v3
- run: ./scripts/ci-select-xcode.sh
# GitHub Actions sometimes fail to launch the UI tests. Therefore we retry
- name: Run Fastlane
run: for i in {1..2}; do fastlane ui_tests_ios_swift device:"$iPhone 8 (15.5)" address_sanitizer:true && break ; done
shell: sh
- name: Archiving Raw Test Logs
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: raw-uitest-output-asan
path: |
~/Library/Logs/scan/*.log
./fastlane/test_output/**