-
Notifications
You must be signed in to change notification settings - Fork 4
/
rws
executable file
·168 lines (146 loc) · 4.43 KB
/
rws
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
#!/usr/bin/env bash
set -e
IFS=$'\t\n'
# sane defaults
# When SELE_VER="" it will use latest
SELE_VER=""
CHROME_START_COUNT="1"
FIREFOX_START_COUNT="1"
WITH_VIDEOS="true"
status=101 #assumed it failed unless proved wrong
# to count minutes of usage
start_time=$(date +%s)
TEST_CONTAINER="test_${BUILD_NUMBER}"
[ -z "${SEL_CONTAINER}" ] && SEL_CONTAINER="zalenium"
TOOLS_DIR="/tools"
# Exit all child processes properly
shutdown () {
echo ""
echo "-----------------"
echo "--- TESTS END ---"
echo "-----------------"
# shutdown tests if still running
echo "INFO: Shutting down the test command..."
docker stop ${TEST_CONTAINER} >/dev/null 2>&1 || true
docker rm ${TEST_CONTAINER} >/dev/null 2>&1 || true
# shutdown selenium
echo "INFO: Shutting down selenium..."
# Run up-to-date Zalenium stop command
curl -sSL "https://raw.githubusercontent.com/dosel/t/i/p" | bash -s stop
if [ "${WITH_VIDEOS}" == "true" ]; then
if ! ls -la ./videos/; then
echo "WARN: Videos should but were not transferred!" >&2
fi
fi
echo "-- RESULT: Tests exit code=${status}"
# give correct feedback
exit ${status}
}
# Run function shutdown() when this process a killer signal
trap shutdown SIGHUP SIGTERM SIGINT
# In OSX install gtimeout through
# brew install coreutils
function mtimeout() {
if [ "$(uname -s)" = 'Darwin' ]; then
gtimeout "$@"
else
timeout "$@"
fi
}
# parse cli options http://stackoverflow.com/a/14203146/511069
for i in "$@"; do
case $i in
-s=*|--selenium=*)
SELE_VER="${i#*=}"
shift # past argument=value
;;
-c=*|--chrome-count=*)
CHROME_START_COUNT="${i#*=}"
shift # past argument=value
;;
-f=*|--firefox-count=*)
FIREFOX_START_COUNT="${i#*=}"
shift # past argument=value
;;
--no-videos)
WITH_VIDEOS="false"
shift # past argument with no value
;;
*)
# unknown option
;;
esac
done
if [ $# -lt 1 ]; then
echo "Usage: $0 [--selenium=3] [--chrome-count=1] [--firefox-count=1] <toolchain> [<toolchain-docker-opts>] -- <toolchain-command>" >&2
echo " Simple example: $0 :toolchain-frontend -- gulp ui-test" >&2
echo " Advanced example: $0 --chrome-count=2 --firefox-count=2 :toolchain-frontend -- gulp ui-test" >&2
#usage error arbitrary error number
status=202
exit $status
fi
TEST_DOCKER_IMAGE=$1
# remove first 1 args, we saved them leaving us with docker opts and command for the run tool
shift 1
# clean-up old Docker container
docker stop ${SEL_CONTAINER} 2>/dev/null || true
docker rm -fv ${SEL_CONTAINER} 2>/dev/null || true
# clean-up old Docker containers
docker rm -ff /test_0 2>/dev/null || true
docker rm -ff test_0 2>/dev/null || true
# Pull the toolchain so doesn't take test running time
${TOOLS_DIR}/run ${TEST_DOCKER_IMAGE} -- \
echo "Pull the toolchain so doesn't take testing time"
export VIDEO=${WITH_VIDEOS}
echo "INFO: Cleaning up previous Selenium instances..."
curl -sSL "https://raw.githubusercontent.com/dosel/t/i/p" | bash -s stop >/dev/null 2>&1
echo "INFO: Starting Selenium..."
curl -sSL "https://raw.githubusercontent.com/dosel/t/i/p" | bash -s ${SELE_VER} start
# wait a bit more to show the complete logs
sleep 2
echo "INFO: Retrieving current Zalenium logs..."
docker logs ${SEL_CONTAINER}
# Sauce Labs or BrowserStack have tunnel IDs
if [ "${SAUCE_USERNAME}" != "" ] || [ "${BROWSER_STACK_USER}" != "" ]; then
export TUNNEL_ID="zalenium${BUILD_NUMBER}"
fi
start_time=$(date +%s)
# execute real command
echo ""
echo "-------------------"
echo "--- TESTS START ---"
echo "-------------------" && echo ""
# set +e
${TOOLS_DIR}/run ${TEST_DOCKER_IMAGE} \
--name=${TEST_CONTAINER} \
--net=container:${SEL_CONTAINER} \
-e SELENIUM_URL="http://localhost:4444/wd/hub" \
-e TUNNEL_ID \
-e APPLICATION_ID \
-e OAUTH2_ACCESS_TOKEN_URL \
-e TOOLCHAIN_LOOKUP_PREFIX \
-e TOOLCHAIN_LOOKUP_REGISTRY \
-e TOOLCHAIN_LOOKUP_NAMESPACE \
-e TOKENINFO_URL \
-e KIO_URL \
-e CREDENTIALS_DIR \
-e MAVEN_MIRROR_URL \
-e MAVEN_SNAPSHOTS_URL \
-e MAVEN_USER \
-e MAVEN_RELEASES_URL \
-e BUILD_ID \
-e BUILD_TAG \
-e NODE_NAME \
-e EXECUTOR_NUMBER \
-e HUDSON_HOME \
-e JENKINS_HOME \
-e JENKINS_USER \
-e JENKINS_URL \
-e JOB_BASE_NAME \
-e JOB_NAME \
-e JOB_URL \
-e BUILD_DISPLAY_NAME \
-e BUILD_NUMBER \
-e BUILD_URL \
$@ && status=$? || status=$?
shutdown