From 614a1f3f36ca8666ecf1e26ee828a5dd1e0e04c2 Mon Sep 17 00:00:00 2001 From: Luca Greco Date: Thu, 21 Jan 2021 13:20:11 +0100 Subject: [PATCH] chore(ci): Migrate CI jobs to circleci (#256) --- .circleci/config.yml | 170 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 39 --------- CONTRIBUTING.md | 2 +- Gruntfile.js | 7 -- README.md | 7 +- package.json | 4 +- test/integration/setup.js | 15 +++- 7 files changed, 192 insertions(+), 52 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 .travis.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..a2b411d --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,170 @@ +# These environment variables must be set in CircleCI UI +# +# NPM_TOKEN - A valid NPM token for releases +# +# NOTE: +# - to validate changes to this file locally using the circleci CLI tool: +# +# circleci config process .circleci/config.yml +# +# - to try run jobs locally: +# +# circleci config process .circleci/config.yml > tmp/processed.yml +# circleci local execute -c tmp/processed.yml --job build-nodejs-current +# +version: 2.1 + +references: + nodejs_current: &nodejs_current "10" + repo_path: &repo_path ~/webextension-polyfill + defaults: &defaults + working_directory: *repo_path + parameters: + nodejs_current: + type: string + default: *nodejs_current + +commands: + run_npm_install: + description: install npm dependencies + steps: + - run: npm i + + run_npm_build: + description: build project in << parameters.node_env >> mode + parameters: + node_env: + type: enum + default: production + enum: ["production", "test"] + steps: + - run: + command: npm run build --if-present + environment: + NODE_ENV: << parameters.node_env >> + + run_test_minified: + description: rerun unit tests on minified file + steps: + - run: + command: npm run test-minified + + run_test_bundlers: + description: rerun unit tests on webpack and browserify bundled files + steps: + - configure_global_npm + - run: npm install -g browserify webpack webpack-cli + - run: | + export PATH=$PATH:../.npm-global/bin + node ./scripts/run-module-bundlers-smoketests.js + + run_xephyr: + description: run Xephyr on DISPLAY=:10 + steps: + - run: | + sudo apt install xserver-xephyr + Xephyr -ac -br -noreset -screen 1280x1024x24 :10 & + sleep 2 + + run_functional_tests: + description: run integration tests on Firefox and Chrome browsers + steps: + # circleci browsers image variant does include and run Xvfb + # unfortunately Chrome seems to intermittently fail to connect + # to it successfully: + # + # ERROR:browser_main_loop.cc(1434)] Unable to open X display + # + # On the contrary it seems to don't happen with Xephyr. + - run_xephyr + - run: + command: node ./scripts/run-browsers-smoketests.js + environment: + DISPLAY: :10.0 + CHROMEDRIVER_VERBOSE_LOGFILE: /tmp/chromedriver.log + - store_artifacts: + # chromedriver verbose logs stored in the artifacts to make + # it easier investigate CI jobs chromedriver issues. + path: /tmp/chromedriver.log + run_tests: + description: run tests + steps: + - run: + name: run linting check and unit tests with coverage + command: npm run test-coverage + - store_artifacts: + path: coverage + - run: + name: publish coverage data + command: npm run publish-coverage + - run_test_minified + - run_test_bundlers + - run_functional_tests + + # This is required to avoid a `EACCES` when running `npm install -g` (which is + # executed in the test suite). + configure_global_npm: + description: create custom directory for global npm installs + steps: + - run: mkdir ../.npm-global + - run: npm config set prefix '../.npm-global' + + attach_project_repo: + description: attach repo from workspace + steps: + - attach_workspace: + at: *repo_path + + persist_project_repo: + description: persist repo in workspace + steps: + - persist_to_workspace: + root: *repo_path + paths: . + +jobs: + build: + <<: *defaults + docker: + # Image variant including Firefox, Chrome and Xvfb + - image: circleci/node:<< parameters.nodejs_current >>-browsers + steps: + - attach_project_repo + - checkout + - run_npm_install + - run_npm_build: + node_env: test + - run_tests + - persist_project_repo + + release-tag: + <<: *defaults + docker: + - image: circleci/node:<< parameters.nodejs_current >> + steps: + - attach_project_repo + - run_npm_build: + node_env: production + - run: + name: npm registry auth + command: echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > .npmrc + - run: + name: npm registry publish + command: npm publish + +workflows: + default-workflow: + jobs: + - build: + name: build-nodejs-current + filters: + tags: + only: /.*/ + - release-tag: + requires: + - build-nodejs-current + filters: + tags: + only: /.*/ + branches: + ignore: /.*/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8dd8f15..0000000 --- a/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ -language: node_js -node_js: -## Some of the ES6 syntax used in the browser-polyfill sources is only supported on nodejs >= 6 -## and the selenium-webdriver dependency used by the integration tests requires nodejs >= 8. -## and the chromedriver dependency requires Node >= 10. -- '10' - -script: -- npm run build -- npm run test-coverage -- echo "RE-RUN tests on the minified file" && npm run test-minified -- echo "RE-RUN tests on the webpack and browserify bundled files" && - npm install -g browserify webpack webpack-cli && - node ./scripts/run-module-bundlers-smoketests.js -- export DISPLAY=:99.0 -- echo "RUN integration tests on real browsers" && - TRAVIS_CI=true node ./scripts/run-browsers-smoketests.js - -## See https://docs.travis-ci.com/user/chrome -sudo: required - -addons: - firefox: 'latest' - chrome: 'stable' - -services: ["xvfb"] - -after_script: npm run publish-coverage - -deploy: - provider: npm - email: addons-dev-automation+npm@mozilla.com - skip_cleanup: true - on: - tags: true - repo: mozilla/webextension-polyfill - branch: master - api_key: - secure: K4rZPsnERK4hiVJICp2MGjLSiL64AeDc0yxmr54/ZlbAYy5OhtDrtaZ0L65eGx+HuIgVQbduSNn1zBN/Bx7w8zmYVyXdTVD1HqXuopS+vmBTrwW/d28uKdpCcMo311ODbk//AL3ylTCeOMkSsLsbb5Io6zcEpuw0VLtSNSrytaA85vcUIj2l8iurLrThN3r7iIsIEHceCzDo3KDx/o4yh7cEKs0FP9Jl8A6jm8sTt/j3jLmsxFFXp/SWOvPCQFX1hCu2uLgCtoLbFJlaDq2+RzsEXv4K5Ee5coVtc4vLRiNjC1UP7cHqfN8VZ0I2LeVT79MRmLqRAccGCSMdarFgoA2SW1laNch0vXy6hBSluh+OVJVPDrz7Xdyy70rt+57tJYFCtpZ24E6X+GNyOOMYfIsatvv59h5R6vE3hWvNZVtiOhYw9wMrKBA9rLkzyoCXeEVu4BuU834RbeeYUAg9VR6WZ1U2nD4IxGr33mSPDqsA6tOhr7tM0kEmg2eVe8qHop8BRtUAhQfkY6C+kfRkPE0OZBq4kiWcfugRJyKI7rAp9T5JNUSLW5X1KrvRv0RBaDr8SKFaWHE4N5Dbt/u2zluq+wJn/n5IxvEFDHSAzxLWBDz+LsmZ1eXRdfA+Pu4cyIKjMX1O8yPAnX8RCTc9oq8Qj74l5rXzCJtmygRdf2I= diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d1f85bd..a4e1ecf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -63,7 +63,7 @@ The integration tests use selenium-webdriver to run a set of test extensions supported by this library) and Firefox (to compare the polyfilled APIs with the ones natively provided on Firefox). -The shell script `test/run-browsers-smoketests.sh` (executed by the Travis CI service on every +The shell script `test/run-browsers-smoketests.sh` (executed by the CI service on every pull request) runs this test suite on both the browsers. To run the integration tests on a single browser: diff --git a/Gruntfile.js b/Gruntfile.js index c3b34e0..280ef66 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -12,12 +12,6 @@ module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON("package.json"), - coveralls: { - all: { - src: "coverage/lcov.info", - }, - }, - eslint: { src: ["src/browser-polyfill.js", "Gruntfile.js"], test: ["test/**/*.js", "scripts/**/*.js"], @@ -99,7 +93,6 @@ module.exports = function(grunt) { grunt.loadNpmTasks("gruntify-eslint"); grunt.loadNpmTasks("grunt-replace"); - grunt.loadNpmTasks("grunt-coveralls"); grunt.loadNpmTasks("grunt-contrib-concat"); grunt.loadNpmTasks("grunt-babel"); diff --git a/README.md b/README.md index 4b0260d..bdc1a87 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,13 @@ -# WebExtension `browser` API Polyfill [![Build Status](https://travis-ci.org/mozilla/webextension-polyfill.svg?branch=master)](https://travis-ci.org/mozilla/webextension-polyfill) [![npm version](https://badge.fury.io/js/webextension-polyfill.svg)](https://www.npmjs.com/package/webextension-polyfill) +# WebExtension `browser` API Polyfill This library allows extensions that use the Promise-based WebExtension/BrowserExt API being standardized by the [W3 Browser Extensions][w3-browserext] group to run on Google Chrome with minimal or no changes. +[![CircleCI](https://circleci.com/gh/mozilla/webextension-polyfill.svg?style=svg)](https://circleci.com/gh/mozilla/webextension-polyfill) +[![codecov](https://codecov.io/gh/mozilla/webextension-polyfill/branch/master/graph/badge.svg)](https://codecov.io/gh/mozilla/webextension-polyfill) +[![devDependency Status](https://david-dm.org/mozilla/webextension-polyfill/dev-status.svg)](https://david-dm.org/mozilla/webextension-polyfill#info=devDependencies) +[![npm version](https://badge.fury.io/js/webextension-polyfill.svg)](https://badge.fury.io/js/webextension-polyfill) + > This library doesn't (and it is not going to) polyfill API methods or options that are missing on Chrome but natively provided > on Firefox, and so the extension has to do its own "runtime feature detection" in those cases (and then eventually polyfill the > missing feature on its own or enable/disable some of the features accordingly). diff --git a/package.json b/package.json index 871b00d..609df54 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "browserify": "^16.2.2", "chai": "^4.2.0", "chromedriver": "^87.0.2", + "codecov": "^3.8.1", "cross-env": "^6.0.3", "eslint": "^6.6.0", "finalhandler": "^1.1.0", @@ -34,7 +35,6 @@ "grunt": "^1.0.1", "grunt-babel": "^8.0.0", "grunt-contrib-concat": "^1.0.1", - "grunt-coveralls": "^2.0.0", "grunt-replace": "^1.0.1", "gruntify-eslint": "^5.0.0", "istanbul-lib-instrument": "^3.3.0", @@ -61,7 +61,7 @@ "scripts": { "build": "grunt", "prepublish": "npm run build && npm run test", - "publish-coverage": "grunt coveralls", + "publish-coverage": "codecov", "test": "mocha", "test-coverage": "cross-env COVERAGE=y nyc mocha", "test-minified": "cross-env TEST_MINIFIED_POLYFILL=1 mocha", diff --git a/test/integration/setup.js b/test/integration/setup.js index 40af6c1..d658def 100644 --- a/test/integration/setup.js +++ b/test/integration/setup.js @@ -34,7 +34,7 @@ const launchBrowser = async (launchOptions) => { const options = new chrome.Options(); options.addArguments([ `--load-extension=${extensionPath}`, - // See https://docs.travis-ci.com/user/chrome and issue #85 for a rationale. + // See issue #85 for a rationale. "--no-sandbox", ]); @@ -49,10 +49,21 @@ const launchBrowser = async (launchOptions) => { ]); } + const service = new chrome.ServiceBuilder(chromedriver.path); + + if (process.env.CHROMEDRIVER_VERBOSE_LOGFILE) { + // Prevent intermittent failures due to limited resources while running + // in small VMs / docker containers (See #256 for a rationale). + const logsPath = process.env.CHROMEDRIVER_VERBOSE_LOGFILE; + console.warn(`NOTE: Verbose chromedriver logs: ${logsPath}`); + service.loggingTo(logsPath); + service.enableVerboseLogging(); + } + driver = await new Builder() .forBrowser("chrome") .setChromeOptions(options) - .setChromeService(new chrome.ServiceBuilder(chromedriver.path)) + .setChromeService(service) .build(); } else if (browser === "firefox") { const firefox = require("selenium-webdriver/firefox");