1#!/bin/bash
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3#
4# This source code is licensed under the MIT license found in the
5# LICENSE file in the root directory of this source tree.
6
7GITHUB_OWNER=${CIRCLE_PROJECT_USERNAME:-facebook}
8GITHUB_REPO=${CIRCLE_PROJECT_REPONAME:-react-native}
9export GITHUB_OWNER
10export GITHUB_REPO
11
12if [ -x "$(command -v shellcheck)" ]; then
13  IFS=$'\n'
14
15  if [ -n "$CIRCLE_CI" ]; then
16    results=( "$(find . -type f -not -path "*node_modules*" -not -path "*third-party*" -name '*.sh' -exec sh -c  'shellcheck "$1" -f json' -- {} \;)" )
17
18    cat <(echo shellcheck; printf '%s\n' "${results[@]}" | jq .,[] | jq -s . | jq --compact-output --raw-output '[ (.[] | .[] | . ) ]') | GITHUB_PR_NUMBER="$CIRCLE_PR_NUMBER" node scripts/circleci/code-analysis-bot.js
19
20    # check status
21    STATUS=$?
22    if [ $STATUS == 0 ]; then
23      echo "Shell scripts analyzed successfully."
24    else
25      echo "Shell script analysis failed, error status $STATUS."
26    fi
27
28  else
29    find . \
30      -type f \
31      -not -path "*node_modules*" \
32      -not -path "*third-party*" \
33      -name '*.sh' \
34    -exec sh -c 'shellcheck "$1"' -- {} \;
35  fi
36
37else
38  echo 'shellcheck is not installed. See https://github.com/facebook/react-native/wiki/Development-Dependencies#shellcheck for instructions.'
39  exit 1
40fi
41
42