From 0479ce3492dbf1988ec38d0886f5b3513a14e878 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Mon, 17 Feb 2020 14:09:53 -0800 Subject: [PATCH] Add Windows CI job (Node 12) --- .travis.yml | 21 +++++---- scripts/ci.sh | 7 ++- scripts/e2e.npm.publish.sh | 11 ++++- scripts/e2e.windows.sh | 25 +++++++++++ scripts/install.sh | 15 +++++++ scripts/js/basic_usage.js | 92 ++++++++++++++++++++++++++++++++++++++ verdaccio.yml | 4 +- 7 files changed, 161 insertions(+), 14 deletions(-) create mode 100755 scripts/e2e.windows.sh create mode 100755 scripts/install.sh create mode 100644 scripts/js/basic_usage.js diff --git a/.travis.yml b/.travis.yml index 17307599971..ee957662d1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,10 +16,13 @@ matrix: env: TEST=build_and_lint - node_js: 10 env: TEST=unit_and_e2e_clients - - node_js: 10 + - node_js: 12 env: TEST=e2e_ganache - - node_js: 10 + - node_js: 12 env: TEST=e2e_mosaic + - node_js: 12 + env: TEST=e2e_windows + os: windows - node_js: 10 env: TEST=e2e_ens - node_js: 10 @@ -28,10 +31,13 @@ matrix: chrome: stable firefox: latest allow_failures: - - node_js: 10 + - node_js: 12 env: TEST=e2e_ganache - - node_js: 10 + - node_js: 12 env: TEST=e2e_mosaic + - node_js: 12 + env: TEST=e2e_windows + os: windows addons: apt: @@ -51,9 +57,6 @@ before_install: - export DISPLAY=:99.0 - export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true install: - - if [[ $TEST != "e2e_ganache" ]] && [[ $TEST != "e2e_mosaic" ]]; then - npm install; - fi + - bash ./scripts/install.sh script: - - npm run ci - + - bash ./scripts/ci.sh diff --git a/scripts/ci.sh b/scripts/ci.sh index 2bee77af154..0a84f2f36ec 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -47,7 +47,12 @@ elif [ "$TEST" = "e2e_mosaic" ]; then elif [ "$TEST" = "e2e_ens" ]; then npm run test:e2e:ens - + +elif [ "$TEST" = "e2e_windows" ]; then + + bash ./scripts/e2e.npm.publish.sh + bash ./scripts/e2e.windows.sh + elif [ "$TEST" = "e2e_ganache" ]; then npm run test:e2e:publish diff --git a/scripts/e2e.npm.publish.sh b/scripts/e2e.npm.publish.sh index a05082a0444..3a8a703a431 100755 --- a/scripts/e2e.npm.publish.sh +++ b/scripts/e2e.npm.publish.sh @@ -25,8 +25,12 @@ npm install -g verdaccio@4.4.2 npm install -g npm-auth-to-token@1.0.0 npm install -g lerna@3.18.3 -# Launch npm proxy registry -verdaccio --config verdaccio.yml & npx wait-port 4873 +# Launch npm proxy registry and save pid to kill server (req. in Windows env) +verdaccio --config verdaccio.yml & +VERDACCIO_PID=$! +echo "VERDACCIO_PID=$VERDACCIO_PID" > verdaccio_pid + +npx wait-port 4873 # `npm add user` curl -XPUT \ @@ -59,6 +63,9 @@ lerna version minor \ --allow-branch $BRANCH \ --yes +# Set email prior to publishing (necessary for Windows) +git config user.email "you@example.com" + # Commit changes because lerna checks git before git commit -a -m 'virtual-version-bump' diff --git a/scripts/e2e.windows.sh b/scripts/e2e.windows.sh new file mode 100755 index 00000000000..740ba63630f --- /dev/null +++ b/scripts/e2e.windows.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# This script installs Web3 from virtual registry in a +# Windows env and runs some simple Web3 calls. + +# Exit immediately on error +set -o errexit + +# Setup mock project to install web3 from virtual registry +mkdir windows_test +cp scripts/js/basic_usage.js windows_test/basic_usage.js +cd windows_test + +# Install web3 as dep +npm init --yes +npm install web3@e2e --save --registry http://localhost:4873 +node ./basic_usage.js + +# Shutdown verdaccio server +cd .. +source verdaccio_pid +kill -9 $VERDACCIO_PID + +# Debugging... +ps -ef diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 00000000000..0d7943f5610 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# This script contains conditional installation logic for Travis CI + +# CI jobs we'd like to skip default installation for: +# Helpful for E2E tests where the dev deps might cause problems +skip=( + "e2e_ganache" + "e2e_mosaic" + "e2e_windows" +) + +if [[ ! " ${skip[@]} " =~ " ${TEST} " ]]; then + npm install +fi diff --git a/scripts/js/basic_usage.js b/scripts/js/basic_usage.js new file mode 100644 index 00000000000..9d33bc85ed9 --- /dev/null +++ b/scripts/js/basic_usage.js @@ -0,0 +1,92 @@ +#!/usr/bin/env node + +// This script runs some simple Web3 calls. +// Useful for validating the published version in different OS environments. +const Web3 = require('web3'); +const util = require('util'); +const log = console.log; + +async function delay(secs=0){ + return new Promise(resolve => setTimeout(() => resolve(), secs * 1000)) +} + +// A workaround for how flaky the infura connection can be... +// Tries to fetch data 10x w/ 1 sec delays. Exits on first success. +async function getBlockWithRetry(web3){ + let i = 0; + let block; + + while(true){ + await delay(1); + + try { + + block = await web3.eth.getBlock('latest'); + break; + + } catch(err){ + + i++; + if (i === 10){ + throw new Error('Failed to connect to Infura over websockets after 10 tries'); + } + + } + } + return block; +} + +async function main(){ + let web3; + let block; + + // Providers + log(); + log('>>>>>>'); + log('HTTP:MAINNET getBlock'); + log('>>>>>>'); + + // Http + web3 = new Web3('https://mainnet.infura.io/v3/1d13168ffb894ad2827f2152620bd27c'); + block = await getBlockWithRetry(web3); + log(util.inspect(block)); + + log(); + log('>>>>>>'); + log('WS:MAINNET getBlock'); + log('>>>>>>'); + + // WebSockets + web3 = new Web3('wss://mainnet.infura.io/ws/v3/1d13168ffb894ad2827f2152620bd27c'); + block = await getBlockWithRetry(web3); + web3.currentProvider.disconnect(); + log(util.inspect(block)); + + + // Accounts + web3 = new Web3(); + + log(); + log('>>>>>>'); + log('eth.accounts.createAccount'); + log('>>>>>>'); + + const account = web3.eth.accounts.create(); + log(util.inspect(account)); + + log(); + log('>>>>>>'); + log('eth.accounts.hashMessage'); + log('>>>>>>'); + + const hash = web3.eth.accounts.hashMessage('Hello World'); + log(util.inspect(hash)); +} + +main() + .then(() => process.exit(0)) + .catch(err => { + log(err); + process.exit(1) + }); + diff --git a/verdaccio.yml b/verdaccio.yml index 78daa76841d..066ade8ec2e 100644 --- a/verdaccio.yml +++ b/verdaccio.yml @@ -5,10 +5,10 @@ auth: uplinks: npmjs: url: https://registry.npmjs.org/ - timeout: 25000ms + timeout: 100000ms yarn: url: https://registry.yarnpkg.com/ - timeout: 25000ms + timeout: 100000ms packages: '@*/*': # scoped packages