From c0977c39b9e2f6887edce919bc850b2958e6905d Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Wed, 3 Jul 2024 05:49:47 -0700 Subject: [PATCH] Migrate analyse_code to GHA (#45247) Summary: This migrates `analyse_code` to GHA into a single job called `lint`. ## Changelog: [INTERNAL] - Migrate analyse_code to GHA Pull Request resolved: https://github.com/facebook/react-native/pull/45247 Test Plan: CI Reviewed By: NickGerleman Differential Revision: D59283393 Pulled By: cortinico fbshipit-source-id: dcdc4828a551062b3706e6450614b8c94e1a7e81 --- .circleci/configurations/jobs.yml | 6 +-- .github/actions/lint/action.yml | 43 ++++++++++++++++++++++ .github/workflows/nightly.yml | 3 -- .github/workflows/publish-release.yml | 3 -- .github/workflows/test-all.yml | 15 ++++++-- scripts/circleci/validate_yarn_lockfile.sh | 43 ---------------------- 6 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 .github/actions/lint/action.yml delete mode 100755 scripts/circleci/validate_yarn_lockfile.sh diff --git a/.circleci/configurations/jobs.yml b/.circleci/configurations/jobs.yml index 59e51e16f8d..b97865fc450 100644 --- a/.circleci/configurations/jobs.yml +++ b/.circleci/configurations/jobs.yml @@ -58,10 +58,8 @@ jobs: when: always - run: - name: Sanity checks - command: | - ./scripts/circleci/check_license.sh - ./scripts/circleci/validate_yarn_lockfile.sh + name: Check license + command: ./scripts/circleci/check_license.sh when: always - run: diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml new file mode 100644 index 00000000000..bfec4d5814a --- /dev/null +++ b/.github/actions/lint/action.yml @@ -0,0 +1,43 @@ +name: lint +description: Runs all the linters in the codebase +inputs: + node-version: + description: "The node.js version to use" + required: false + default: "18" + github-token: + description: "The GitHub token used by pull-bot" + required: true +runs: + using: composite + steps: + - name: Setup node.js + uses: ./.github/actions/setup-node + with: + node-version: ${{ inputs.node-version }} + - name: Yarn install + shell: bash + run: yarn install --non-interactive --frozen-lockfile + - name: Run linters against modified files (analysis-bot) + shell: bash + run: yarn lint-ci + env: + GITHUB_TOKEN: ${{ inputs.github-token}} + - name: Lint code + shell: bash + run: ./scripts/circleci/exec_swallow_error.sh yarn lint --format junit -o ./reports/junit/eslint/results.xml + - name: Lint java + shell: bash + run: ./scripts/circleci/exec_swallow_error.sh yarn lint-java --check + - name: Run flowcheck + shell: bash + run: yarn flow-check + - name: Run typescript check + shell: bash + run: yarn test-typescript + - name: Check license + shell: bash + run: ./scripts/circleci/check_license.sh + - name: Check formatting + shell: bash + run: yarn run format-check diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 592e7eb87c9..fdc1f6109a0 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -564,9 +564,6 @@ jobs: GRADLE_OPTS: '-Dorg.gradle.daemon=false' # By default we only build ARM64 to save time/resources. For release/nightlies/prealpha, we override this value to build all archs. ORG_GRADLE_PROJECT_reactNativeArchitectures: "arm64-v8a" - # Repeated here, as the environment key in this executor will overwrite the one in defaults - PUBLIC_ANALYSISBOT_GITHUB_TOKEN_A: ${{ secrets.GITHUB_ANALYSISBOT_TOKEN_A }} - PUBLIC_ANALYSISBOT_GITHUB_TOKEN_B: ${{ secrets.GITHUB_ANALYSISBOT_TOKEN_B }} HERMES_WS_DIR: /tmp/hermes env: GHA_NPM_TOKEN: ${{ secrets.GHA_NPM_TOKEN }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index b7b0031755d..409b3533882 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -561,9 +561,6 @@ jobs: GRADLE_OPTS: '-Dorg.gradle.daemon=false' # By default we only build ARM64 to save time/resources. For release/nightlies/prealpha, we override this value to build all archs. ORG_GRADLE_PROJECT_reactNativeArchitectures: "arm64-v8a" - # Repeated here, as the environment key in this executor will overwrite the one in defaults - PUBLIC_ANALYSISBOT_GITHUB_TOKEN_A: ${{ secrets.GITHUB_ANALYSISBOT_TOKEN_A }} - PUBLIC_ANALYSISBOT_GITHUB_TOKEN_B: ${{ secrets.GITHUB_ANALYSISBOT_TOKEN_B }} HERMES_WS_DIR: /tmp/hermes env: GHA_NPM_TOKEN: ${{ secrets.GHA_NPM_TOKEN }} diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml index e29f7360cbb..7a67f4a89a2 100644 --- a/.github/workflows/test-all.yml +++ b/.github/workflows/test-all.yml @@ -645,9 +645,6 @@ jobs: GRADLE_OPTS: "-Dorg.gradle.daemon=false" # By default we only build ARM64 to save time/resources. For release/nightlies/prealpha, we override this value to build all archs. ORG_GRADLE_PROJECT_reactNativeArchitectures: "arm64-v8a" - # Repeated here, as the environment key in this executor will overwrite the one in defaults - PUBLIC_ANALYSISBOT_GITHUB_TOKEN_A: ${{ secrets.GITHUB_ANALYSISBOT_TOKEN_A }} - PUBLIC_ANALYSISBOT_GITHUB_TOKEN_B: ${{ secrets.GITHUB_ANALYSISBOT_TOKEN_B }} HERMES_WS_DIR: /tmp/hermes steps: - name: Add github.com to SSH known hosts @@ -943,3 +940,15 @@ jobs: uses: ./.github/actions/test-js with: node-version: ${{ matrix.node-version }} + + lint: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + - name: Run all the Linters + uses: ./.github/actions/lint + with: + github-token: ${{ env.GH_TOKEN }} diff --git a/scripts/circleci/validate_yarn_lockfile.sh b/scripts/circleci/validate_yarn_lockfile.sh deleted file mode 100755 index 5ef993ed9ef..00000000000 --- a/scripts/circleci/validate_yarn_lockfile.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash -# Copyright (c) Meta Platforms, Inc. and affiliates. -# -# This source code is licensed under the MIT license found in the -# LICENSE file in the root directory of this source tree. - -# Abort the mission if any command fails -set -e - -# Allow the script to be invoked from various environments -if [[ -z "${OVERRIDE_YARN_BINARY}" ]]; then - YARN_BINARY=$(command -v yarn) -else - YARN_BINARY="${OVERRIDE_YARN_BINARY}" -fi - -REACT_NATIVE_TEMP_DIR=$(mktemp -d /tmp/react-native-XXXXXXXX) - -function cleanup { - set +e - rm -rf "$REACT_NATIVE_TEMP_DIR" - set -e -} - -function msg { - echo -e " " - echo -e "\\x1B[36m${1}\\x1B[0m"; - echo -e "\\x1B[36m${1//?/=}\\x1B[0m" -} - -trap cleanup EXIT - -cp -R ./package.json "$REACT_NATIVE_TEMP_DIR" -cp -R ./yarn.lock "$REACT_NATIVE_TEMP_DIR" -pushd "$REACT_NATIVE_TEMP_DIR" >/dev/null - -if ! $YARN_BINARY --ignore-scripts --silent --non-interactive --mutex network --frozen-lockfile; then - msg "Yarn validation failed." - echo "This means the package.json and yarn.lock disagree in some way." - echo "Try fixing it by running \`yarn\` and committing the changes." -fi - -popd >/dev/null