Skip to content

Commit 5108eae

Browse files
committed
Adds CI
1 parent bd9661a commit 5108eae

File tree

3 files changed

+171
-1
lines changed

3 files changed

+171
-1
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ notifications:
77
email: false
88

99
script:
10-
- echo "WIP"
10+
- . ./scripts/common.sh ; rx "Tests" Release "${DEFAULT_IOS_SIMULATOR}" test

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Travis CI](https://travis-ci.org/RxSwiftCommunity/RxDataSources.svg?branch=master)](https://travis-ci.org/RxSwiftCommunity/RxDataSources)
2+
13
Table and Collection view data sources
24
======================================
35

scripts/common.sh

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#!/bin/bash
2+
set -e
3+
4+
RESET="\033[0m"
5+
BLACK="\033[30m"
6+
RED="\033[31m"
7+
GREEN="\033[32m"
8+
YELLOW="\033[33m"
9+
BLUE="\033[34m"
10+
MAGENTA="\033[35m"
11+
CYAN="\033[36m"
12+
WHITE="\033[37m"
13+
BOLDBLACK="\033[1m\033[30m"
14+
BOLDRED="\033[1m\033[31m"
15+
BOLDGREEN="\033[1m\033[32m"
16+
BOLDYELLOW="\033[1m\033[33m"
17+
BOLDBLUE="\033[1m\033[34m"
18+
BOLDMAGENTA="\033[1m\033[35m"
19+
BOLDCYAN="\033[1m\033[36m"
20+
BOLDWHITE="\033[1m\033[37m"
21+
22+
# make sure all tests are passing
23+
24+
if [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.iOS-10-1 | wc -l` -eq 1 ]; then
25+
DEFAULT_IOS_SIMULATOR=RxSwiftTest/iPhone-6/iOS/10.1
26+
else
27+
DEFAULT_IOS_SIMULATOR=RxSwiftTest/iPhone-6/iOS/10.0
28+
fi
29+
30+
if [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.watchOS-3-1 | wc -l` -eq 1 ]; then
31+
DEFAULT_WATCHOS_SIMULATOR=RxSwiftTest/Apple-Watch-38mm/watchOS/3.1
32+
else
33+
DEFAULT_WATCHOS_SIMULATOR=RxSwiftTest/Apple-Watch-38mm/watchOS/3.0
34+
fi
35+
36+
if [ `xcrun simctl list runtimes | grep com.apple.CoreSimulator.SimRuntime.tvOS-10-1 | wc -l` -eq 1 ]; then
37+
DEFAULT_TVOS_SIMULATOR=RxSwiftTest/Apple-TV-1080p/tvOS/10.1
38+
else
39+
DEFAULT_TVOS_SIMULATOR=RxSwiftTest/Apple-TV-1080p/tvOS/10.0
40+
fi
41+
RUN_SIMULATOR_BY_NAME=0
42+
43+
function runtime_available() {
44+
if [ `xcrun simctl list runtimes | grep "${1}" | wc -l` -eq 1 ]; then
45+
return 0
46+
else
47+
return 1
48+
fi
49+
}
50+
51+
# used to check simulator name
52+
function contains() {
53+
string="$1"
54+
substring="$2"
55+
if [[ $string == *"$substring"* ]]
56+
then
57+
return 0 # $substring is in $string
58+
else
59+
return 1 # $substring is not in $string
60+
fi
61+
}
62+
63+
function simulator_ids() {
64+
SIMULATOR=$1
65+
xcrun simctl list | grep "${SIMULATOR}" | cut -d "(" -f 2 | cut -d ")" -f 1 | sort | uniq
66+
}
67+
68+
function simulator_available() {
69+
SIMULATOR=$1
70+
if [ `simulator_ids "${SIMULATOR}" | wc -l` -eq 0 ]; then
71+
return -1
72+
elif [ `simulator_ids "${SIMULATOR}" | wc -l` -gt 1 ]; then
73+
echo "Multiple simulators ${SIMULATOR} found"
74+
xcrun simctl list | grep "${SIMULATOR}"
75+
exit -1
76+
elif [ `xcrun simctl list | grep "${SIMULATOR}" | grep "unavailable" | wc -l` -gt 0 ]; then
77+
xcrun simctl list | grep "${SIMULATOR}" | grep "unavailable"
78+
exit -1
79+
else
80+
return 0
81+
fi
82+
}
83+
84+
function is_real_device() {
85+
contains "$1" "’s "
86+
}
87+
88+
function ensure_simulator_available() {
89+
SIMULATOR=$1
90+
91+
if simulator_available "${SIMULATOR}"; then
92+
echo "${SIMULATOR} exists"
93+
return
94+
fi
95+
96+
DEVICE=`echo "${SIMULATOR}" | cut -d "/" -f 2`
97+
OS=`echo "${SIMULATOR}" | cut -d "/" -f 3`
98+
VERSION_SUFFIX=`echo "${SIMULATOR}" | cut -d "/" -f 4 | sed -e "s/\./-/"`
99+
100+
RUNTIME="com.apple.CoreSimulator.SimRuntime.${OS}-${VERSION_SUFFIX}"
101+
102+
echo "Creating new simulator with runtime=${RUNTIME}"
103+
xcrun simctl create "${SIMULATOR}" "com.apple.CoreSimulator.SimDeviceType.${DEVICE}" "${RUNTIME}"
104+
105+
SIMULATOR_ID=`simulator_ids "${SIMULATOR}"`
106+
echo "Warming up ${SIMULATOR_ID} ..."
107+
open -a "Simulator" --args -CurrentDeviceUDID "${SIMULATOR_ID}"
108+
sleep 120
109+
}
110+
111+
BUILD_DIRECTORY=build
112+
113+
function rx() {
114+
action RxDataSources.xcworkspace "$1" "$2" "$3" "$4"
115+
}
116+
117+
function action() {
118+
WORKSPACE=$1
119+
SCHEME=$2
120+
CONFIGURATION=$3
121+
SIMULATOR=$4
122+
ACTION=$5
123+
124+
echo
125+
printf "${GREEN}${ACTION} ${BOLDCYAN}$SCHEME - $CONFIGURATION ($SIMULATOR)${RESET}\n"
126+
echo
127+
128+
DESTINATION=""
129+
if [ "${SIMULATOR}" != "" ]; then
130+
#if it's a real device
131+
if is_real_device "${SIMULATOR}"; then
132+
DESTINATION='name='${SIMULATOR}
133+
#else it's just a simulator
134+
else
135+
OS=`echo $SIMULATOR | cut -d '/' -f 3`
136+
if [ "${RUN_SIMULATOR_BY_NAME}" -eq 1 ]; then
137+
SIMULATOR_NAME=`echo $SIMULATOR | cut -d '/' -f 1`
138+
DESTINATION='platform='$OS' Simulator,name='$SIMULATOR_NAME''
139+
else
140+
ensure_simulator_available "${SIMULATOR}"
141+
SIMULATOR_GUID=`simulator_ids "${SIMULATOR}"`
142+
DESTINATION='platform='$OS' Simulator,OS='$OS',id='$SIMULATOR_GUID''
143+
fi
144+
echo "Running on ${DESTINATION}"
145+
fi
146+
else
147+
DESTINATION='platform=macOS,arch=x86_64'
148+
fi
149+
150+
set -x
151+
killall Simulator || true
152+
xcodebuild -workspace "${WORKSPACE}" \
153+
-scheme "${SCHEME}" \
154+
-configuration "${CONFIGURATION}" \
155+
-derivedDataPath "${BUILD_DIRECTORY}" \
156+
-destination "$DESTINATION" \
157+
$ACTION | tee build/last-build-output.txt | xcpretty -c
158+
exitIfLastStatusWasUnsuccessful
159+
set +x
160+
}
161+
162+
function exitIfLastStatusWasUnsuccessful() {
163+
STATUS=${PIPESTATUS[0]}
164+
if [ $STATUS -ne 0 ]; then
165+
echo $STATUS
166+
exit $STATUS
167+
fi
168+
}

0 commit comments

Comments
 (0)