forked from braintree/braintree_android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.sh
executable file
·126 lines (102 loc) · 2.97 KB
/
ci.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
#!/bin/bash
android_path="$PWD"
if [ -z "${ANDROID_HOME}" ]; then
export ANDROID_HOME=$HOME/.android-sdk
fi
android_adb=$ANDROID_HOME/platform-tools/adb
export PATH=$ANDROID_HOME/platform-tools:$PATH
export rvm_trust_rvmrcs_flag=1
gateway_path="$PWD/../$JOB_NAME-gateway"
gateway_pid="/tmp/$JOB_NAME-gateway-server"
gateway_port=3000
emulator_started_at=0
cd_android() {
cd $android_path
}
cd_gateway() {
cd $gateway_path
source $HOME/.rvm/scripts/rvm
source .rvmrc_ci
}
init_gateway_repo() {
if [ -d $gateway_path ]; then
(cd $gateway_path && git clean -dxf && git checkout . && git pull)
else
(git clone [email protected]:braintree/gateway.git $gateway_path)
(cd $gateway_path && git checkout $1)
fi
}
init_gateway() {
./ci.sh prepare
}
start_gateway() {
stop_gateway
bundle exec thin --port $gateway_port --pid "$gateway_pid" --daemonize start
sleep 30
}
stop_gateway() {
cd_gateway
if [ -f $gateway_pid ]; then
bundle exec thin --pid "$gateway_pid" stop
fi
}
cleanup_android() {
$android_adb emu kill
$android_adb kill-server
kill -9 `cat /tmp/httpsd.pid`
}
start_adb() {
echo "Starting ADB server"
$android_adb start-server
echo "ADB server started"
}
start_emulator() {
echo "Creating emulator"
echo no | $ANDROID_HOME/tools/android create avd --force -n braintree-android -t android-22 --abi armeabi-v7a --skin WXGA720
echo "hw.keyboard=yes" >> ~/.android/avd/braintree-android.avd/config.ini
echo "Starting emulator"
$ANDROID_HOME/tools/emulator -avd braintree-android -no-boot-anim -wipe-data -no-audio -no-window &
emulator_started_at=$(date +%s)
}
wait_for_emulator() {
# This is a hack - wait-for-device just checks power on.
# By polling until the package manager is ready, we can make sure a device is actually booted
# before attempting to run tests.
echo "Waiting for emulator to start and package manager to load"
adb_output=$(($android_adb shell pm path android) 2>&1)
while [[ $adb_output == *'error'* ]]; do
if [ $(($emulator_started_at + 900)) -lt $(date +%s) ]; then
cleanup_android
stop_gateway
exit 1
fi
sleep 2
adb_output=$(($android_adb shell pm path android) 2>&1)
done
echo "Emulator ready, starting tests"
}
# Build three times, the first two builds will resolve dependencies via sdk-manager-plugin and then fail
# https://github.com/JakeWharton/sdk-manager-plugin/issues/10
$android_path/gradlew --info --no-color clean assembleDebug
$android_path/gradlew --info --no-color clean assembleDebug
$android_path/gradlew --info --no-color clean lint
lint_return_code=$?
if [ $lint_return_code -ne 0 ]; then
exit 1
fi
cleanup_android
cd_android
start_adb
start_emulator
init_gateway_repo $GATEWAY_BRANCH
cd_gateway
init_gateway
start_gateway
cd_android
wait_for_emulator
ruby script/httpsd.rb /tmp/httpsd.pid
$android_path/gradlew --info --continue --no-color runAllTests connectedAndroidTest
test_return_code=$?
cleanup_android
stop_gateway
exit $test_return_code;