Skip to content
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

Add Windows CI job (Node 12) #3376

Merged
merged 2 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
7 changes: 6 additions & 1 deletion scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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
Expand Down
11 changes: 9 additions & 2 deletions scripts/e2e.npm.publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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'

Expand Down
25 changes: 25 additions & 0 deletions scripts/e2e.windows.sh
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -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
92 changes: 92 additions & 0 deletions scripts/js/basic_usage.js
Original file line number Diff line number Diff line change
@@ -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)
});

4 changes: 2 additions & 2 deletions verdaccio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down