|
1 |
| -export BROWSER_STACK_ACCESS_KEY=`echo $BROWSER_STACK_ACCESS_KEY | rev` |
| 1 | +#!/bin/bash |
2 | 2 |
|
3 |
| -node ./scripts/browserstack/start_tunnel.js & |
| 3 | +set -e -o pipefail |
| 4 | + |
| 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//'` |
| 8 | + |
| 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` |
| 15 | + |
| 16 | +# 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 |
| 20 | + |
| 21 | +cd $TUNNEL_DIR |
| 22 | + |
| 23 | +# Download the saucelabs connect binaries. |
| 24 | +curl $TUNNEL_URL -o $TUNNEL_FILE 2> /dev/null 1> /dev/null |
| 25 | + |
| 26 | +# Extract the saucelabs connect binaries from the tarball. |
| 27 | +mkdir -p browserstack-tunnel |
| 28 | +unzip -q $TUNNEL_FILE -d browserstack-tunnel |
| 29 | + |
| 30 | +# Cleanup the download directory. |
| 31 | +rm $TUNNEL_FILE |
| 32 | + |
| 33 | +ARGS="" |
| 34 | + |
| 35 | +# Set tunnel-id only on Travis, to make local testing easier. |
| 36 | +if [ ! -z "$TRAVIS_JOB_NUMBER" ]; then |
| 37 | + ARGS="$ARGS --local-identifier $TRAVIS_JOB_NUMBER" |
| 38 | +fi |
| 39 | + |
| 40 | +echo "Starting Browserstack Local in the background, logging into:" |
| 41 | +echo " $TUNNEL_LOG" |
| 42 | +echo " ---" |
| 43 | +echo " $ARGS" |
| 44 | + |
| 45 | +# Extension to the BrowserStackLocal binaries, because those can't create a readyfile. |
| 46 | +function create_ready_file { |
| 47 | + |
| 48 | + # To be able to exit the tail properly we need to have a sub shell spawned, which is |
| 49 | + # used to track the state of tail. |
| 50 | + sleep 120 & |
| 51 | + |
| 52 | + TIMER_PID=$! |
| 53 | + |
| 54 | + # Disown the background process, because we don't want to show any messages when killing |
| 55 | + # the timer. |
| 56 | + disown |
| 57 | + |
| 58 | + # When the tail recognizes the `Ctrl-C` log message the BrowserStack Tunnel is up. |
| 59 | + { |
| 60 | + tail -n0 -f $TUNNEL_LOG --pid $TIMER_PID | { sed '/Ctrl/q' && kill -9 $TIMER_PID; }; |
| 61 | + } &> /dev/null |
| 62 | + |
| 63 | + echo "BrowserStack Tunnel ready" |
| 64 | + |
| 65 | + touch $BROWSER_PROVIDER_READY_FILE |
| 66 | +} |
| 67 | + |
| 68 | +browserstack-tunnel/BrowserStackLocal -k $BROWSER_STACK_ACCESS_KEY $ARGS &>> $TUNNEL_LOG & |
| 69 | + |
| 70 | +# Wait for the tunnel to be ready and create the readyfile with the Browserstack PID |
| 71 | +create_ready_file & |
0 commit comments