-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·418 lines (357 loc) · 14.8 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·418 lines (357 loc) · 14.8 KB
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
#!/usr/bin/env bash
set -eu
# This script triggers the integration tests, e.g. by running 'xcodebuild' or 'swift' (SPM).
# If no project directory is given as parameter, this script calls itself for each test directory in a for loop.
version=""
##### Used in Podfile/Cartfile or as the Swift Package repo #####
source=""
##### Behavioral flags #####
file_only=""
do_clean=""
use_carthage=""
use_swiftpm=""
use_swiftpm_sync=""
use_staging=""
framework=""
skip_project=""
carthage_bin="carthage"
use_default_ruby=""
# Note: do not use the repo name, 'objectbox-swift-spm', it may accidentally use a different directory than intended
swift_package_dir="obx-swift-package"
while [ $# -ge 1 ]; do
case $1 in
-h|help|--help|usage)
echo
echo "Usage: $(basename "$0") [options] {project-directory}"
echo
echo " -v, --version <version> Set the ObjectBox pod or Carthage version or Swift Package repository tag or branch to test"
echo " -s, --source <source> Set the source repository for the Podfile/Cartfile or the Swift Package repository URL"
echo " -S, --staging Use our staging source repository for the Podfile/Cartfile"
echo " -f, --file Only create the Podfile/Cartfile"
echo " -c, --carthage Test the Carthage instead of the CocoaPods release"
echo " --carthage-bin Use the packaged Carthage executable from our bin dir"
echo " --framework <url> Test the framework uploaded to this HTTPS URL instead of the CocoaPods release"
echo " (this creates a local Cartfile pointing to the URL)"
echo " --swiftpm Test the Swift Package instead of the CocoaPods release"
echo " --sync Test the Swift Package Sync variant"
echo " --clean Cleans all added/modified files to reset the state to a fresh"
echo " git checkout. Warning: Data may be LOST!!"
echo " Does something like 'git clean -fdx && git reset --hard'"
echo " --skip <project> Skip the given project"
echo " --default-ruby Deletes .ruby-version file so rbenv uses the default version of ruby"
exit 0
;;
-v|--version)
shift
version="$1"
;;
--framework)
shift
framework="$1"
use_carthage="true"
;;
-s|--source)
shift
source="$1"
;;
-S|--staging)
use_staging="true"
;;
-f|--file)
file_only="true"
;;
-c|--carthage)
use_carthage="true"
;;
--carthage-bin)
use_carthage="true"
carthage_bin="bin/carthage"
;;
--clean)
do_clean="true"
;;
--skip)
shift
skip_project="$1"
;;
--swiftpm)
use_swiftpm="true"
;;
--sync)
use_swiftpm_sync="true"
;;
--default-ruby)
use_default_ruby="true"
;;
*) break # Assuming project comes next, stop parsing here
;;
esac
shift
done
#Validation
if [ -n "${source}" ]; then
if [ -n "$use_staging" ]; then
echo "Cannot specify source AND staging; use -h for help"
exit 1
fi
if [ -n "$framework" ]; then
echo "Cannot specify source AND framework; use -h for help"
exit 1
fi
fi
if [ -n "${use_carthage}" ] && [ -n "${use_swiftpm}" ]; then
echo "Cannot combine carthage AND Swift PM; use -h for help"
exit 1
fi
#macOS's readlink does not have -f option, do this instead:
script_dir=$( cd "$(dirname "$0")" ; pwd -P )
cd "$script_dir" # allow to call from any dir
if [ -n "$do_clean" ]; then
echo "Cleaning..."
git clean -fdx
git reset --hard
fi
if [ -n "${use_default_ruby}" ]; then
echo "Removing .ruby-version rbenv config, will use ruby version:"
rm .ruby-version
ruby --version
fi
if [ -n "$framework" ]; then
source="$script_dir/objectbox-framework-spec.json"
if [ -z "$version" ]; then # didn't work without a version
date=$(date '+%Y%m%d')
version="0.0.0-dummy$date"
fi
echo "{ \"${version}\": \"${framework}\" }" > "$source"
fi
########################################################################################################
#### If no project parameter was given, loop over project directories and call this script for each ####
########################################################################################################
if [ -z "${1-}" ]; then
# Original args ($@) are gone as shift was called during parameter parsing above.
# Also, cannot capture original args as string as spaces need to be preserved, i.e. in version values.
additional_args=""
if [ -n "${file_only}" ]; then
additional_args+=" --file"
fi
if [ -n "${use_carthage}" ]; then
additional_args+=" --carthage"
fi
if [ -n "${use_swiftpm}" ]; then
additional_args+=" --swiftpm"
fi
if [ -n "${use_swiftpm_sync}" ]; then
additional_args+=" --sync"
fi
if [ -n "$use_staging" ]; then
additional_args+=" --staging"
fi
# Note: no need to propagate --clean or --default-ruby flag, doing it once on the root directory is enough
echo "Invoking projects using args: -v \"$version\" -s \"$source\" $additional_args"
for project in "$script_dir"/*/ ; do
project_name="$(basename "${project}")"
if [ "$project_name" == "bin" ]; then
continue # Skip the bin/ dir
fi
if [ "$project_name" == "$swift_package_dir" ]; then
continue # Skip the Swift Package itself, it is not an integration test project
fi
# Skip IntTestiOSXcode16 when the current Xcode version is smaller than 16
# Xcode 16 projects default to 'Buildable Folders' which are not backwards
# compatible with Xcode 15.* versions. Skipping the IntTestiOSXcode16 project
# ensures that the pipelines pass when executed on runners with Xcode version < 16
if [ "$project_name" == "IntTestiOSXcode16" ]; then
xcode_version=$(xcodebuild -version | grep "Xcode" | awk '{print $2}' | cut -d. -f1)
if [ "$xcode_version" -lt 16 ]; then
echo "Skipped $project_name due to Xcode version $xcode_version"
continue
fi
fi
if [ "$project_name" != "$skip_project" ]; then
bash "$(basename "$0")" -v "$version" -s "$source" $additional_args "$project_name"
else
echo "Skipped $project"
fi
done
echo " _"
echo " _ // ALL DONE ($(date))"
echo " \X/"
echo
exit
fi # end of "project loop"
###############################################################################
#### A project parameter was given (by the user or the project loop above) ####
###############################################################################
project="$1"
if [ -n "${use_swiftpm}" ]; then
# Check out the Swift Package version once for all projects that should be tested
# If source is not set, use the GitHub repo URL
if [ -z "$source" ]; then
source="https://github.com/objectbox/objectbox-swift-spm.git"
fi
# TODO Only do this once if called for multiple projects (issues: this script calls itself; this script may be called
# multiple times with different versions; CI does not remove this as it's a Git repo).
echo "Checking out ObjectBox Swift Package from $source at branch/tag $version"
rm -rf "$swift_package_dir"
git clone --depth 1 --branch "$version" "$source" "$swift_package_dir"
fi
cd "${project}"
[ -d "${project}Tests" ] && project_has_tests=true || project_has_tests=false
echo "========================================================================="
echo "Building integration test project '${project}' (tests: $project_has_tests)"
echo "========================================================================="
if [ -n "${use_swiftpm}" ]; then # --------------------- SwiftPM ---------------------
# Note: the below assumes the Swift Package is checked out in the same directory as this script,
# this is done once for all projects, see above.
# Make the existing test projects into Swift Package projects by adding a Package file,
# then build and run tests using swift tools instead of xcodebuild.
# This only works because the Package file excludes iOS/macOS (UI) app specific files.
if [ $project_has_tests == "true" ]; then
template_name="PackageWithTest.swift"
else
template_name="Package.swift"
fi
cp "$script_dir/.templates/$template_name" Package.swift
sed -i '' "s|\${PROJECT_DIR}|$project|g" Package.swift
# If sync flag is given, switch to the Sync xcframework
if [[ $use_swiftpm_sync == "true" ]]; then
echo "Using ObjectBox Sync xcframework"
sed -i '' 's/ObjectBox.xcframework/ObjectBox-Sync.xcframework/g' Package.swift
fi
swift --version
swift package reset
#swift package purge-cache
swift package update
# Use --verbose to make generator print additional log output for debugging
swift package plugin --allow-writing-to-package-directory --allow-network-connections all objectbox-generator --target "$project" --verbose
swift build
if [ -d "${project}Tests" ]; then
echo "Testing SwiftPM project $project..."
# Execute unit tests on the host machine
swift test
fi
if [ "$project" == "IntTestiOSRegularSPM" ]; then
echo "Running tests on iOS simulator for IntTestiOSRegularSPM project..."
# IntTestiOSRegularSPM contains an Xcode iOS app project (as Swift Package projects can currently not run tests on
# an iOS simulator) with the ObjectBox Swift Package manually added as a dependency (as there currently is no way to
# script this).
# Also note that typically a user would run the generator by running the ObjectBox Swift command plugin from the
# Xcode UI. As this is also not possible via script, take the generated files from when treating this project as a
# Swift Package project above.
# Delete Package file to avoid confusing xcodebuild
rm Package.swift
# Steal files generated using swift tools above
mkdir generated
mv IntTestiOSRegularSPM/generated/EntityInfo-IntTestiOSRegularSPM.generated.swift ./generated/
mv IntTestiOSRegularSPM/model-IntTestiOSRegularSPM.json .
xcodebuild -scheme 'IntTestiOSRegularSPMTests' test -destination 'platform=iOS Simulator,name=iPhone 11' -derivedDataPath ./DerivedData -parallel-testing-enabled NO -test-timeouts-enabled NO
fi
elif [ "$project" == "IntTestiOSRegularSPM" ]; then
echo "Skip IntTestiOSRegularSPM for CocoaPods/Carthage, only supported when using --swiftpm option"
else # --------------------- CocoaPods or Carthage ---------------------
options=(CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO CODE_SIGN_ENTITLEMENTS= CODE_SIGNING_ALLOWED=NO ENABLE_BITCODE=NO)
options+=(-derivedDataPath ./DerivedData -scheme "${project}")
if [ -n "$use_carthage" ]; then # --------------------- Carthage ---------------------
if [ -n "$use_staging" ]; then
source="https://raw.githubusercontent.com/objectbox/objectbox-swift-spec-staging/master/cartspec/ObjectBox.json"
echo "Using staging repo at $source"
fi
if [ -z "$source" ]; then
source="https://raw.githubusercontent.com/objectbox/objectbox-swift/main/cartspec/ObjectBox.json"
fi
xcodefile="project.pbxproj" # XCode project file
xcodefile_carthage="project.pbxproj.4carthage" # XCode project file with changes "done by user" after "carthage update"
if [ ! -f "$xcodefile_carthage" ]; then
echo "No $xcodefile_carthage file, skipping..."
exit 0
fi
#echo "github \"objectbox/objectbox-swift\"" > Cartfile
printf "binary \"%s\"" "$source" > Cartfile
if [ -n "${version}" ]; then
if [[ $version =~ ^[[:digit:]] ]]; then
version="== $version" # Cartfile syntax for exact version
fi
echo "Using version: ${version}"
echo " ${version}" >> Cartfile
fi
if [ -n "${file_only}" ]; then
exit
fi
carthage_version=$($carthage_bin version 2>/dev/null || true)
echo "Detected Carthage version ${carthage_version:-N/A}"
$carthage_bin update --use-xcframeworks
xcodeproj_dir=$(find -- *.xcodeproj -maxdepth 0)
mv "$xcodeproj_dir/$xcodefile" "$xcodeproj_dir/$xcodefile.bak"
cp "$xcodefile_carthage" "$xcodeproj_dir/$xcodefile"
Carthage/Build/Mac/OBXCodeGen.framework/setup.rb
options+=(-project "$xcodeproj_dir")
else # --------------------- CocoaPods ---------------------
if [ -n "$use_staging" ]; then
source="https://github.com/objectbox/objectbox-swift-spec-staging.git"
fi
# Set version to minimum deployment target required by ObjectBox pod.
# Note: all other projects are iOS and might not contain iOS in name.
if [[ $project =~ "macOS" ]]; then
echo "platform :osx, '11.0'
" > Podfile
else
echo "platform :ios, '15.0'
" > Podfile
fi
if [ -n "${source}" ]; then
echo "Using source repository: ${source}"
echo "source '${source}'
" >> Podfile
fi
echo "target '${project}' do
use_frameworks!
# Pods for ${project}" >> Podfile
if [ -n "${version}" ]; then
echo "Using version: ${version}"
echo " pod 'ObjectBox', '${version}'" >> Podfile
else
echo " pod 'ObjectBox'" >> Podfile
fi
if [ -d "${project}Tests" ]; then
echo "
target '${project}Tests' do
inherit! :search_paths
end" >> Podfile
fi
echo "
end" >> Podfile
if [ -n "${file_only}" ]; then
exit
fi
pod_bin="$(which pod 2>/dev/null || true)"
# On macOS 'which' will return no error message if the command doesn't exist, so manually print one
if [ -z "$pod_bin" ]; then
echo "Error: the pod command (CocoaPods) was not found. If using rbenv, check if this shell is correctly initialized."
echo "Or otherwise, make sure the CocoaPods gem is installed."
exit 1
fi
cocoapods_version=$($pod_bin --version 2>/dev/null || true)
echo "Detected CocoaPods version ${cocoapods_version:-N/A}"
# On fresh CocoaPods installations (never did 'pod install' before; CI!), CocoaPods 1.8.[0-3] `pod repo update` fails.
# https://github.com/CocoaPods/CocoaPods/issues/9226
# To workaround this, use 'pod install --repo-update' instead
if [[ "$cocoapods_version" > "1.8.3" ]]; then
$pod_bin repo update
else
$pod_bin install --repo-update
fi
if test -f "Podfile.lock"; then
echo "Podfile.lock exist, will use 'pod update' instead of 'pod install'"
$pod_bin update
Pods/ObjectBox/setup.rb --replace-modified
else
$pod_bin install
Pods/ObjectBox/setup.rb
fi
options+=(-workspace "${project}.xcworkspace")
fi # End CocoaPods
xcodebuild clean build "${options[@]}"
if [ -d "${project}Tests" ]; then
xcodebuild test "${options[@]}" -destination 'platform=iOS Simulator,name=iPhone 11' -parallel-testing-enabled NO -test-timeouts-enabled NO
fi
fi