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
This commit is contained in:
Nicola Corti 2024-07-03 05:49:47 -07:00 committed by Facebook GitHub Bot
parent 8db2995934
commit c0977c39b9
6 changed files with 57 additions and 56 deletions

View File

@ -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:

43
.github/actions/lint/action.yml vendored Normal file
View File

@ -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

View File

@ -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 }}

View File

@ -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 }}

View File

@ -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 }}

View File

@ -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