Skip to content

Commit

Permalink
chore: migrate CircleCI to GH Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmalinowski committed Dec 21, 2020
1 parent fda034d commit a63a3e9
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 116 deletions.
34 changes: 0 additions & 34 deletions .circleci/config.yml

This file was deleted.

Empty file added .github/workflows/.gitkeep
Empty file.
98 changes: 98 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Continuous Integration
on:
push:
branches: [master]
pull_request:

jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- name: Ensure that Chrome is present
run: google-chrome --version
- name: Ensure that Firefox is present
run: firefox --version
- name: Checkout
uses: actions/checkout@v1
- name: Fix ssh+git access
run: git config --global url."https://github.com/".insteadOf "[email protected]:"
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Cache Dependencies
uses: actions/cache@v2
with:
path: |
node_modules
package-lock.json
packages/*/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package.json') }}
- run: npm install
- name: Lint code
run: npm run lint
- name: Lint docs
run: npm run lint:markdown
- run: npm run build:prod
- name: Unit test
run: npm run test

browserstack-integration-tests:
runs-on: ubuntu-latest
env:
BROWSERSTACK_USER: ${{ secrets.BROWSERSTACK_USER }}
BROWSERSTACK_KEY: ${{ secrets.BROWSERSTACK_KEY }}
strategy:
fail-fast: false
matrix:
browser: [safari, edge]
experimental: [true] # due to instabilities of integration tests, let these fail, provided we review failures manually
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Fix ssh+git access
run: git config --global url."https://github.com/".insteadOf "[email protected]:"
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Cache Dependencies
uses: actions/cache@v2
with:
path: |
node_modules
package-lock.json
packages/*/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package.json') }}
- run: npm install
- run: npm run build:debug
- run: npm run build:prod
- name: Run integration tests in Browserstack
run: node ./integration-tests/utils/browserstack.runner.js -e ${{ matrix.browser }} -c ./integration-tests/utils/browserstack.conf.js
continue-on-error: true
timeout-minutes: 10

local-integration-tests:
runs-on: ubuntu-latest
steps:
- name: Ensure that Chrome is present
run: google-chrome --version
- name: Ensure that Firefox is present
run: firefox --version
- name: Checkout
uses: actions/checkout@v1
- name: Fix ssh+git access for public submodules
run: git config --global url."https://github.com/".insteadOf "[email protected]:"
- name: Checkout submodules
run: git submodule update --init --recursive
- name: Cache Dependencies
uses: actions/cache@v2
with:
path: |
node_modules
package-lock.json
packages/*/node_modules
key: ${{ runner.os }}-${{ hashFiles('**/package.json') }}
- run: npm install
- run: npm run build:debug
- run: npm run build:prod
- name: Local integration tests using Headless Chrome
run: npm run test:integration:local:_execute
- name: Local integration tests using Firefox
run: npm run test:integration:local:headlessFirefox:_execute
2 changes: 0 additions & 2 deletions integration-tests/utils/browserstack.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ limitations under the License.
*/

const path = require('path');
const { getCurrentBuildId } = require('./buildApi');

console.log('Loading config.');
if (!process.env.BROWSERSTACK_USER || !process.env.BROWSERSTACK_KEY) {
Expand Down Expand Up @@ -57,7 +56,6 @@ const nightwatch_config = {

// metadata for grouping sessions in browserstack
project: require('../../package.json').name,
build: getCurrentBuildId(),
},
globals: {
host: 'bs-local.com',
Expand Down
57 changes: 30 additions & 27 deletions integration-tests/utils/browserstack.runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ require('dotenv').config();
const Nightwatch = require('nightwatch');
const browserstack = require('browserstack-local');
const { clearBuildId, generateBuildId } = require('./buildApi');
const path = require('path');

let browserstackLocal;

function createTunnel() {
function generateHex(length) {
return [...Array(length).keys()].map(() => parseInt(Math.random() * 16).toString(16)).join('');
}

let browserstackLocal;
function createTunnel({localIdentifier}) {
return new Promise((resolve, reject) => {
Nightwatch.browserstackLocal = browserstackLocal = new browserstack.Local();

Expand All @@ -32,7 +35,11 @@ function createTunnel() {
throw new Error('You need to provide environment variable: BROWSERSTACK_KEY.');
}

browserstackLocal.start({ key }, function(error) {
browserstackLocal.start({
key,
verbose: true,
localIdentifier,
}, function(error) {
if (error) {
reject(error);
} else {
Expand All @@ -44,37 +51,31 @@ function createTunnel() {
});
}

(async function() {
async function runTests(argv) {
let buildId;
try {
buildId = generateBuildId();
console.log(`Starting build ${buildId}`);

console.log('Starting tunnel.');
const tunnelHandle = await createTunnel();
const localIdentifier = generateHex(32);
const tunnelHandle = await createTunnel({localIdentifier});
console.log('Tunnel started.');

// TODO: restructure so that we don't have to rely on a path to the config file
const configPath = path.join(__dirname, 'browserstack.conf.js');
console.log(`Loading config from ${configPath}`);

const envs = ['safari', 'edge'];
const reporters = [];
for (const env of envs) {
const runner = new Nightwatch.CliRunner({
config: configPath,
env,

// note: this can be used to scope down tests, leaving here so I don't need to search for this in the future
// test: path.join(__dirname, '..', 'tests', 'websocket', 'websockets.spec.js')
});
runner.setup();
await runner.runTests();

reporters.push(runner.testRunner);
}
const runner = new Nightwatch.CliRunner({
...argv,
// note: this can be used to scope down tests, leaving here so I don't need to search for this in the future
// test: path.join(__dirname, '..', 'tests', 'websocket', 'websockets.spec.js')
});
runner.setup({
desiredCapabilities: {
'browserstack.localIdentifier': localIdentifier,
build: generateBuildId(),
},
});
await runner.runTests();

if (reporters.some(r => r.hasTestFailures)) {
if (runner.testRunner.hasTestFailures) {
console.warn('Tests failed.');
process.exitCode = 1;
} else {
Expand All @@ -90,4 +91,6 @@ function createTunnel() {
clearBuildId();
console.log(`Finished build ${buildId}`);
}
}());
}

Nightwatch.cli(runTests);
29 changes: 1 addition & 28 deletions integration-tests/utils/buildApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,19 @@ limitations under the License.
*/

const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

const buildIdFilePath = path.join(__dirname, '..', '..', '.nightwatch_build_id');

function sanitizeCliOut(out) {
return out.toString().replace(/\n/g, '');
}

function generateBuildId() {
if (fs.existsSync(buildIdFilePath)) {
console.warn('Build ID file already exists. Please remove the existing file, before requesting a new ID.');
}

const commitId = process.env.CIRCLE_SHA1 || sanitizeCliOut(execSync('git rev-parse HEAD'));
const author = process.env.CIRCLE_PR_USERNAME || sanitizeCliOut(execSync('whoami'));
const when = new Date().toJSON();

const buildId = `${author}-${when}-${commitId.substring(0, 8)}`;
fs.writeFileSync(buildIdFilePath, buildId);

return buildId;
}

function getCurrentBuildId() {
if (!fs.existsSync(buildIdFilePath)) {
throw new Error('Build ID file does not exist.');
}

return fs.readFileSync(buildIdFilePath).toString();
}

function clearBuildId() {
if (fs.existsSync(buildIdFilePath)) {
fs.unlinkSync(buildIdFilePath);
}
return `${author}-${when}-${commitId.substring(0, 8)}`;
}

module.exports = {
generateBuildId,
getCurrentBuildId,
clearBuildId,
};
10 changes: 10 additions & 0 deletions integration-tests/utils/local.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const nightwatch_config = {
start_session: false,
server_path: seleniumServer.path,
port: 9515,
check_process_delay: 5000,
cli_args: {
'webdriver.chrome.driver': chromeDriver.path,
'webdriver.gecko.driver': geckoDriver.path,
Expand Down Expand Up @@ -71,6 +72,15 @@ const nightwatch_config = {
marionette: true,
}
},
headlessFirefox: {
desiredCapabilities: {
browserName: 'firefox',
marionette: true,
'moz:firefoxOptions': {
'args': ['--headless']
},
}
},
safari: {
webdriver: {
use_legacy_jsonwire: false,
Expand Down
45 changes: 24 additions & 21 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
// Karma configuration
// Generated on Thu Jun 04 2020 09:56:24 GMT-0400 (Eastern Daylight Time)
/*
Copyright 2020 Splunk Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

const json = require('@rollup/plugin-json');
const alias = require('@rollup/plugin-alias');
const commonjs = require('@rollup/plugin-commonjs');
const typescript = require('rollup-plugin-typescript2');
const resolve = require('@rollup/plugin-node-resolve');
const istanbulrollup = require('rollup-plugin-istanbul');
const rollupPolyfills = require('rollup-plugin-node-polyfills');
const path = require('path');

const rollupHelpers = require('./rollup.helpers');

process.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function (config) {
config.set({

Expand Down Expand Up @@ -57,22 +75,9 @@ module.exports = function (config) {
'test/index.js'
],


// list of files / patterns to exclude
exclude: [],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,

Expand All @@ -90,9 +95,8 @@ module.exports = function (config) {
autoWatch: false,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// start these browsers - might be using Puppeteer
browsers: ['ChromeHeadless'],


// Continuous Integration mode
Expand Down Expand Up @@ -145,8 +149,7 @@ module.exports = function (config) {
},
},

reporters: ['spec', 'coverage-istanbul'],
preprocessors: {'test/index.js': ['rollup']}

reporters: ['progress', 'spec', 'coverage-istanbul'],
preprocessors: {'test/index.js': ['rollup']},
});
};
Loading

0 comments on commit a63a3e9

Please sign in to comment.