From 4927b02771a0da9671d8e4a1b7fcde68d388bfa0 Mon Sep 17 00:00:00 2001 From: Hector Ramos Date: Tue, 6 Feb 2018 11:37:20 -0800 Subject: [PATCH 1/2] Switch e2e to yarn --- .circleci/config.yml | 74 +++++++++++++++++++++---------------- .gitignore | 3 ++ scripts/run-ci-e2e-tests.js | 18 ++++----- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 50cbeb3a41fbba..a127b614f4352d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -112,7 +112,8 @@ aliases: sudo apt-get install -y nodejs - &create-ndk-directory - | + name: Create Android NDK Directory + command: | if [[ ! -e /opt/ndk ]]; then sudo mkdir /opt/ndk fi @@ -121,7 +122,8 @@ aliases: # CircleCI does not support interpolating env variables in the environment # https://circleci.com/docs/2.0/env-vars/#interpolating-environment-variables-to-set-other-environment-variables - &configure-android-path - | + name: Configure Environment Variables + command: | echo 'export PATH=${ANDROID_NDK}:~/react-native/gradle-2.9/bin:~/buck/bin:$PATH' >> $BASH_ENV source $BASH_ENV @@ -129,8 +131,9 @@ aliases: | source scripts/circle-ci-android-setup.sh && getAndroidSDK - - &install-build-dependencies - | + - &install-android-build-dependencies + name: Install Android Build Dependencies + command: | sudo apt-get update -y sudo apt-get install ant autoconf automake g++ gcc libqt5widgets5 lib32z1 lib32stdc++6 make maven python-dev python3-dev qml-module-qtquick-controls qtdeclarative5-dev file -y @@ -171,7 +174,6 @@ aliases: - &build-js-bundle name: Build JavaScript Bundle command: node local-cli/cli.js bundle --max-workers 2 --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js - when: always - &compile-native-libs name: Compile Native Libs for Unit and Integration Tests @@ -184,7 +186,11 @@ aliases: - &run-android-instrumentation-tests name: Run Instrumentation Tests - command: source scripts/circle-ci-android-setup.sh && NO_BUCKD=1 retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS + command: | + if [[ ! -e ReactAndroid/src/androidTest/assets/AndroidTestBundle.js ]]; then + echo "JavaScript bundle missing, cannot run instrumentation tests. Verify build-js-bundle step completed successfully."; exit 1; + fi + source scripts/circle-ci-android-setup.sh && NO_BUCKD=1 retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS - &collect-android-test-results name: Collect Test Results @@ -235,7 +241,7 @@ version: 2 jobs: # Runs JavaScript lint and flow checks. # Currently will fail a PR if lint/flow raises issues. - run-js-checks: + js-checks: <<: *defaults docker: - image: circleci/node:8 @@ -256,7 +262,7 @@ jobs: path: ~/reports/junit # Runs JavaScript tests on Node 8 - test-js-node-8: + js-node-8: <<: *defaults docker: - image: circleci/node:8 @@ -276,7 +282,7 @@ jobs: path: ~/reports/junit # Runs JavaScript tests on Node 6 - test-js-node-6: + js-node-6: <<: *defaults docker: - image: circleci/node:6 @@ -296,7 +302,7 @@ jobs: path: ~/reports/junit # Runs unit tests on iOS devices - test-objc-ios: + objc-ios: <<: *defaults macos: xcode: "9.0" @@ -319,7 +325,7 @@ jobs: path: ~/reports/junit # Runs unit tests on tvOS devices - test-objc-tvos: + objc-tvos: <<: *defaults macos: xcode: "9.0" @@ -342,7 +348,7 @@ jobs: path: ~/reports/junit # Runs end to end tests - test-e2e-objc-ios: + objc-ios-e2e: <<: *defaults macos: xcode: "9.0" @@ -387,7 +393,7 @@ jobs: # Configure Android dependencies - run: *configure-android-path - - run: *install-build-dependencies + - run: *install-android-build-dependencies - restore-cache: *restore-cache-android-packages - run: *install-android-packages - save-cache: *save-cache-android-packages @@ -424,15 +430,15 @@ jobs: fi # Runs unit tests tests on Android - test-android: + android: <<: *android_defaults steps: - checkout - run: *setup-artifacts - # Configure Android dependencies + # Configure Android SDK and related dependencies - run: *configure-android-path - - run: *install-build-dependencies + - run: *install-android-build-dependencies - restore-cache: *restore-cache-android-packages - run: *install-android-packages - save-cache: *save-cache-android-packages @@ -442,11 +448,8 @@ jobs: - run: *launch-avd # Keep configuring Android dependencies while AVD boots up - - run: *create-ndk-directory - - restore-cache: *restore-cache-ndk - - run: *install-ndk - - save-cache: *save-cache-ndk + # Fetch dependencies using BUCK - restore-cache: *restore-cache-buck - run: *install-buck - save-cache: *save-cache-buck @@ -458,10 +461,17 @@ jobs: - run: buck fetch ReactAndroid/src/androidTest/... - run: ./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog :ReactAndroid:downloadJSCHeaders + # Install Android NDK + - run: *create-ndk-directory + - restore-cache: *restore-cache-ndk + - run: *install-ndk + - save-cache: *save-cache-ndk + + # Build and compile - run: *build-android-app - run: *compile-native-libs - # The JavaScript Bundle is required for instrumentation tests. + # Build JavaScript Bundle for instrumentation tests - run: *install-node - run: *install-yarn - restore-cache: *restore-yarn-cache @@ -472,7 +482,7 @@ jobs: # Wait for AVD to finish booting before running tests - run: *wait-for-avd - # Tests + # Test Suite - run: *run-android-unit-tests - run: *run-android-instrumentation-tests @@ -533,31 +543,31 @@ workflows: jobs: # Run lint and flow checks - - run-js-checks: + - js-checks: filters: *filter-ignore-gh-pages # Test JavaScript on Node 8 and 6 - - test-js-node-8: + - js-node-8: filters: *filter-ignore-gh-pages - - test-js-node-6: + - js-node-6: filters: *filter-ignore-gh-pages # Test Android - - test-android: + - android: filters: *filter-ignore-gh-pages # Test iOS & tvOS - - test-objc-ios: + - objc-ios: filters: *filter-ignore-gh-pages - - test-objc-tvos: + - objc-tvos: filters: *filter-ignore-gh-pages # End-to-end tests - - test-e2e-objc-ios: + - objc-ios-e2e: filters: *filter-ignore-gh-pages requires: - - test-objc-ios - - test-js-node-8 + - objc-ios + - js-node-8 # If we are on a stable branch, deploy to `npm` - hold: @@ -568,4 +578,4 @@ workflows: - hold - analyze-pull-request: - filters: *filter-ignore-master-stable + filters: *filter-ignore-master-stable \ No newline at end of file diff --git a/.gitignore b/.gitignore index 032f9335f905e2..19c3bbdce24975 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,9 @@ node_modules *.log .nvm /bots/node_modules/ + +# TODO: Check in yarn.lock in open source. Right now we need to keep it out +# from the GitHub repo as importing it might conflict with internal workspaces */**/yarn.lock # OS X diff --git a/scripts/run-ci-e2e-tests.js b/scripts/run-ci-e2e-tests.js index eb9bbe7c190f71..5c38ae676c3a06 100644 --- a/scripts/run-ci-e2e-tests.js +++ b/scripts/run-ci-e2e-tests.js @@ -17,7 +17,7 @@ * --android - 'react-native init' and check Android app doesn't redbox * --js - 'react-native init' and only check the packager returns a bundle * --skip-cli-install - to skip react-native-cli global installation (for local debugging) - * --retries [num] - how many times to retry possible flaky commands: npm install and running tests, default 1 + * --retries [num] - how many times to retry possible flaky commands: yarn add and running tests, default 1 */ /*eslint-disable no-undef */ require('shelljs/global'); @@ -44,12 +44,12 @@ let exitCode; try { // install CLI cd('react-native-cli'); - exec('npm pack'); + exec('yarn pack'); const CLI_PACKAGE = path.join(ROOT, 'react-native-cli', 'react-native-cli-*.tgz'); cd('..'); if (!argv['skip-cli-install']) { - if (exec(`sudo npm install -g ${CLI_PACKAGE}`).code) { + if (exec(`sudo yarn global add ${CLI_PACKAGE}`).code) { echo('Could not install react-native-cli globally.'); echo('Run with --skip-cli-install to skip this step'); exitCode = 1; @@ -65,7 +65,7 @@ try { } } - if (exec('npm pack').code) { + if (exec('yarn pack').code) { echo('Failed to pack react-native'); exitCode = 1; throw Error(exitCode); @@ -76,7 +76,7 @@ try { if (tryExecNTimes( () => { exec('sleep 10s'); - return exec(`react-native init EndToEndTest --version ${PACKAGE} --npm`).code; + return exec(`react-native init EndToEndTest --version ${PACKAGE}`).code; }, numberOfRetries, () => rm('-rf', 'EndToEndTest'))) { @@ -92,7 +92,7 @@ try { echo('Running an Android e2e test'); echo('Installing e2e framework'); if (tryExecNTimes( - () => exec('npm install --save-dev appium@1.5.1 mocha@2.4.5 wd@0.3.11 colors@1.0.3 pretty-data2@0.40.1', { silent: true }).code, + () => exec('yarn add --dev appium@1.5.1 mocha@2.4.5 wd@0.3.11 colors@1.0.3 pretty-data2@0.40.1', { silent: true }).code, numberOfRetries)) { echo('Failed to install appium'); echo('Most common reason is npm registry connectivity, try again'); @@ -125,7 +125,7 @@ try { echo(`Starting packager server, ${SERVER_PID}`); // shelljs exec('', {async: true}) does not emit stdout events, so we rely on good old spawn - const packagerProcess = spawn('npm', ['start', '--', '--max-workers 1'], { + const packagerProcess = spawn('yarn', ['start', '--max-workers 1'], { env: process.env }); SERVER_PID = packagerProcess.pid; @@ -158,7 +158,7 @@ try { // shelljs exec('', {async: true}) does not emit stdout events, so we rely on good old spawn const packagerEnv = Object.create(process.env); packagerEnv.REACT_NATIVE_MAX_WORKERS = 1; - const packagerProcess = spawn('npm', ['start', '--', '--nonPersistent'], + const packagerProcess = spawn('yarn', ['start', '--nonPersistent'], { stdio: 'inherit', env: packagerEnv @@ -204,7 +204,7 @@ try { exitCode = 1; throw Error(exitCode); } - if (exec('npm test').code) { + if (exec('yarn test').code) { echo('Jest test failure'); exitCode = 1; throw Error(exitCode); From 2fcbef67e03e120080ca607ac2e046e24fd1e78f Mon Sep 17 00:00:00 2001 From: Hector Ramos Date: Tue, 6 Feb 2018 11:48:11 -0800 Subject: [PATCH 2/2] Upload yarn.lock lockfile for debugging --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index a127b614f4352d..b9056680af6708 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -260,6 +260,8 @@ jobs: path: ~/reports/junit - store_artifacts: path: ~/reports/junit + - store_artifacts: + path: ~/react-native/yarn.lock # Runs JavaScript tests on Node 8 js-node-8: