From 87efe800bb561381687bcec046d55a13739c9547 Mon Sep 17 00:00:00 2001 From: Hector Ramos Date: Thu, 27 Sep 2018 15:09:18 -0700 Subject: [PATCH] force analysis to run --- .circleci/config.yml | 469 +++++++++++++++++-------------- bots/code-analysis-bot.js | 118 +++++--- scripts/circleci/analyze_code.sh | 9 +- 3 files changed, 336 insertions(+), 260 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1b4629a18333fc..6ee09167347c6a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,51 +28,42 @@ aliases: - &restore-cache-android-packages keys: - - v1-android-sdkmanager-packages-api-26-alpha-{{ checksum "scripts/.tests.env" }} + - v1-android-sdkmanager-packages-api-27-alpha-{{ checksum "scripts/.tests.env" }} - &save-cache-android-packages paths: - /opt/android/sdk - key: v1-android-sdkmanager-packages-api-26-alpha-{{ checksum "scripts/.tests.env" }} + key: v1-android-sdkmanager-packages-api-27-alpha-{{ checksum "scripts/.tests.env" }} - &restore-cache-gradle keys: - - v1-gradle-{{ arch }}-{{ .Branch }}-{{ checksum "build.gradle" }}-{{ checksum "ReactAndroid/build.gradle" }} + - v1-gradle-{{ .Branch }}-{{ checksum "build.gradle" }}-{{ checksum "ReactAndroid/build.gradle" }} # Fallback in case checksum fails - - v1-gradle-{{ arch }}-{{ .Branch }}-{{ checksum "build.gradle" }}- - - v1-gradle-{{ arch }}-{{ .Branch }}- + - v1-gradle-{{ .Branch }}-{{ checksum "build.gradle" }}- + - v1-gradle-{{ .Branch }}- # Fallback in case this is a first-time run on a fork - - v1-gradle-{{ arch }}-master- + - v1-gradle-master- - &save-cache-gradle paths: - ~/.gradle - key: v1-gradle-{{ arch }}-{{ .Branch }}-{{ checksum "build.gradle" }}-{{ checksum "ReactAndroid/build.gradle" }} - - - &restore-cache-apt - keys: - - v1-apt-{{ .Branch }}-{{ checksum "scripts/circleci/apt-get-android-deps.sh" }} - # Fallback in case this is a first-time run on a fork - - v1-apt-master-{{ checksum "scripts/circleci/apt-get-android-deps.sh" }} - - &save-cache-apt - paths: - - ~/vendor/apt - key: v1-apt-{{ .Branch }}-{{ checksum "scripts/circleci/apt-get-android-deps.sh" }} + key: v1-gradle-{{ .Branch }}-{{ checksum "build.gradle" }}-{{ checksum "ReactAndroid/build.gradle" }} - &restore-cache-ndk keys: - - v3-android-ndk-{{ arch }}-r10e-{{ checksum "scripts/android-setup.sh" }} + - v3-android-ndk-r17b-{{ checksum "scripts/android-setup.sh" }} - &save-cache-ndk paths: - /opt/ndk - key: v3-android-ndk-{{ arch }}-r10e-{{ checksum "scripts/android-setup.sh" }} + key: v3-android-ndk-r17b-{{ checksum "scripts/android-setup.sh" }} - - &restore-cache-buck + - &restore-cache-downloads-buck keys: - - v3-buck-{{ arch }}-v2018.03.26.01 - - &save-cache-buck + - v3-buck-v2018.07.23.01-{{ checksum "scripts/circleci/buck_fetch.sh" }}} + - v3-buck-v2018.07.23.01- + - &save-cache-downloads-buck paths: - ~/buck - ~/okbuck - key: v3-buck-{{ arch }}-v2018.03.26.01 + key: v3-buck-v2018.07.23.01-{{ checksum "scripts/circleci/buck_fetch.sh" }} - &restore-cache-watchman keys: @@ -82,16 +73,16 @@ aliases: - ~/watchman key: v1-watchman-{{ arch }}-v4.9.0 - - &restore-cache-gradle-downloads + - &restore-cache-downloads-gradle keys: - - v1-gradle-{{ arch }}-{{ checksum "ReactAndroid/build.gradle" }}-{{ checksum "scripts/circleci/gradle_download_deps.sh" }} - - v1-gradle-{{ arch }}- - - &save-cache-gradle-downloads + - v1-gradle-{{ checksum "ReactAndroid/build.gradle" }}-{{ checksum "scripts/circleci/gradle_download_deps.sh" }} + - v1-gradle- + - &save-cache-downloads-gradle paths: - ~/.gradle - ReactAndroid/build/downloads - ReactAndroid/build/third-party-ndk - key: v1-gradle-{{ arch }}-{{ checksum "ReactAndroid/build.gradle" }}-{{ checksum "scripts/circleci/gradle_download_deps.sh" }} + key: v1-gradle-{{ checksum "ReactAndroid/build.gradle" }}-{{ checksum "scripts/circleci/gradle_download_deps.sh" }} # Branch Filtering - &filter-only-master-stable @@ -122,8 +113,13 @@ aliases: command: source scripts/android-setup.sh && getAndroidNDK - &yarn - | - yarn install --non-interactive --cache-folder ~/.cache/yarn + name: Run Yarn + command: | + # Skip yarn install on metro bump commits as the package is not yet + # available on npm + if [[ $(echo "$GIT_COMMIT_DESC" | grep -c "Bump metro@") -eq 0 ]]; then + yarn install --non-interactive --cache-folder ~/.cache/yarn + fi - &install-yarn name: Install Yarn @@ -132,10 +128,6 @@ aliases: echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update && sudo apt-get install yarn - - &install-node-dependencies - | - npm install --no-package-lock --no-spin --no-progress - - &install-shellcheck name: Install ShellCheck command: sudo apt-get install -y shellcheck @@ -144,7 +136,7 @@ aliases: name: Install BUCK command: | if [[ ! -e ~/buck ]]; then - git clone https://github.com/facebook/buck.git ~/buck --branch v2018.03.26.01 --depth=1 + git clone https://github.com/facebook/buck.git ~/buck --branch v2018.07.23.01 --depth=1 fi cd ~/buck && ant buck --version @@ -155,12 +147,6 @@ aliases: mkdir -p ~/react-native/tooling/junit cp -R ~/okbuck/tooling/junit/* ~/react-native/tooling/junit/. - - &install-node - name: Install Node - command: | - curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - - sudo apt-get install -y nodejs - - &create-ndk-directory name: Create Android NDK Directory command: | @@ -174,7 +160,7 @@ aliases: - &configure-android-path name: Configure Environment Variables command: | - echo 'export PATH=${ANDROID_NDK}:~/react-native/gradle-2.9/bin:~/buck/bin:$PATH' >> $BASH_ENV + echo 'export PATH=${ANDROID_NDK}:~/buck/bin:$PATH' >> $BASH_ENV source $BASH_ENV - &install-android-packages @@ -202,12 +188,14 @@ aliases: - &run-lint-checks name: Lint code command: scripts/circleci/exec_swallow_error.sh yarn lint --format junit -o ~/react-native/reports/junit/eslint/results.xml - when: always - - &run-flow-checks - name: Check for errors in code using Flow - command: yarn flow check - when: always + - &run-flow-checks-ios + name: Check for errors in code using Flow (iOS) + command: yarn flow-check-ios + + - &run-flow-checks-android + name: Check for errors in code using Flow (Android) + command: yarn flow-check-android - &run-sanity-checks name: Sanity checks @@ -216,10 +204,14 @@ aliases: ./scripts/circleci/check_cache.sh when: always - - &gradle-download-deps - name: Download C++ Dependencies + - &download-dependencies-gradle + name: Download Dependencies Using Gradle command: ./scripts/circleci/gradle_download_deps.sh + - &download-dependencies-buck + name: Download Dependencies Using Buck + command: ./scripts/circleci/buck_fetch.sh + - &build-android-app name: Build Android App command: | @@ -260,6 +252,10 @@ aliases: fi source scripts/android-setup.sh && NO_BUCKD=1 retry3 timeout 300 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=$BUILD_THREADS + - &build-android-rntester-app + name: Build Android RNTester App + command: ./gradlew RNTester:android:app:assembleRelease -Pjobs=$BUILD_THREADS + - &collect-android-test-results name: Collect Test Results command: | @@ -277,6 +273,12 @@ aliases: mkdir -p ~/react-native/reports/junit/ mkdir -p ~/react-native/reports/outputs/ + - &brew-install-watchman + name: Install Watchman + command: | + brew install watchman + touch .watchmanconfig + - &boot-simulator-iphone name: Boot iPhone Simulator command: xcrun simctl boot "iPhone 5s" || true @@ -293,20 +295,41 @@ aliases: name: tvOS Test Suite command: ./scripts/objc-test-tvos.sh test + - &display-broken-tests-warning + name: Running broken tests (Ignore any failures past this point) + command: | + echo 'The following steps are known to be failing on master.' + echo 'They will no-op for most users.' + echo 'PRs that bring these back to green are appreciated.' + + - &run-podspec-tests + name: Test CocoaPods (Disabled) + command: ./scripts/circleci/exec_author_check.sh ./scripts/process-podspecs.sh + - &run-e2e-tests - name: End-to-End Test Suite - command: node ./scripts/run-ci-e2e-tests.js --ios --tvos --js --retries 3; + name: End-to-End Test Suite (Disabled) + command: ./scripts/circleci/exec_author_check.sh node ./scripts/run-ci-e2e-tests.js --android --ios --tvos --js --retries 3; - &run-objc-ios-e2e-tests - name: iOS End-to-End Test Suite - command: node ./scripts/run-ci-e2e-tests.js --ios --retries 3; + name: iOS End-to-End Test Suite (Disabled) + command: ./scripts/circleci/exec_author_check.sh node ./scripts/run-ci-e2e-tests.js --ios --retries 3; - &run-objc-tvos-e2e-tests - name: tvOS End-to-End Test Suite - command: node ./scripts/run-ci-e2e-tests.js --tvos --js --retries 3; + name: tvOS End-to-End Test Suite (Disabled) + command: ./scripts/circleci/exec_author_check.sh node ./scripts/run-ci-e2e-tests.js --tvos --js --retries 3; + + - &run-android-e2e-tests + name: Android End-to-End Test Suite (Disabled) + command: ./scripts/circleci/exec_author_check.sh node ./scripts/run-ci-e2e-tests.js --android --retries 3; + + - &run-js-e2e-tests + name: JavaScript End-to-End Test Suite + command: node ./scripts/run-ci-e2e-tests.js --js --retries 3; defaults: &defaults working_directory: ~/react-native + environment: + - GIT_COMMIT_DESC: git log --format=oneline -n 1 $CIRCLE_SHA1 js_defaults: &js_defaults <<: *defaults @@ -318,14 +341,14 @@ js_defaults: &js_defaults android_defaults: &android_defaults <<: *defaults docker: - - image: circleci/android:api-26-node8-alpha + - image: circleci/android:api-27-node8-alpha resource_class: "large" environment: - TERM: "dumb" - ADB_INSTALL_TIMEOUT: 10 - _JAVA_OPTIONS: "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap" - GRADLE_OPTS: '-Dorg.gradle.daemon=false -Dorg.gradle.jvmargs="-XX:+HeapDumpOnOutOfMemoryError"' - - ANDROID_NDK: '/opt/ndk/android-ndk-r10e' + - ANDROID_NDK: '/opt/ndk/android-ndk-r17b' - BUILD_THREADS: 2 macos_defaults: &macos_defaults @@ -335,7 +358,6 @@ macos_defaults: &macos_defaults version: 2 jobs: - # Set up a Node environment for downstream jobs checkout_code: <<: *js_defaults @@ -355,6 +377,7 @@ jobs: paths: . # Runs JavaScript lint and flow checks. + # Currently will fail a PR if lint/flow raises issues. analyze: <<: *js_defaults steps: @@ -362,7 +385,8 @@ jobs: at: ~/react-native - run: *run-lint-checks - - run: *run-flow-checks + - run: *run-flow-checks-ios + - run: *run-flow-checks-android - store_test_results: path: ~/react-native/reports/junit @@ -381,122 +405,98 @@ jobs: - store_test_results: path: ~/react-native/reports/junit - # Runs unit tests on iOS devices - test_ios: + # Run JavaScript tests on Node 10 + test_node10: + <<: *defaults + docker: + - image: circleci/node:10 + environment: + - PATH: "/opt/yarn/yarn-v1.5.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + steps: + - checkout + - run: *setup-artifacts + - run: *yarn + - run: *run-js-tests + - store_test_results: + path: ~/react-native/reports/junit + + # Runs unit tests on iOS and Apple TV devices + test_objc: <<: *macos_defaults steps: - attach_workspace: at: ~/react-native - run: *boot-simulator-iphone - - run: brew install watchman + - run: *boot-simulator-appletv + - run: *brew-install-watchman + - run: *run-objc-ios-tests + - run: *run-objc-tvos-tests + + # TODO: Fix these failing tests. + - run: *display-broken-tests-warning + - run: *run-podspec-tests + - run: *run-objc-ios-e2e-tests + - run: *run-objc-tvos-e2e-tests - store_test_results: path: ~/react-native/reports/junit - # Runs unit tests on tvOS devices - test_tvos: - <<: *macos_defaults + # Xcode 10: Runs unit tests on iOS and Apple TV devices + test_objc_xcode10: + <<: *defaults + macos: + xcode: "10.0.0" steps: - - attach_workspace: - at: ~/react-native + - checkout + - run: *setup-artifacts + - run: *yarn + - run: *boot-simulator-iphone - run: *boot-simulator-appletv - - run: brew install watchman + - run: *brew-install-watchman + + - run: *run-objc-ios-tests - run: *run-objc-tvos-tests + # TODO: Fix these failing tests. + - run: *display-broken-tests-warning + - run: *run-podspec-tests + - run: *run-objc-ios-e2e-tests + - run: *run-objc-tvos-e2e-tests + - store_test_results: path: ~/react-native/reports/junit - # Runs end to end tests - test_end_to_end: + # Runs end to end tests (Detox) + test_detox_end_to_end: <<: *macos_defaults steps: - attach_workspace: at: ~/react-native - - - run: *boot-simulator-iphone - + - run: xcrun simctl boot "iPhone 5s" || true - run: name: Configure Environment Variables command: | echo 'export PATH=/usr/local/opt/node@8/bin:$PATH' >> $BASH_ENV source $BASH_ENV - - run: name: Install Node 8 command: | brew install node@8 brew link node@8 + brew tap wix/brew + brew install applesimutils node -v - - - run: *run-objc-ios-e2e-tests - - - store_test_results: - path: ~/react-native/reports/junit - - # Checks podspec - test_podspec: - <<: *macos_defaults - steps: - - attach_workspace: - at: ~/react-native - - - run: ./scripts/process-podspecs.sh - - # Publishes new version onto npm - publish_npm_package: - <<: *android_defaults - steps: - # Checkout code so that we can work with `git` in publish.js - - checkout - - # Configure Android SDK and related dependencies - - run: *configure-android-path - - run: *install-android-build-dependencies - - - restore-cache: *restore-cache-android-packages - - run: *install-android-packages - - save-cache: *save-cache-android-packages - - # Install Android NDK - - 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 - - - run: buck fetch ReactAndroid/src/test/java/com/facebook/react/modules - - run: buck fetch ReactAndroid/src/main/java/com/facebook/react - - run: buck fetch ReactAndroid/src/main/java/com/facebook/react/shell - - run: buck fetch ReactAndroid/src/test/... - - run: buck fetch ReactAndroid/src/androidTest/... - - - restore-cache: *restore-cache-gradle-downloads - - run: *gradle-download-deps - - save-cache: *save-cache-gradle-downloads - - - restore-cache: *restore-yarn-cache - run: *yarn - - save-cache: *save-yarn-cache - run: - name: Publish React Native Package - command: | - if [ -z "$CIRCLE_PULL_REQUEST" ]; then - echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc - git config --global user.email "reactjs-bot@users.noreply.github.com" - git config --global user.name "npm Deployment Script" - echo "machine github.com login reactjs-bot password $GITHUB_TOKEN" > ~/.netrc - node ./scripts/publish-npm.js - else - echo "Skipping deploy." - fi + name: Build iOS app for simulator + command: yarn run build-ios-e2e + - run: + name: Run Detox Tests + command: yarn run test-ios-e2e # Set up an Android environment for downstream jobs test_android: @@ -507,14 +507,14 @@ jobs: # Configure Android SDK and related dependencies - run: *configure-android-path - - restore-cache: *restore-cache-apt + # Android build deps install from the network faster than cache - run: *install-android-build-dependencies - - save-cache: *save-cache-apt - restore-cache: *restore-cache-android-packages - run: *install-android-packages - save-cache: *save-cache-android-packages + # Validate Android SDK installation and packages - run: *validate-android-sdk # Starting emulator in advance as it takes some time to boot. @@ -529,22 +529,21 @@ jobs: - run: *install-ndk - save-cache: *save-cache-ndk - # Fetch dependencies using BUCK - - restore-cache: *restore-cache-buck + # Install Buck + - restore-cache: *restore-cache-downloads-buck - run: *install-buck - - save-cache: *save-cache-buck + - save-cache: *save-cache-downloads-buck + # Validate Android test environment (including Buck) - run: *validate-android-test-env - - run: buck fetch ReactAndroid/src/test/java/com/facebook/react/modules - - run: buck fetch ReactAndroid/src/main/java/com/facebook/react - - run: buck fetch ReactAndroid/src/main/java/com/facebook/react/shell - - run: buck fetch ReactAndroid/src/test/... - - run: buck fetch ReactAndroid/src/androidTest/... + # Download dependencies using Buck + - run: *download-dependencies-buck - - restore-cache: *restore-cache-gradle-downloads - - run: *gradle-download-deps - - save-cache: *save-cache-gradle-downloads + # Download dependencies using Gradle + - restore-cache: *restore-cache-downloads-gradle + - run: *download-dependencies-gradle + - save-cache: *save-cache-downloads-gradle # Build and compile - run: *build-android-app @@ -559,6 +558,12 @@ jobs: # Test Suite - run: *run-android-unit-tests - run: *run-android-instrumentation-tests + - run: *build-android-rntester-app + + # Run Android end-to-end tests + # TODO: Fix these failing tests. + - run: *display-broken-tests-warning + - run: *run-android-e2e-tests # Collect Results - run: *collect-android-test-results @@ -568,47 +573,100 @@ jobs: # Analyze pull request and raise any lint/flow issues. # Issues will be posted to the PR itself via GitHub bots. # This workflow should only fail if the bots fail to run. + # The public github tokens are publicly visible by design analyze_pr: - <<: *js_defaults + <<: *defaults + docker: + - image: circleci/node:10 + environment: + - PATH: "/opt/yarn/yarn-v1.5.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + - PUBLIC_PULLBOT_GITHUB_TOKEN_A: "a6edf8e8d40ce4e8b11a" + - PUBLIC_PULLBOT_GITHUB_TOKEN_B: "150e1341f4dd9c944d2a" + - PUBLIC_ANALYSISBOT_GITHUB_TOKEN_A: "78a72af35445ca3f8180" + - PUBLIC_ANALYSISBOT_GITHUB_TOKEN_B: "b1a98e0bbd56ff1ccba1" + - CIRCLE_PR_NUMBER: "19681" + steps: - - attach_workspace: - at: ~/react-native + - checkout + - run: *setup-artifacts - - restore-cache: *restore-cache-analysis + - restore-cache: *restore-yarn-cache - run: *yarn + + - run: *install-shellcheck - run: - name: Install Additional Dependencies + name: Analyze Code command: | if [ -n "$CIRCLE_PR_NUMBER" ]; then - yarn add github@0.2.4 - cd bots - yarn install --non-interactive --cache-folder ~/.cache/yarn + echo -e "\\x1B[36mInstalling additional dependencies\\x1B[0m"; yarn add @octokit/rest@15.10.0 + echo -e "\\x1B[36mAnalyzing code\\x1B[0m"; GITHUB_TOKEN="$PUBLIC_ANALYSISBOT_GITHUB_TOKEN_A""$PUBLIC_ANALYSISBOT_GITHUB_TOKEN_B" ./scripts/circleci/analyze_code.sh else - echo "Skipping dependency installation." + echo "Skipping code analysis." fi - - save-cache: *save-cache-analysis - - run: *install-shellcheck + when: always + - restore-cache: *restore-cache-analysis - run: name: Analyze Pull Request command: | - # DANGER_GITHUB_API_TOKEN=React-Linter public_repo access token if [ -n "$CIRCLE_PR_NUMBER" ]; then - cd bots && DANGER_GITHUB_API_TOKEN="80aa64c50f38a267e9ba""575d41d528f9c234edb8" yarn danger + cd bots + yarn install --non-interactive --cache-folder ~/.cache/yarn + DANGER_GITHUB_API_TOKEN="$PUBLIC_PULLBOT_GITHUB_TOKEN_A""$PUBLIC_PULLBOT_GITHUB_TOKEN_B" yarn danger else echo "Skipping pull request analysis." fi when: always + - save-cache: *save-cache-analysis + + # Publishes new version onto npm + # Only works on stable branches when a properly tagged commit is pushed + publish_npm_package: + <<: *android_defaults + steps: + - checkout + + - restore-cache: *restore-yarn-cache + - run: *yarn + + # Configure Android SDK and related dependencies + - run: *configure-android-path + - run: *install-android-build-dependencies + + - restore-cache: *restore-cache-android-packages + - run: *install-android-packages + + # Install Android NDK + - run: *create-ndk-directory + - restore-cache: *restore-cache-ndk + - run: *install-ndk + + # Fetch dependencies using Buck + - restore-cache: *restore-cache-downloads-buck + - run: *install-buck + - run: *download-dependencies-buck + + # Fetch dependencies using Gradle + - restore-cache: *restore-cache-downloads-gradle + - run: *download-dependencies-gradle + + - restore-cache: *restore-yarn-cache + - run: *yarn + - run: - name: Analyze Code + name: Authenticate with npm + command: echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc + + - run: + name: Authenticate git user command: | - # GITHUB_TOKEN=eslint-bot public_repo access token - if [ -n "$CIRCLE_PR_NUMBER" ]; then - GITHUB_TOKEN="af6ef0d15709bc91d""06a6217a5a826a226fb57b7" CI_USER=$CIRCLE_PROJECT_USERNAME CI_REPO=$CIRCLE_PROJECT_REPONAME PULL_REQUEST_NUMBER=$CIRCLE_PR_NUMBER scripts/circleci/analyze_code.sh - else - echo "Skipping code analysis." - fi - when: always + git config --global user.email "react-native-bot@users.noreply.github.com" + git config --global user.name "npm Deployment Script" + echo "machine github.com login react-native-bot password $GITHUB_TOKEN" > ~/.netrc + + - run: + name: Publish React Native Package + command: node ./scripts/publish-npm.js # Workflows enables us to run multiple jobs in parallel workflows: @@ -616,7 +674,6 @@ workflows: tests: jobs: - # Checkout repo and run Yarn - checkout_code: filters: *filter-ignore-gh-pages @@ -640,60 +697,38 @@ workflows: - checkout_code # Test iOS & tvOS - - test_ios: + - test_objc: filters: *filter-ignore-gh-pages requires: - checkout_code - - test_tvos: + + - test_detox_end_to_end: filters: *filter-ignore-gh-pages requires: - checkout_code - # End-to-end tests - - test_end_to_end: + # Tooling Compatibility Checks + - test_objc_xcode10: + filters: *filter-ignore-gh-pages + - test_node10: filters: *filter-ignore-gh-pages - requires: - - checkout_code - # Only runs on PRs - analyze: - jobs: - # Checkout repo and run Yarn - - checkout_code: - filters: *filter-ignore-master-stable + # Only runs on vX.X.X tags if all tests are green + - publish_npm_package: + filters: + # ignore any commit on any branch by default + branches: + ignore: /.*/ + # only act on version tags + tags: + only: /v[0-9]+(\.[0-9]+)*(\-rc(\.[0-9]+)?)?/ + requires: + - analyze + - test_detox_end_to_end + - test_javascript + - test_objc + - test_android # Run code checks - analyze_pr: filters: *filter-ignore-master-stable - requires: - - checkout_code - - # Only runs on NN-stable branches - deploy: - jobs: - # If we are on a stable branch, wait for approval to deploy to npm - - approve_publish_npm_package: - filters: *filter-only-stable - type: approval - - - publish_npm_package: - requires: - - approve_publish_npm_package - - # These tests are flaky or are yet to be fixed. They are placed on their own - # workflow to avoid marking benign PRs as broken. - # To run them, uncomment the entire block and open a PR (do not merge). - # Once a test is fixed, move the test definition to the 'tests' workflow. - # disabled_tests: - # jobs: - # # Checkout repo and run Yarn (pre-req, should succeed) - # - checkout_code: - # filters: *filter-ignore-gh-pages - - # # The following were DISABLED because they have not run since - # # the migration from Travis, and they have broken since then, - # # CocoaPods - # - test_podspec: - # filters: *filter-ignore-gh-pages - # requires: - # - checkout_code diff --git a/bots/code-analysis-bot.js b/bots/code-analysis-bot.js index d8cf159a14739c..1407684f76f108 100644 --- a/bots/code-analysis-bot.js +++ b/bots/code-analysis-bot.js @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. @@ -9,12 +9,12 @@ 'use strict'; -if (!process.env.CI_USER) { - console.error('Missing CI_USER. Example: facebook'); +if (!process.env.CIRCLE_PROJECT_USERNAME) { + console.error('Missing CIRCLE_PROJECT_USERNAME. Example: facebook'); process.exit(1); } -if (!process.env.CI_REPO) { - console.error('Missing CI_REPO. Example: react-native'); +if (!process.env.CIRCLE_PROJECT_REPONAME) { + console.error('Missing CIRCLE_PROJECT_REPONAME. Example: react-native'); process.exit(1); } if (!process.env.GITHUB_TOKEN) { @@ -23,20 +23,18 @@ if (!process.env.GITHUB_TOKEN) { ); process.exit(1); } -if (!process.env.PULL_REQUEST_NUMBER) { - console.error('Missing PULL_REQUEST_NUMBER. Example: 4687'); - // for master branch don't throw and error +if (!process.env.CIRCLE_PR_NUMBER) { + console.error('Missing CIRCLE_PR_NUMBER. Example: 4687'); + // for master branch, don't throw an error process.exit(0); } -var GitHubApi = require('github'); -var path = require('path'); +// https://octokit.github.io/rest.js/ +const octokit = require('@octokit/rest')(); -var github = new GitHubApi({ - version: '3.0.0', -}); +var path = require('path'); -github.authenticate({ +octokit.authenticate({ type: 'oauth', token: process.env.GITHUB_TOKEN, }); @@ -111,20 +109,21 @@ var converters = { }, }; -function getShaFromPullRequest(user, repo, number, callback) { - github.pullRequests.get({user, repo, number}, (error, res) => { +function getShaFromPullRequest(owner, repo, number, callback) { + octokit.pullRequests.get({owner, repo, number}, (error, res) => { if (error) { - console.log(error); + console.error(error); return; } - callback(res.head.sha); + + callback(res.data.head.sha); }); } -function getFilesFromCommit(user, repo, sha, callback) { - github.repos.getCommit({user, repo, sha}, (error, res) => { +function getFilesFromCommit(owner, repo, sha, callback) { + octokit.repos.getCommit({owner, repo, sha}, (error, res) => { if (error) { - console.log(error); + console.error(error); return; } // A merge commit should not have any new changes to report @@ -132,7 +131,7 @@ function getFilesFromCommit(user, repo, sha, callback) { return; } - callback(res.files); + callback(res.data.files); }); } @@ -165,39 +164,68 @@ function getLineMapFromPatch(patchString) { return lineMap; } -function sendComment(user, repo, number, sha, filename, lineMap, message) { +function sendReview(owner, repo, number, commit_id, comments) { + if (comments.length === 0) { + // Do not leave an empty review. + return; + } + + const body = + '`eslint` found some issues. You may run `yarn prettier` or `npm run prettier` to fix these.'; + const event = 'REQUEST_CHANGES'; + + const opts = { + owner, + repo, + number, + commit_id, + body, + event, + comments, + }; + + octokit.pullRequests.createReview(opts, function(error, res) { + if (error) { + console.error(error); + return; + } + }); +} + +function sendComment(owner, repo, number, sha, filename, lineMap, message) { if (!lineMap[message.line]) { // Do not send messages on lines that did not change return; } var opts = { - user, + owner, repo, number, sha, - path: filename, commit_id: sha, - body: message.message, + path: filename, position: lineMap[message.line], + body: message.message, }; - github.pullRequests.createComment(opts, function(error, res) { + octokit.pullRequests.createComment(opts, function(error, res) { if (error) { - console.log(error); + console.error(error); return; } }); console.log('Sending comment', opts); } -function main(messages, user, repo, number) { +function main(messages, owner, repo, number) { // No message, we don't need to do anything :) if (Object.keys(messages).length === 0) { return; } - getShaFromPullRequest(user, repo, number, sha => { - getFilesFromCommit(user, repo, sha, files => { + getShaFromPullRequest(owner, repo, number, sha => { + getFilesFromCommit(owner, repo, sha, files => { + var comments = []; files.filter(file => messages[file.filename]).forEach(file => { // github api sometimes does not return a patch on large commits if (!file.patch) { @@ -205,11 +233,21 @@ function main(messages, user, repo, number) { } var lineMap = getLineMapFromPatch(file.patch); messages[file.filename].forEach(message => { - sendComment(user, repo, number, sha, file.filename, lineMap, message); - }); - }); - }); - }); + if (lineMap[message.line]) { + var comment = { + path: file.filename, + position: lineMap[message.line], + body: message.message, + }; + + comments.push(comment); + } + }); // forEach + }); // filter + + sendReview(owner, repo, number, sha, comments); + }); // getFilesFromCommit + }); // getShaFromPullRequest } var content = ''; @@ -260,10 +298,10 @@ process.stdin.on('end', function() { delete messages[absolutePath]; } - var user = process.env.CI_USER; - var repo = process.env.CI_REPO; - var number = process.env.PULL_REQUEST_NUMBER; + var owner = process.env.CIRCLE_PROJECT_USERNAME; + var repo = process.env.CIRCLE_PROJECT_REPONAME; + var number = process.env.CIRCLE_PR_NUMBER; // intentional lint warning to make sure that the bot is working :) - main(messages, user, repo, number); + main(messages, owner, repo, number); }); diff --git a/scripts/circleci/analyze_code.sh b/scripts/circleci/analyze_code.sh index da21e1aa7e4ee8..731cf1475e7c18 100755 --- a/scripts/circleci/analyze_code.sh +++ b/scripts/circleci/analyze_code.sh @@ -1,12 +1,15 @@ #!/bin/bash +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. -cat <(echo shellcheck; find scripts/. -type f -name '*.sh' -print0 | xargs -0 shellcheck -f json; echo shellcheck; find ContainerShip/scripts/. -type f -name '*.sh' -print0 | xargs -0 shellcheck -f json; echo eslint; yarn --silent lint --format=json; echo flow; yarn --silent flow check --json) | GITHUB_TOKEN=$GITHUB_TOKEN CI_USER=$CI_USER CI_REPO=$CI_REPO PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER node bots/code-analysis-bot.js +cat <(echo shellcheck; find scripts/. -type f -name '*.sh' -print0 | xargs -0 shellcheck -f json; echo shellcheck; find ContainerShip/scripts/. -type f -name '*.sh' -print0 | xargs -0 shellcheck -f json; echo eslint; npm run lint --silent -- --format=json; echo flow; npm run flow --silent -- check --json) | node scripts/circleci/code-analysis-bot.js # check status STATUS=$? if [ $STATUS == 0 ]; then echo "Code analyzed successfully" else - echo "Code analyzis failed, error status $STATUS" + echo "Code analysis failed, error status $STATUS" fi -