- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6.8k
build(): First version of using SauceLabs and BrowserStack on travis. #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| 'use strict'; | ||
| /** | ||
| * Start the BrowserStack tunnel. Once its started it creates a file so the callee can wait | ||
| * for the tunnel to be started. | ||
| */ | ||
|  | ||
| var fs = require('fs'); | ||
| var http = require('http'); | ||
| var BrowserStackTunnel = require('browserstacktunnel-wrapper'); | ||
|  | ||
| var HOSTNAME = 'localhost'; | ||
| var PORTS = [9876, 9877]; | ||
| var ACCESS_KEY = process.env.BROWSER_STACK_ACCESS_KEY; | ||
| var READY_FILE = process.env.BROWSER_PROVIDER_READY_FILE; | ||
| var TUNNEL_IDENTIFIER = process.env.TRAVIS_JOB_NUMBER; | ||
|  | ||
| // We need to start fake servers, otherwise the tunnel does not start. | ||
| var fakeServers = []; | ||
| var hosts = []; | ||
|  | ||
| PORTS.forEach(function(port) { | ||
| fakeServers.push(http.createServer(function() {}).listen(port)); | ||
| hosts.push({ | ||
| name: HOSTNAME, | ||
| port: port, | ||
| sslFlag: 0 | ||
| }); | ||
| }); | ||
|  | ||
| var tunnel = new BrowserStackTunnel({ | ||
| key: ACCESS_KEY, | ||
| localIdentifier: TUNNEL_IDENTIFIER, | ||
| hosts: hosts | ||
| }); | ||
|  | ||
| console.log('Starting tunnel on ports', PORTS.join(', ')); | ||
| tunnel.start(function(error) { | ||
| if (error) { | ||
| console.error('Can not establish the tunnel', error); | ||
| } else { | ||
| console.log('Tunnel established.'); | ||
| fakeServers.forEach(function(server) { | ||
| server.close(); | ||
| }); | ||
|  | ||
| if (READY_FILE) { | ||
| fs.writeFile(READY_FILE, ''); | ||
| } | ||
| } | ||
| }); | ||
|  | ||
| tunnel.on('error', function(error) { | ||
| console.error(error); | ||
| }); | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export BROWSER_STACK_ACCESS_KEY=`echo $BROWSER_STACK_ACCESS_KEY | rev` | ||
|  | ||
| node ./scripts/browserstack/start_tunnel.js & | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #!/bin/bash | ||
|  | ||
| set -e -o pipefail | ||
|  | ||
|  | ||
| echo "Shutting down Browserstack tunnel" | ||
| echo "TODO: implement me" | ||
| exit 1 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #!/bin/bash | ||
|  | ||
|  | ||
| # Wait for Connect to be ready before exiting | ||
| # Time out if we wait for more than 2 minutes, so that we can print logs. | ||
| let "counter=0" | ||
|  | ||
| while [ ! -f $BROWSER_PROVIDER_READY_FILE ]; do | ||
| let "counter++" | ||
| if [ $counter -gt 240 ]; then | ||
| echo "Timed out after 2 minutes waiting for browser provider ready file" | ||
| # We must manually print logs here because travis will not run | ||
| # after_script commands if the failure occurs before the script | ||
| # phase. | ||
| ./scripts/ci/print-logs.sh | ||
| exit 5 | ||
| fi | ||
| sleep .5 | ||
| done | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #!/bin/bash | ||
|  | ||
| # Wait for Connect to be ready before exiting | ||
| printf "Connecting to Sauce." | ||
| while [ ! -f $BROWSER_PROVIDER_READY_FILE ]; do | ||
| printf "." | ||
| #dart2js takes longer than the travis 10 min timeout to complete | ||
| sleep .5 | ||
| done | ||
| echo "Connected" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| #!/bin/bash | ||
|  | ||
| set -e -o pipefail | ||
|  | ||
| # Setup and start Sauce Connect for your TravisCI build | ||
| # This script requires your .travis.yml to include the following two private env variables: | ||
| # SAUCE_USERNAME | ||
| # SAUCE_ACCESS_KEY | ||
| # Follow the steps at https://saucelabs.com/opensource/travis to set that up. | ||
| # | ||
| # Curl and run this script as part of your .travis.yml before_script section: | ||
| # before_script: | ||
| # - curl https://gist.github.com/santiycr/5139565/raw/sauce_connect_setup.sh | bash | ||
|  | ||
| CONNECT_URL="https://saucelabs.com/downloads/sc-4.3.11-linux.tar.gz" | ||
| CONNECT_DIR="/tmp/sauce-connect-$RANDOM" | ||
| CONNECT_DOWNLOAD="sc-latest-linux.tar.gz" | ||
|  | ||
| CONNECT_LOG="$LOGS_DIR/sauce-connect" | ||
| CONNECT_STDOUT="$LOGS_DIR/sauce-connect.stdout" | ||
| CONNECT_STDERR="$LOGS_DIR/sauce-connect.stderr" | ||
|  | ||
| # Get Connect and start it | ||
| mkdir -p $CONNECT_DIR | ||
| cd $CONNECT_DIR | ||
| curl $CONNECT_URL -o $CONNECT_DOWNLOAD 2> /dev/null 1> /dev/null | ||
| mkdir sauce-connect | ||
| tar --extract --file=$CONNECT_DOWNLOAD --strip-components=1 --directory=sauce-connect > /dev/null | ||
| rm $CONNECT_DOWNLOAD | ||
|  | ||
| SAUCE_ACCESS_KEY=`echo $SAUCE_ACCESS_KEY | rev` | ||
|  | ||
| ARGS="" | ||
|  | ||
| # Set tunnel-id only on Travis, to make local testing easier. | ||
| if [ ! -z "$TRAVIS_JOB_NUMBER" ]; then | ||
| ARGS="$ARGS --tunnel-identifier $TRAVIS_JOB_NUMBER" | ||
| fi | ||
| if [ ! -z "$BROWSER_PROVIDER_READY_FILE" ]; then | ||
| ARGS="$ARGS --readyfile $BROWSER_PROVIDER_READY_FILE" | ||
| fi | ||
|  | ||
|  | ||
| echo "Starting Sauce Connect in the background, logging into:" | ||
| echo " $CONNECT_LOG" | ||
| echo " $CONNECT_STDOUT" | ||
| echo " $CONNECT_STDERR" | ||
| sauce-connect/bin/sc -u $SAUCE_USERNAME -k $SAUCE_ACCESS_KEY $ARGS \ | ||
| --logfile $CONNECT_LOG 2> $CONNECT_STDERR 1> $CONNECT_STDOUT & | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #!/bin/bash | ||
|  | ||
| set -e -o pipefail | ||
|  | ||
|  | ||
| echo "Shutting down Sauce Connect tunnel" | ||
|  | ||
| killall sc | ||
|  | ||
| while [[ -n `ps -ef | grep "sauce-connect-" | grep -v "grep"` ]]; do | ||
| printf "." | ||
| sleep .5 | ||
| done | ||
|  | ||
| echo "" | ||
| echo "Sauce Connect tunnel has been shut down" | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add comment up top here explaining what the purpose of this script is?