Skip to content

Commit 4d61fc6

Browse files
authored
Migrate to GitHub actions (#878)
* Drop Travis CI * Add Github Actions * Added `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` secrets to this repo * Rotated the saucelabs access key for good measure * Caching `./node_modules` * Utilizing `./buildtools/sauce_connect.sh` in Actions * the version of `sc` was depreciated, upgraded to `4.6.5` * if `$GITHUB_RUN_ID` is present, use that for the tunnel identifier * Update `protractor.conf.js` to check for Github Actions ENV variables
1 parent 4740dc2 commit 4d61fc6

File tree

5 files changed

+56
-29
lines changed

5 files changed

+56
-29
lines changed

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- "**"
7+
pull_request:
8+
branches:
9+
- "**"
10+
11+
env:
12+
SAUCE_USERNAME: ${{secrets.SAUCE_USERNAME}}
13+
SAUCE_ACCESS_KEY: ${{secrets.SAUCE_ACCESS_KEY}}
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v2
21+
- name: Setup node
22+
uses: actions/setup-node@v2-beta
23+
with:
24+
node-version: '14'
25+
check-latest: true
26+
- name: node_modules cache
27+
id: node_modules_cache
28+
uses: actions/cache@v2
29+
with:
30+
path: ./node_modules
31+
key: ${{ runner.os }}-14-node_modules-${{ hashFiles('package-lock.json') }}
32+
restore-keys: |
33+
${{ runner.os }}-14-node_modules-
34+
- name: NPM install
35+
if: steps.node_modules_cache.outputs.cache-hit != 'true'
36+
run: npm ci
37+
- name: Build & run tests
38+
run: |
39+
./buildtools/sauce_connect.sh &
40+
npm test -- --saucelabs

.travis.yml

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

buildtools/run_tests.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# Can take up to two arguments:
2424
# --saucelabs: Use SauceLabs instead of phantomJS.
2525
# --tunnelIdentifier=<tunnelId>: when using SauceLabs, specify the tunnel
26-
# identifier. Otherwise, uses the environment variable TRAVIS_JOB_NUMBER.
26+
# identifier. Otherwise, uses the environment variable GITHUB_RUN_ID.
2727
#
2828
# Prefer to use the `npm test` command as explained below.
2929
#
@@ -45,7 +45,7 @@
4545
# This will start the HTTP Server locally, and connect through SauceConnect
4646
# to SauceLabs remote browsers instances.
4747
#
48-
# Travis will run `npm test -- --saucelabs`.
48+
# Github Actions will run `npm test -- --saucelabs`.
4949

5050
cd "$(dirname $(dirname "$0"))"
5151
BIN_PATH="./node_modules/.bin"
@@ -71,8 +71,8 @@ trap killServer EXIT
7171
# If --saucelabs option is passed, forward it to the protractor command adding
7272
# the second argument that is required for local SauceLabs test run.
7373
if [[ $1 = "--saucelabs" ]]; then
74-
# Enable saucelabs tests only when running locally or when Travis enviroment vars are accessible.
75-
if [[ ( "$TRAVIS" = true && "$TRAVIS_SECURE_ENV_VARS" = true ) || ( -z "$TRAVIS" ) ]]; then
74+
# Enable saucelabs tests only when running locally or when CI enviroment vars are accessible.
75+
if [[ ((! -z "$SAUCE_USERNAME") && (! -z "$SAUCE_ACCESS_KEY")) || ( -z "$CI" ) ]]; then
7676
seleniumStarted=false
7777
sleep 2
7878
echo "Using SauceLabs."

buildtools/sauce_connect.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
# Download and install SauceConnect under Linux 64-bit. To be used when testing
1818
# with SauceLabs locally. See the instructions in protractor.conf.js file.
1919
#
20-
# It should not be used on Travis. Travis already handles SauceConnect.
21-
#
2220
# Script copied from the Closure Library repository:
2321
# https://github.com/google/closure-library/blob/master/scripts/ci/sauce_connect.sh
2422
#
2523

2624
# Setup and start Sauce Connect locally.
27-
CONNECT_URL="https://saucelabs.com/downloads/sc-4.4.1-linux.tar.gz"
25+
CONNECT_URL="https://saucelabs.com/downloads/sc-4.6.5-linux.tar.gz"
2826
CONNECT_DIR="/tmp/sauce-connect-$RANDOM"
2927
CONNECT_DOWNLOAD="sc-latest-linux.tar.gz"
3028

@@ -46,8 +44,13 @@ function removeFiles() {
4644

4745
trap removeFiles EXIT
4846

49-
# This will be used by Protractor to connect to SauceConnect.
50-
TUNNEL_IDENTIFIER="tunnelId-$RANDOM"
47+
# This will be used by Protractor to connect to SauceConnect
48+
if [[(! -z "$GITHUB_RUN_ID")]]; then
49+
TUNNEL_IDENTIFIER="$GITHUB_RUN_ID"
50+
else
51+
TUNNEL_IDENTIFIER="tunnelId-$RANDOM"
52+
fi
53+
5154
echo ""
5255
echo "========================================================================="
5356
echo " Tunnel Identifier to pass to Protractor:"

protractor.conf.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* This will start the HTTP Server locally, and connect through SauceConnect
3737
* to SauceLabs remote browsers instances.
3838
*
39-
* Travis will run `npm test -- --saucelabs`.
39+
* Github will run `npm test -- --saucelabs`.
4040
*/
4141

4242
// Common configuration.
@@ -60,10 +60,10 @@ config = {
6060
var arguments = process.argv.slice(3);
6161

6262
// Default options: run tests locally (saucelabs false) and use the env variable
63-
// TRAVIS_JOB_NUMBER to get the tunnel identifier, when using saucelabs.
63+
// GITHUB_RUN_ID to get the tunnel identifier, when using saucelabs.
6464
var options = {
6565
saucelabs: false,
66-
tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER
66+
tunnelIdentifier: process.env.GITHUB_RUN_ID
6767
};
6868

6969
for (var i = 0; i < arguments.length; i++) {
@@ -77,7 +77,7 @@ for (var i = 0; i < arguments.length; i++) {
7777

7878
if (options.saucelabs) {
7979
if (!options.tunnelIdentifier) {
80-
throw 'No tunnel identifier given! Either the TRAVIS_JOB_NUMBER is not ' +
80+
throw 'No tunnel identifier given! Either the GITHUB_RUN_ID is not ' +
8181
'set, or you haven\'t passed the --tunnelIdentifier=xxx argument.';
8282
}
8383
// SauceLabs configuration.

0 commit comments

Comments
 (0)