-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.sh
executable file
·276 lines (233 loc) · 7.75 KB
/
test.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
#!/usr/bin/env bash
set -eu
##### Used in Podfile/Cartfile #####
version=""
source=""
##### Behavioral flags #####
file_only=""
do_clean=""
use_carthage=""
use_staging=""
framework=""
skip_project=""
carthage_bin="carthage"
while [ $# -ge 1 ]; do
case $1 in
-h|help|--help|usage)
echo "Usage: $(basename "$0") [options] {project-directory}"
echo
echo " -v, --version: specify version for the Podfile/Cartfile"
echo " -s, --source: specify source repository for the Podfile/Cartfile"
echo " -S, --staging: use the staging source repository for the Podfile/Cartfile"
echo " -f, --file: only create Podfile/Cartfile"
echo " -c, --carthage: use Carthage instead of CocoaPods"
echo " --carthage-bin: use the packaged Carthage executable from our bin dir"
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: specify a project to skip"
echo " --framework: specify a HTTPS URL to an uploaded framework to be tested"
echo " (this creates a local Cartfile pointing to the URL)"
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"
;;
*) 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
#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 "$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 [ -z "${1-}" ]; then # No tailing "project" param, so loop over dirs and call this script with those
# Original args ($@) are gone as we called shift during parsing.
# Also, cannot capture original args as string as we need to preserve spaces, 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_staging" ]; then
additional_args+=" --staging"
fi
# Note: we do not need to propagate --clean flag
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 our bin/ dir
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
project="$1"
echo "========================================================================="
echo "Building integration test project '${project}'"
echo "========================================================================="
options=(CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO CODE_SIGN_ENTITLEMENTS= CODE_SIGNING_ALLOWED=NO ENABLE_BITCODE=NO)
options+=(-derivedDataPath ./DerivedData -scheme "${project}")
cd "${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 mimimum 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, '10.15'
" > Podfile
else
echo "platform :ios, '12.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)"
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'
fi