-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathworkflowtests.sh
executable file
·582 lines (425 loc) · 19.8 KB
/
workflowtests.sh
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
#!/usr/bin/env bash
#
# workflowtests.sh
# Copyright © 2023 SomeRandomiOSDev. All rights reserved.
#
# Usage example: ./workflowtests.sh --no-clean
# Set Script Variables
SCRIPT="$("$(dirname "$0")/resolvepath.sh" "$0")"
SCRIPTS_DIR="$(dirname "$SCRIPT")"
ROOT_DIR="$(dirname "$SCRIPTS_DIR")"
CURRENT_DIR="$(pwd -P)"
EXIT_CODE=0
EXIT_MESSAGE=""
# Help
function printhelp() {
local HELP="Run tests for the Github Action workflows.\n"
HELP+="\n"
HELP+="workflowtests.sh [--help | -h] [--verbose] [--project-name <project_name>]\n"
HELP+=" [--no-clean | --no-clean-on-fail] [--is-running-in-temp-env]\n"
HELP+="\n"
HELP+="--help, -h) Print this help message and exit.\n"
HELP+="\n"
HELP+="--help, -h) Enable verbose logging.\n"
HELP+="\n"
HELP+="--project-name) The name of the project to run tests against. If not\n"
HELP+=" provided it will attempt to be resolved by searching\n"
HELP+=" the working directory for an Xcode project and using\n"
HELP+=" its name.\n"
HELP+="\n"
HELP+="--no-clean) When not running in a temporary environment, do not\n"
HELP+=" clean up the temporary project created to run these\n"
HELP+=" tests upon completion.\n"
HELP+="\n"
HELP+="--no-clean-on-fail) Same as --no-clean with the exception that if the\n"
HELP+=" succeed clean up will continue as normal. This is\n"
HELP+=" mutually exclusive with --no-clean with --no-clean\n"
HELP+=" taking precedence.\n"
HELP+="\n"
HELP+="--is-running-in-temp-env) Setting this flag tells this script that the\n"
HELP+=" environment (directory) in which it is running is a\n"
HELP+=" temporary environment and it need not worry about\n"
HELP+=" dirtying up the directory or creating/deleting files\n"
HELP+=" and folders. USE CAUTION WITH THIS OPTION.\n"
HELP+="\n"
HELP+=" When this flag is NOT set, a copy of the containing\n"
HELP+=" working folder is created in a temporary location and\n"
HELP+=" removed (unless --no-clean is set) after the tests\n"
HELP+=" have finished running."
IFS='%'
echo -e "$HELP" 1>&2
unset IFS
exit $EXIT_CODE
}
# Parse Arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--project-name)
PROJECT_NAME="$2"
shift # --project-name
shift # <project_name>
;;
--is-running-in-temp-env)
IS_RUNNING_IN_TEMP_ENV=1
shift # --is-running-in-temp-env
;;
--no-clean)
NO_CLEAN=1
shift # --no-clean
;;
--no-clean-on-fail)
NO_CLEAN_ON_FAIL=1
shift # --no-clean-on-fail
;;
--verbose)
VERBOSE=1
shift # --verbose
;;
--help | -h)
printhelp
;;
*)
"$SCRIPTS_DIR/printformat.sh" "foreground:red" "Unknown argument: $1\n" 1>&2
EXIT_CODE=1
printhelp
;;
esac
done
if [ -z ${IS_RUNNING_IN_TEMP_ENV+x} ]; then
IS_RUNNING_IN_TEMP_ENV=0
fi
if [ -z ${NO_CLEAN+x} ]; then
NO_CLEAN=0
fi
if [ -z ${NO_CLEAN_ON_FAIL+x} ]; then
NO_CLEAN_ON_FAIL=0
fi
# Function Definitions
function cleanup() {
if [ "$IS_RUNNING_IN_TEMP_ENV" == "0" ]; then
if [[ "$NO_CLEAN" == "1" ]] || [[ "$NO_CLEAN_ON_FAIL" == "1" && "$EXIT_CODE" != "0" ]]; then
echo "Test Project: $OUTPUT_DIR"
else
cd "$CURRENT_DIR"
rm -rf "$TEMP_DIR"
fi
fi
#
local CARTHAGE_CACHE="$HOME/Library/Caches/org.carthage.CarthageKit"
if [ -e "$CARTHAGE_CACHE" ]; then
if [ -e "$CARTHAGE_CACHE/dependencies/$PROJECT_NAME" ]; then
rm -rf "$CARTHAGE_CACHE/dependencies/$PROJECT_NAME"
fi
for DIR in $(find "$CARTHAGE_CACHE/DerivedData" -mindepth 1 -maxdepth 1 -type d); do
if [ -e "$DIR/$PROJECT_NAME" ]; then
rm -rf "$DIR/$PROJECT_NAME"
fi
done
fi
#
if [ "${#EXIT_MESSAGE}" != 0 ]; then
if [ "$EXIT_MESSAGE" == "**printhelp**" ]; then
printhelp
else
echo -e "$EXIT_MESSAGE" 1>&2
fi
fi
exit $EXIT_CODE
}
function checkresult() {
if [ "$1" != "0" ]; then
if [ "${#2}" != "0" ]; then
EXIT_MESSAGE="$("$SCRIPTS_DIR/printformat.sh" "foreground:red" "$2")"
else
EXIT_MESSAGE="**printhelp**"
fi
EXIT_CODE=$1
cleanup
fi
}
function printstep() {
"$SCRIPTS_DIR/printformat.sh" "foreground:green" "$1"
}
function setuptemp() {
TEMP_DIR="$(mktemp -d)"
local TEMP_NAME="$(basename "$(mktemp -u "$TEMP_DIR/${PROJECT_NAME}WorkflowTests_XXXXXXXX")")"
local OUTPUT_DIR="$TEMP_DIR/$TEMP_NAME"
cp -R "$ROOT_DIR" "$OUTPUT_DIR"
if [ "$?" != "0" ]; then exit $?; fi
if [ -e "$OUTPUT_DIR/.build" ]; then
rm -rf "$OUTPUT_DIR/.build"
fi
if [ -e "$OUTPUT_DIR/.swiftpm" ]; then
rm -rf "$OUTPUT_DIR/.swiftpm"
fi
if [ -e "$OUTPUT_DIR/.xcodebuild" ]; then
rm -rf "$OUTPUT_DIR/.xcodebuild"
fi
echo "$OUTPUT_DIR"
}
function createlogfile() {
if [ ! -d "$OUTPUT_DIR/Logs" ]; then
mkdir -p "$OUTPUT_DIR/Logs"
fi
local LOG="$OUTPUT_DIR/Logs/$1.log"
touch "$LOG"
echo "$LOG"
}
function errormessage() {
local ERROR_MESSAGE="$1"
if [[ "$NO_CLEAN" == "1" ]] || [[ "$NO_CLEAN_ON_FAIL" == "1" ]]; then
ERROR_MESSAGE="$("$SCRIPTS_DIR/printformat.sh" "foreground:default" "${1%.}. See log for more details: $("$SCRIPTS_DIR/printformat.sh" "foreground:yellow" "$2")")"
elif [ "$VERBOSE" != "1" ]; then
ERROR_MESSAGE="$("$SCRIPTS_DIR/printformat.sh" "foreground:default" "${1%.}. Use the '--no-clean' or '--no-clean-on-fail' flag to inspect the logs.")"
fi
echo "$ERROR_MESSAGE"
}
function interrupt() {
EXIT_CODE=$SIGINT
EXIT_MESSAGE="$("$SCRIPTS_DIR/printformat.sh" "foreground:yellow" "Tests run was interrupted..")"
cleanup
}
# Setup
trap interrupt SIGINT # Cleanup if the user aborts (Ctrl + C)
#
ARGUMENTS=()
if [ "${#PROJECT_NAME}" != 0 ]; then
ARGUMENTS=(--project-name "$PROJECT_NAME")
fi
PROJECT_NAME="$("$SCRIPTS_DIR/findproject.sh" "${ARGUMENTS[@]}")"
checkresult $?
#
VERBOSE_FLAGS=()
if [ "$VERBOSE" == "1" ]; then
VERBOSE_FLAGS=(--verbose)
fi
#
if [ "$IS_RUNNING_IN_TEMP_ENV" == "1" ]; then
OUTPUT_DIR="$ROOT_DIR"
else
OUTPUT_DIR="$(setuptemp)"
echo -e "Testing from Temporary Directory: $("$SCRIPTS_DIR/printformat.sh" "foreground:yellow" "$OUTPUT_DIR")"
fi
# Check For Dependencies
cd "$OUTPUT_DIR"
printstep "Checking for Test Dependencies..."
### Carthage
if which carthage >/dev/null; then
CARTHAGE_VERSION="$(carthage version)"
echo "Carthage: $CARTHAGE_VERSION"
"$SCRIPTS_DIR/versions.sh" "$CARTHAGE_VERSION" "0.37.0"
if [ $? -lt 0 ]; then
"$SCRIPTS_DIR/printformat.sh" "foreground:yellow" "Carthage version of at least 0.37.0 is recommended for running these unit tests"
fi
else
checkresult -1 "Carthage is not installed and is required for running unit tests: $("$SCRIPTS_DIR/printformat.sh" "foreground:blue;underline" "https://github.com/Carthage/Carthage#installing-carthage")"
fi
### CocoaPods
if which pod >/dev/null; then
PODS_VERSION="$(pod --version)"
"$SCRIPTS_DIR/versions.sh" "$PODS_VERSION" "1.7.3"
if [ $? -ge 0 ]; then
echo "CocoaPods: $PODS_VERSION"
else
checkresult -1 "These unit tests require version 1.7.3 or later of CocoaPods: $("$SCRIPTS_DIR/printformat.sh" "foreground:blue;underline" "https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods")"
fi
else
checkresult -1 "CocoaPods is not installed and is required for running unit tests: $("$SCRIPTS_DIR/printformat.sh" "foreground:blue;underline" "https://guides.cocoapods.org/using/getting-started.html#installation")"
fi
### SwiftLint
if which swiftlint >/dev/null; then
echo "SwiftLint: $(swiftlint --version)"
else
checkresult -1 "SwiftLint is not installed and is required for running unit tests: $("$SCRIPTS_DIR/printformat.sh" "foreground:blue;underline" "https://github.com/realm/SwiftLint#installation")"
fi
# Run Tests
printstep "Running Tests...\n"
### Carthage Workflow
printstep "Testing 'carthage.yml' Workflow..."
git add . >/dev/null 2>&1
git commit -m "Commit" --no-gpg-sign >/dev/null 2>&1
git tag | xargs git tag -d >/dev/null 2>&1
git tag --no-sign 1.0 >/dev/null 2>&1
checkresult $? "'Create Cartfile' step of 'carthage.yml' workflow failed."
echo "git \"file://$OUTPUT_DIR\"" > ./Cartfile
./scripts/carthage.sh update "${VERBOSE_FLAGS[@]}"
checkresult $? "'Build' step of 'carthage.yml' workflow failed."
printstep "'carthage.yml' Workflow Tests Passed\n"
### CocoaPods Workflow
printstep "Testing 'cocoapods.yml' Workflow..."
pod lib lint "${VERBOSE_FLAGS[@]}"
checkresult $? "'Lint (Dynamic)' step of 'cocoapods.yml' workflow failed."
pod lib lint --use-libraries "${VERBOSE_FLAGS[@]}"
checkresult $? "'Lint (Static)' step of 'cocoapods.yml' workflow failed."
printstep "'cocoapods.yml' Workflow Tests Passed\n"
### Documentation Workflow
printstep "Testing 'documentation.yml' Workflow..."
ERROR_MESSAGE="'Build Documentation' step of 'documentation.yml' workflow failed."
if [ "$VERBOSE" == "1" ]; then
xcodebuild docbuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME" -destination "generic/platform=iOS Simulator" -derivedDataPath "$OUTPUT_DIR/.xcodebuild" SKIP_SWIFTLINT=YES ARCHS="x86_64"
else
LOG="$(createlogfile "build-documentation")"
ERROR_MESSAGE="$(errormessage "$ERROR_MESSAGE" "$LOG")"
#
xcodebuild docbuild -project "$PROJECT_NAME.xcodeproj" -scheme "$PROJECT_NAME" -destination "generic/platform=iOS Simulator" -derivedDataPath "$OUTPUT_DIR/.xcodebuild" SKIP_SWIFTLINT=YES ARCHS="x86_64" > "$LOG" 2>&1
fi
checkresult $? "$ERROR_MESSAGE"
printstep "'documentation.yml' Workflow Tests Passed\n"
### Swift Package Workflow
printstep "Testing 'swift-package.yml' Workflow..."
if [ "$VERBOSE" == "1" ]; then
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Building Swift Package from $("$SCRIPTS_DIR/printformat.sh" "bold" "Package.swift")"
swift build "${VERBOSE_FLAGS[@]}"
checkresult $? "'Build' step of 'swift-package.yml' workflow failed."
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Testing Swift Package from $("$SCRIPTS_DIR/printformat.sh" "bold" "Package.swift")"
swift test --enable-code-coverage "${VERBOSE_FLAGS[@]}"
checkresult $? "'Test' step of 'swift-package.yml' workflow failed."
else
LOG="$(createlogfile "build-swiftpackage")"
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Building Swift Package from $("$SCRIPTS_DIR/printformat.sh" "bold" "Package.swift")"
swift build > "$LOG" 2>&1
checkresult $? "$(errormessage "'Build' step of 'swift-package.yml' workflow failed." "$LOG")"
#
LOG="$(createlogfile "test-swiftpackage")"
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Testing Swift Package from $("$SCRIPTS_DIR/printformat.sh" "bold" "Package.swift")"
swift test --enable-code-coverage > "$LOG" 2>&1
checkresult $? "$(errormessage "'Test' step of 'swift-package.yml' workflow failed." "$LOG")"
fi
xcrun llvm-cov export --format=lcov --instr-profile=".build/debug/codecov/default.profdata" ".build/debug/${PROJECT_NAME}PackageTests.xctest/Contents/MacOS/${PROJECT_NAME}PackageTests" > "./codecov.lcov"
checkresult $? "'Generate Code Coverage File' step of 'swift-package.yml' workflow failed."
printstep "'swift-package.yml' Workflow Tests Passed\n"
### SwiftLint Workflow
printstep "Testing 'swiftlint.yml' Workflow..."
swiftlint
checkresult $? "'Run SwiftLint' step of 'swiftlint.yml' workflow failed."
printstep "'swiftlint.yml' Workflow Tests Passed\n"
### XCFramework Workflow
printstep "Testing 'xcframework.yml' Workflow..."
./scripts/xcframework.sh --project-name "$PROJECT_NAME" --output "$OUTPUT_DIR" "${VERBOSE_FLAGS[@]}" -- RUN_DOCUMENTATION_COMPILER=NO SKIP_SWIFTLINT=YES
checkresult $? "'Build' step of 'xcframework.yml' workflow failed."
printstep "'xcframework.yml' Workflow Tests Passed\n"
### Upload Assets Workflow
printstep "Testing 'upload-assets.yml' Workflow..."
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Creating zip archive for $("$SCRIPTS_DIR/printformat.sh" "bold" "$PROJECT_NAME.xcframework")"
zip -rX "$PROJECT_NAME.xcframework.zip" "$PROJECT_NAME.xcframework" >/dev/null 2>&1
checkresult $? "'Create XCFramework Zip' step of 'upload-assets.yml' workflow failed."
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Creating tar archive for $("$SCRIPTS_DIR/printformat.sh" "bold" "$PROJECT_NAME.xcframework")"
tar -zcvf "$PROJECT_NAME.xcframework.tar.gz" "$PROJECT_NAME.xcframework" >/dev/null 2>&1
checkresult $? "'Create XCFramework Tar' step of 'upload-assets.yml' workflow failed."
#
DOCC_ARCHIVE="$(find "$OUTPUT_DIR/.xcodebuild" -type d -name "$PROJECT_NAME.doccarchive")"
if [ "${DOCC_ARCHIVE[@]]}" == "0" ]; then
checkresult 1 "'Build Documentation' step of 'upload-assets.yml' workflow failed."
else
mv "${DOCC_ARCHIVE%/}" "$OUTPUT_DIR/$PROJECT_NAME.doccarchive"
checkresult $? "'Build Documentation' step of 'upload-assets.yml' workflow failed."
fi
#
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Creating zip archive for $("$SCRIPTS_DIR/printformat.sh" "bold" "$PROJECT_NAME.doccarchive")"
zip -rX "$PROJECT_NAME.doccarchive.zip" "$PROJECT_NAME.doccarchive" >/dev/null 2>&1
checkresult $? "'Create Documentation Zip' step of 'upload-assets.yml' workflow failed."
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Creating tar archive for $("$SCRIPTS_DIR/printformat.sh" "bold" "$PROJECT_NAME.doccarchive")"
tar -zcvf "$PROJECT_NAME.doccarchive.tar.gz" "$PROJECT_NAME.doccarchive" >/dev/null 2>&1
checkresult $? "'Create Documentation Tar' step of 'upload-assets.yml' workflow failed."
printstep "'upload-assets.yml' Workflow Tests Passed\n"
### Xcodebuild Workflow
printstep "Testing 'xcodebuild.yml' Workflow..."
#
for PLATFORM in "iOS" "iOS Simulator" "Mac Catalyst" "macOS" "tvOS" "tvOS Simulator" "watchOS" "watchOS Simulator"; do
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Building $("$SCRIPTS_DIR/printformat.sh" "foreground:green" "$PLATFORM") in $("$SCRIPTS_DIR/printformat.sh" "bold" "$PROJECT_NAME.xcodeproj")"
SCHEME="${PROJECT_NAME}"
DESTINATION="$PLATFORM"
case "$PLATFORM" in
"Mac Catalyst") DESTINATION="macOS,variant=Mac Catalyst" ;;
"macOS") SCHEME="${PROJECT_NAME} macOS" ;;
"tvOS") SCHEME="${PROJECT_NAME} tvOS" ;;
"tvOS Simulator") SCHEME="${PROJECT_NAME} tvOS" ;;
"watchOS") SCHEME="${PROJECT_NAME} watchOS" ;;
"watchOS Simulator") SCHEME="${PROJECT_NAME} watchOS" ;;
esac
#
ERROR_MESSAGE="'Build $PLATFORM' step of 'xcodebuild.yml' workflow failed."
if [ "$VERBOSE" == "1" ]; then
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$SCHEME" -destination "generic/platform=$DESTINATION" -configuration Debug RUN_DOCUMENTATION_COMPILER=NO SKIP_SWIFTLINT=YES
else
LOG="$(createlogfile "$(echo "$PLATFORM" | tr -d ' ' | tr '[:upper:]' '[:lower:]')-build")"
ERROR_MESSAGE="$(errormessage "$ERROR_MESSAGE" "$LOG")"
#
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$SCHEME" -destination "generic/platform=$DESTINATION" -configuration Debug RUN_DOCUMENTATION_COMPILER=NO SKIP_SWIFTLINT=YES > "$LOG" 2>&1
fi
checkresult $? "$ERROR_MESSAGE"
done
echo ""
#
IOS_SIM="$(xcrun simctl list devices available | grep "iPhone [0-9]" | sort -rV | head -n 1 | sed -E 's/(.+)[ ]*\([^)]*\)[ ]*\([^)]*\)/\1/' | awk '{$1=$1};1')"
TVOS_SIM="$(xcrun simctl list devices available | grep "Apple TV" | sort -V | head -n 1 | sed -E 's/(.+)[ ]*\([^)]*\)[ ]*\([^)]*\)/\1/' | awk '{$1=$1};1')"
WATCHOS_SIM="$(xcrun simctl list devices available | grep "Apple Watch" | sort -rV | head -n 1 | sed -E 's/(.+)[ ]*\([^)]*\)[ ]*\([^)]*\)/\1/' | awk '{$1=$1};1')"
#
for PLATFORM in "iOS" "Mac Catalyst" "macOS" "tvOS" "watchOS"; do
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Testing $("$SCRIPTS_DIR/printformat.sh" "foreground:green" "$PLATFORM") in $("$SCRIPTS_DIR/printformat.sh" "bold" "$PROJECT_NAME.xcodeproj")"
SCHEME="${PROJECT_NAME}"
TESTPLAN="${PROJECT_NAME}Tests"
DESTINATION="$PLATFORM"
case "$PLATFORM" in
"iOS") DESTINATION="iOS Simulator,name=$IOS_SIM" ;;
"Mac Catalyst") DESTINATION="macOS,variant=Mac Catalyst" ;;
"macOS")
SCHEME="$PROJECT_NAME macOS"
TESTPLAN="$PROJECT_NAME macOS Tests"
;;
"tvOS")
SCHEME="$PROJECT_NAME tvOS"
TESTPLAN="$PROJECT_NAME tvOS Tests"
DESTINATION="tvOS Simulator,name=$TVOS_SIM"
;;
"watchOS")
SCHEME="$PROJECT_NAME watchOS"
TESTPLAN="$PROJECT_NAME watchOS Tests"
DESTINATION="watchOS Simulator,name=$WATCHOS_SIM"
;;
esac
#
ERROR_MESSAGE="'Test $PLATFORM' step of 'xcodebuild.yml' workflow failed."
if [ "$VERBOSE" == "1" ]; then
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$SCHEME" -testPlan "$TESTPLAN" -destination "platform=$DESTINATION" -configuration Debug RUN_DOCUMENTATION_COMPILER=NO SKIP_SWIFTLINT=YES ONLY_ACTIVE_ARCH=YES test
else
LOG="$(createlogfile "$(echo "$PLATFORM" | tr -d ' ' | tr '[:upper:]' '[:lower:]')-test")"
ERROR_MESSAGE="$(errormessage "$ERROR_MESSAGE" "$LOG")"
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$SCHEME" -testPlan "$TESTPLAN" -destination "platform=$DESTINATION" -configuration Debug RUN_DOCUMENTATION_COMPILER=NO SKIP_SWIFTLINT=YES ONLY_ACTIVE_ARCH=YES test > "$LOG" 2>&1
fi
checkresult $? "$ERROR_MESSAGE"
done
printstep "'xcodebuild.yml' Workflow Tests Passed\n"
### Test Schemes
printstep "Test running unit tests with test schemes..."
for PLATFORM in "iOS" "Mac Catalyst" "macOS" "tvOS" "watchOS"; do
echo -e "$("$SCRIPTS_DIR/printformat.sh" "foreground:blue" "***") Testing $("$SCRIPTS_DIR/printformat.sh" "foreground:green" "$PLATFORM") in $("$SCRIPTS_DIR/printformat.sh" "bold" "$PROJECT_NAME.xcodeproj")"
SCHEME="${PROJECT_NAME}Tests"
DESTINATION="$PLATFORM"
case "$PLATFORM" in
"iOS") DESTINATION="iOS Simulator,name=$IOS_SIM" ;;
"Mac Catalyst") DESTINATION="macOS,variant=Mac Catalyst" ;;
"macOS") SCHEME="$PROJECT_NAME macOS Tests" ;;
"tvOS")
SCHEME="$PROJECT_NAME tvOS Tests"
DESTINATION="tvOS Simulator,name=$TVOS_SIM"
;;
"watchOS")
SCHEME="$PROJECT_NAME watchOS Tests"
DESTINATION="watchOS Simulator,name=$WATCHOS_SIM"
;;
esac
#
ERROR_MESSAGE="Test $PLATFORM (Test Scheme) failed."
if [ "$VERBOSE" == "1" ]; then
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$SCHEME" -testPlan "$SCHEME" -destination "platform=$DESTINATION" -configuration Debug RUN_DOCUMENTATION_COMPILER=NO SKIP_SWIFTLINT=YES ONLY_ACTIVE_ARCH=YES test
else
LOG="$(createlogfile "$(echo "$PLATFORM" | tr -d ' ' | tr '[:upper:]' '[:lower:]')-test")"
ERROR_MESSAGE="$(errormessage "$ERROR_MESSAGE" "$LOG")"
xcodebuild -project "$PROJECT_NAME.xcodeproj" -scheme "$SCHEME" -testPlan "$SCHEME" -destination "platform=$DESTINATION" -configuration Debug RUN_DOCUMENTATION_COMPILER=NO SKIP_SWIFTLINT=YES ONLY_ACTIVE_ARCH=YES test > "$LOG" 2>&1
fi
checkresult $? "$ERROR_MESSAGE"
done
printstep "Test Scheme Unit Tests Passed\n"
### Success
cleanup