22
33set -e -o pipefail
44
5- # Workaround for Travis CI cookbook https://github.com/travis-ci/travis-ci/issues/4862,
6- # where $PATH will be extended with relative paths to the NPM binaries.
7- PATH=` echo ${PATH} | sed -e ' s/:\.\/node_modules\/\.bin//' `
5+ tunnelFileName=" BrowserStackLocal-linux-x64.zip"
6+ tunnelUrl=" https://www.browserstack.com/browserstack-local/${tunnelFileName} "
87
9- TUNNEL_FILE=" BrowserStackLocal-linux-x64.zip"
10- TUNNEL_URL=" https://www.browserstack.com/browserstack-local/${TUNNEL_FILE} "
11- TUNNEL_DIR=" /tmp/browserstack-tunnel"
12- TUNNEL_LOG=" ${LOGS_DIR} /browserstack-tunnel.log"
13-
14- BROWSER_STACK_ACCESS_KEY=` echo ${BROWSER_STACK_ACCESS_KEY} | rev`
8+ tunnelTmpDir=" /tmp/material-browserstack"
9+ tunnelLogFile=" ${tunnelTmpDir} /browserstack-local.log"
10+ tunnelReadyFile=" ${tunnelTmpDir} /readyfile"
11+ tunnelErrorFile=" ${tunnelTmpDir} /errorfile"
1512
1613# Cleanup and create the folder structure for the tunnel connector.
17- rm -rf ${TUNNEL_DIR } ${BROWSER_PROVIDER_READY_FILE }
18- mkdir -p ${TUNNEL_DIR }
19- touch ${TUNNEL_LOG }
14+ rm -rf ${tunnelTmpDir } ${tunnelReadyFile} ${tunnelErrorFile }
15+ mkdir -p ${tunnelTmpDir }
16+ touch ${tunnelLogFile }
2017
21- cd ${TUNNEL_DIR}
18+ # Go into temporary tunnel directory.
19+ cd ${tunnelTmpDir}
2220
2321# Download the browserstack local binaries.
24- curl ${TUNNEL_URL } -o ${TUNNEL_FILE } 2> /dev/null 1> /dev/null
22+ curl ${tunnelUrl } -o ${tunnelFileName } 2> /dev/null 1> /dev/null
2523
2624# Extract the browserstack local binaries from the tarball.
2725mkdir -p browserstack-tunnel
28- unzip -q ${TUNNEL_FILE } -d browserstack-tunnel
26+ unzip -q ${tunnelFileName } -d browserstack-tunnel
2927
30- # Cleanup the download directory .
31- rm ${TUNNEL_FILE }
28+ # Cleanup the downloaded zip archive .
29+ rm ${tunnelFileName }
3230
3331ARGS=" "
3432
35- # Set tunnel-id only on Travis, to make local testing easier.
36- if [ ! -z " ${TRAVIS_JOB_ID} " ]; then
37- ARGS=" ${ARGS} --local-identifier ${TRAVIS_JOB_ID} "
33+ if [ ! -z " ${CIRCLE_BUILD_NUM} " ]; then
34+ ARGS=" ${ARGS} --local-identifier ${CIRCLE_BUILD_NUM} "
3835fi
3936
40- echo " Starting Browserstack Local in the background, logging into: ${TUNNEL_LOG } "
37+ echo " Starting Browserstack Local in the background, logging into: ${tunnelLogFile } "
4138
4239# Extension to the BrowserStackLocal binaries, because those can't create a readyfile.
4340function create_ready_file {
41+ # Process ID for the BrowserStack local asynchronous instance.
42+ tunnelProcessPid=${1}
4443
4544 # To be able to exit the tail properly we need to have a sub shell spawned, which is
4645 # used to track the state of tail.
47- { sleep 120; touch ${BROWSER_PROVIDER_ERROR_FILE } ; } &
46+ { sleep 120; touch ${tunnelErrorFile } ; } &
4847
4948 TIMER_PID=${! }
5049
@@ -54,16 +53,18 @@ function create_ready_file {
5453
5554 # When the tail recognizes the `Ctrl-C` log message the BrowserStack Tunnel is up.
5655 {
57- tail -n0 -f ${TUNNEL_LOG } --pid ${TIMER_PID} | { sed ' /Ctrl/q' && kill -9 ${TIMER_PID} ; };
56+ tail -n0 -f ${tunnelLogFile } --pid ${TIMER_PID} | { sed ' /Ctrl/q' && kill -9 ${TIMER_PID} ; };
5857 } & > /dev/null
5958
6059 echo
6160 echo " BrowserStack Tunnel ready"
6261
63- touch ${BROWSER_PROVIDER_READY_FILE}
62+ # Create the readyfile and write the PID for BrowserStack Local into it.
63+ echo ${tunnelProcessPid} > ${tunnelReadyFile}
6464}
6565
66- browserstack-tunnel/BrowserStackLocal -k ${BROWSER_STACK_ACCESS_KEY} ${ARGS} 2>&1 >> ${TUNNEL_LOG} &
66+ browserstack-tunnel/BrowserStackLocal -k ${BROWSER_STACK_ACCESS_KEY} ${ARGS} 2>&1 >> \
67+ ${tunnelLogFile} &
6768
6869# Wait for the tunnel to be ready and create the readyfile with the Browserstack PID
69- create_ready_file &
70+ create_ready_file ${ ! } &
0 commit comments