From 83a5efe83a5e1e22684bd54bd175d3c2dc67861f Mon Sep 17 00:00:00 2001 From: fortmarek Date: Fri, 2 Sep 2022 12:00:04 +0200 Subject: [PATCH] Add verdaccio --- .circleci/verdaccio/.gitignore | 1 + .circleci/verdaccio/config.yml | 27 ++++++++++++++++++++ .npmrc | 1 + scripts/run-ci-e2e-tests.js | 45 +++++++++++++++++++++++++++++----- scripts/wait-for-verdaccio.js | 21 ++++++++++++++++ 5 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 .circleci/verdaccio/.gitignore create mode 100644 .circleci/verdaccio/config.yml create mode 100644 .npmrc create mode 100644 scripts/wait-for-verdaccio.js diff --git a/.circleci/verdaccio/.gitignore b/.circleci/verdaccio/.gitignore new file mode 100644 index 00000000000000..dbca33e9d54aff --- /dev/null +++ b/.circleci/verdaccio/.gitignore @@ -0,0 +1 @@ +/storage diff --git a/.circleci/verdaccio/config.yml b/.circleci/verdaccio/config.yml new file mode 100644 index 00000000000000..6309a4660c8763 --- /dev/null +++ b/.circleci/verdaccio/config.yml @@ -0,0 +1,27 @@ +storage: ./storage +auth: + htpasswd: + file: ./htpasswd +uplinks: + npmjs: + url: https://registry.npmjs.org/ + max_fails: 40 + maxage: 30m + timeout: 60s + fail_timeout: 10m + cache: false + agent_options: + keepAlive: true + maxSockets: 40 + maxFreeSockets: 10 +packages: + '@*/*': + access: $all + publish: $all + proxy: npmjs + '**': + access: $all + publish: $all + proxy: npmjs +logs: + - {type: file, path: verdaccio.log, format: pretty, level: debug} diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000000000..cc3be8da00f75e --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +//localhost:4873/:_authToken="secretToken" diff --git a/scripts/run-ci-e2e-tests.js b/scripts/run-ci-e2e-tests.js index 177cb102339a72..9fda1c83dfcf98 100644 --- a/scripts/run-ci-e2e-tests.js +++ b/scripts/run-ci-e2e-tests.js @@ -20,9 +20,10 @@ */ const {cd, cp, echo, exec, exit, mv, rm} = require('shelljs'); -const spawn = require('child_process').spawn; +const child_process = require('child_process'); const argv = require('yargs').argv; const path = require('path'); +const fs = require('fs'); const SCRIPTS = __dirname; const ROOT = path.normalize(path.join(__dirname, '..')); @@ -35,6 +36,7 @@ const REACT_NATIVE_APP_DIR = `${REACT_NATIVE_TEMP_DIR}/template`; const numberOfRetries = argv.retries || 1; let SERVER_PID; let APPIUM_PID; +let VERDACCIO_PID; let exitCode; function describe(message) { @@ -70,6 +72,27 @@ try { const REACT_NATIVE_PACKAGE = path.join(ROOT, 'react-native-*.tgz'); + describe('Verdaccio'); + const verdaccioProcess = child_process.spawn( + 'npx', + ['verdaccio', '--config', './.circleci/verdaccio/config.yml'], + { + stdio: 'inherit', + }, + ); + VERDACCIO_PID = verdaccioProcess.pid; + exec('npm set registry http://localhost:4873'); + + exec('node ./scripts/wait-for-verdaccio.js'); + + echo('Publish packages'); + const packages = fs.readdirSync('packages'); + packages.forEach(current_package => { + exec( + `cd packages/${current_package} && npm publish --registry http://localhost:4873 --yes --access public`, + ); + }); + describe('Scaffold a basic React Native app from template'); exec(`rsync -a ${ROOT}/template ${REACT_NATIVE_TEMP_DIR}`); cd(REACT_NATIVE_APP_DIR); @@ -144,7 +167,9 @@ try { } describe(`Start appium server, ${APPIUM_PID}`); - const appiumProcess = spawn('node', ['./node_modules/.bin/appium']); + const appiumProcess = child_process.spawn('node', [ + './node_modules/.bin/appium', + ]); APPIUM_PID = appiumProcess.pid; describe('Build the app'); @@ -156,9 +181,13 @@ try { describe(`Start Metro, ${SERVER_PID}`); // shelljs exec('', {async: true}) does not emit stdout events, so we rely on good old spawn - const packagerProcess = spawn('yarn', ['start', '--max-workers 1'], { - env: process.env, - }); + const packagerProcess = child_process.spawn( + 'yarn', + ['start', '--max-workers 1'], + { + env: process.env, + }, + ); SERVER_PID = packagerProcess.pid; // wait a bit to allow packager to startup exec('sleep 15s'); @@ -185,7 +214,7 @@ try { const packagerEnv = Object.create(process.env); packagerEnv.REACT_NATIVE_MAX_WORKERS = 1; describe('Start Metro'); - const packagerProcess = spawn('yarn', ['start'], { + const packagerProcess = child_process.spawn('yarn', ['start'], { stdio: 'inherit', env: packagerEnv, }); @@ -288,5 +317,9 @@ try { echo(`Killing appium ${APPIUM_PID}`); exec(`kill -9 ${APPIUM_PID}`); } + if (VERDACCIO_PID) { + echo(`Killing verdaccio ${VERDACCIO_PID}`); + exec(`kill -9 ${VERDACCIO_PID}`); + } } exit(exitCode); diff --git a/scripts/wait-for-verdaccio.js b/scripts/wait-for-verdaccio.js new file mode 100644 index 00000000000000..6b0bb3c77033cf --- /dev/null +++ b/scripts/wait-for-verdaccio.js @@ -0,0 +1,21 @@ +#!/usr/bin/env node +// @ts-check + +const http = require('http'); + +function queryForServerStatus() { + + http.get('http://localhost:4873', res => { + console.log(`Server status: ${res.statusCode}`); + if (res.statusCode !== 200) { + setTimeout(queryForServerStatus, 2000); + } + }).on('error', err => { + console.log(err.name, err.stack, err.message); + setTimeout(queryForServerStatus, 2000); + }); +} + +console.log('Waiting for verdaccio instance to respond...'); + +queryForServerStatus(); \ No newline at end of file