Skip to content

Commit 6534eb0

Browse files
devversiontinayuangao
authored andcommitted
chore: remove inactive browserstack wrapper package (#1991)
* chore: remove inactive browserstack wrapper package No longer uses the "inactive" browserstack wrapper package from npm, which was just responsible for creating the readyfile. We can create the readyfile ourself and get rid of the npm package. * Fix incorrect comments * Don't wait for tunnel if timer exceeded * Fix race conditions * Add empty line before logging that the tunnel is ready.
1 parent 26eb7ce commit 6534eb0

File tree

6 files changed

+83
-68
lines changed

6 files changed

+83
-68
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ env:
2424
- BROWSER_STACK_ACCESS_KEY=BWCd4SynLzdDcv8xtzsB
2525
- ARCH=linux-x64
2626
- BROWSER_PROVIDER_READY_FILE=/tmp/angular-material2-build/readyfile
27+
- BROWSER_PROVIDER_ERROR_FILE=/tmp/angular-material2-build/errorfile
2728
# GITHUB_TOKEN_ANGULAR
2829
- secure: "fq/U7VDMWO8O8SnAQkdbkoSe2X92PVqg4d044HmRYVmcf6YbO48+xeGJ8yOk0pCBwl3ISO4Q2ot0x546kxfiYBuHkZetlngZxZCtQiFT9kyId8ZKcYdXaIW9OVdw3Gh3tQyUwDucfkVhqcs52D6NZjyE2aWZ4/d1V4kWRO/LMgo="
2930
matrix:

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"@types/node": "^6.0.34",
5252
"@types/run-sequence": "0.0.27",
5353
"@types/rx": "^2.5.33",
54-
"browserstacktunnel-wrapper": "^2.0.0",
5554
"conventional-changelog": "^1.1.0",
5655
"express": "^4.14.0",
5756
"firebase-tools": "^2.2.1",

scripts/browserstack/start_tunnel.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

scripts/browserstack/start_tunnel.sh

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,72 @@
1-
export BROWSER_STACK_ACCESS_KEY=`echo $BROWSER_STACK_ACCESS_KEY | rev`
1+
#!/bin/bash
22

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 browserstack local binaries.
24+
curl $TUNNEL_URL -o $TUNNEL_FILE 2> /dev/null 1> /dev/null
25+
26+
# Extract the browserstack local 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; touch $BROWSER_PROVIDER_ERROR_FILE; } &
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
64+
echo "BrowserStack Tunnel ready"
65+
66+
touch $BROWSER_PROVIDER_READY_FILE
67+
}
68+
69+
browserstack-tunnel/BrowserStackLocal -k $BROWSER_STACK_ACCESS_KEY $ARGS &>> $TUNNEL_LOG &
70+
71+
# Wait for the tunnel to be ready and create the readyfile with the Browserstack PID
72+
create_ready_file &

scripts/browserstack/teardown_tunnel.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ set -e -o pipefail
55

66
echo "Shutting down Browserstack tunnel"
77

8-
PID=$(cat $BROWSER_PROVIDER_READY_FILE);
8+
killall BrowserStackLocal
99

10-
# Resolving the PID from the readyfile.
11-
kill $PID
12-
13-
14-
while [[ -n `ps -ef | grep $PID | grep -v "grep"` ]]; do
10+
while [[ -n `ps -ef | grep "BrowserStackLocal" | grep -v "grep"` ]]; do
1511
printf "."
1612
sleep .5
1713
done

scripts/browserstack/waitfor_tunnel.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#!/bin/bash
22

3+
TUNNEL_LOG="$LOGS_DIR/browserstack-tunnel.log"
34

45
# Wait for Connect to be ready before exiting
56
# Time out if we wait for more than 2 minutes, so the process won't run forever.
67
let "counter=0"
78

9+
# Exit the process if there are errors reported. Print the tunnel log to the console.
10+
if [ -f $BROWSER_PROVIDER_ERROR_FILE ]; then
11+
echo
12+
echo "An error occurred while starting the tunnel. See error:"
13+
cat $TUNNEL_LOG
14+
exit 5
15+
fi
16+
817
while [ ! -f $BROWSER_PROVIDER_READY_FILE ]; do
918
let "counter++"
1019

0 commit comments

Comments
 (0)