-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathcommon.sh
executable file
·180 lines (156 loc) · 4.46 KB
/
common.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
#!/bin/bash
set -e
RESET="\033[0m"
BLACK="\033[30m"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
MAGENTA="\033[35m"
CYAN="\033[36m"
WHITE="\033[37m"
BOLDBLACK="\033[1m\033[30m"
BOLDRED="\033[1m\033[31m"
BOLDGREEN="\033[1m\033[32m"
BOLDYELLOW="\033[1m\033[33m"
BOLDBLUE="\033[1m\033[34m"
BOLDMAGENTA="\033[1m\033[35m"
BOLDCYAN="\033[1m\033[36m"
BOLDWHITE="\033[1m\033[37m"
# make sure all tests are passing
if [[ `uname` == "Darwin" ]]; then
echo "🏔 Running iOS 17 / Xcode 15"
if [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.iOS-17- | wc -l` -ge 1 ]; then
DEFAULT_IOS_SIMULATOR=RxSwiftTest/iPhone-15/iOS/17.4
else
echo "No iOS 17.* Simulator found, available runtimes are:"
xcrun simctl list runtimes
exit -1
fi
if [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.watchOS-10- | wc -l` -ge 1 ]; then
DEFAULT_WATCHOS_SIMULATOR=RxSwiftTest/Apple-Watch-Series-9-45mm/watchOS/10.0
else
echo "No watchOS 10.* Simulator found, available runtimes are:"
xcrun simctl list runtimes
exit -1
fi
if [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.tvOS-17- | wc -l` -ge 1 ]; then
DEFAULT_TVOS_SIMULATOR=RxSwiftTest/Apple-TV-1080p/tvOS/17.0
else
echo "No tvOS 17.* Simulator found, available runtimes are:"
xcrun simctl list runtimes
exit -1
fi
fi
RUN_SIMULATOR_BY_NAME=0
function runtime_available() {
if [ `xcrun simctl list runtimes | grep "${1}" | wc -l` -eq 1 ]; then
return 0
else
return 1
fi
}
# used to check simulator name
function contains() {
string="$1"
substring="$2"
if [[ $string == *"$substring"* ]]
then
return 0 # $substring is in $string
else
return 1 # $substring is not in $string
fi
}
function simulator_ids() {
SIMULATOR=$1
xcrun simctl list | grep "${SIMULATOR}" | cut -d "(" -f 2 | cut -d ")" -f 1 | sort | uniq
}
function simulator_available() {
SIMULATOR=$1
if [ `simulator_ids "${SIMULATOR}" | wc -l` -eq 0 ]; then
return -1
elif [ `simulator_ids "${SIMULATOR}" | wc -l` -gt 1 ]; then
echo "Multiple simulators ${SIMULATOR} found"
xcrun simctl list | grep "${SIMULATOR}"
exit -1
elif [ `xcrun simctl list | grep "${SIMULATOR}" | grep "unavailable" | wc -l` -gt 0 ]; then
xcrun simctl list | grep "${SIMULATOR}" | grep "unavailable"
exit -1
else
return 0
fi
}
function is_real_device() {
contains "$1" "’s "
}
function ensure_simulator_available() {
SIMULATOR=$1
if simulator_available "${SIMULATOR}"; then
echo "${SIMULATOR} exists"
return
fi
DEVICE=`echo "${SIMULATOR}" | cut -d "/" -f 2`
OS=`echo "${SIMULATOR}" | cut -d "/" -f 3`
VERSION_SUFFIX=`echo "${SIMULATOR}" | cut -d "/" -f 4 | sed -e "s/\./-/"`
RUNTIME="com.apple.CoreSimulator.SimRuntime.${OS}-${VERSION_SUFFIX}"
echo "Creating new simulator with runtime=${RUNTIME}"
xcrun simctl create "${SIMULATOR}" "com.apple.CoreSimulator.SimDeviceType.${DEVICE}" "${RUNTIME}"
SIMULATOR_ID=`simulator_ids "${SIMULATOR}"`
echo "Warming up ${SIMULATOR_ID} ..."
xcrun simctl boot "${SIMULATOR_ID}"
open -a "Simulator" --args -CurrentDeviceUDID "${SIMULATOR_ID}" || true
sleep 120
}
BUILD_DIRECTORY=build
function rx() {
action Rx.xcworkspace "$1" "$2" "$3" "$4"
}
function action() {
WORKSPACE=$1
SCHEME=$2
CONFIGURATION=$3
SIMULATOR=$4
ACTION=$5
echo
printf "${GREEN}${ACTION} ${BOLDCYAN}$SCHEME - $CONFIGURATION ($SIMULATOR)${RESET}\n"
echo
DESTINATION=""
if [ "${SIMULATOR}" != "" ]; then
#if it's a real device
if is_real_device "${SIMULATOR}"; then
DESTINATION='name='${SIMULATOR}
#else it's just a simulator
else
OS=`echo $SIMULATOR | cut -d '/' -f 3`
if [ "${RUN_SIMULATOR_BY_NAME}" -eq 1 ]; then
SIMULATOR_NAME=`echo $SIMULATOR | cut -d '/' -f 1`
DESTINATION='platform='$OS' Simulator,name='$SIMULATOR_NAME''
else
ensure_simulator_available "${SIMULATOR}"
SIMULATOR_GUID=`simulator_ids "${SIMULATOR}"`
DESTINATION='platform='$OS' Simulator,OS='$OS',id='$SIMULATOR_GUID''
fi
echo "Running on ${DESTINATION}"
fi
else
DESTINATION='platform=macOS'
fi
set -x
mkdir -p build
killall Simulator || true
LINT=1 xcodebuild -workspace "${WORKSPACE}" \
-scheme "${SCHEME}" \
-configuration "${CONFIGURATION}" \
-derivedDataPath "${BUILD_DIRECTORY}" \
-destination "$DESTINATION" \
$ACTION | tee build/last-build-output.txt | xcbeautify
exitIfLastStatusWasUnsuccessful
set +x
}
function exitIfLastStatusWasUnsuccessful() {
STATUS=${PIPESTATUS[0]}
if [ $STATUS -ne 0 ]; then
echo $STATUS
exit $STATUS
fi
}