Skip to content

Commit 53b487d

Browse files
hramosfacebook-github-bot
authored andcommitted
Use ShellCheck (facebook#19681)
Summary: As recommended in https://circleci.com/docs/2.0/using-shell-scripts/#use-shellcheck It will only run on PRs for now. Pull Request resolved: facebook#19681 Differential Revision: D10111711 Pulled By: hramos fbshipit-source-id: e980a526561dced79e5197a11cfb41a3eba9be8b
1 parent ea53727 commit 53b487d

File tree

9 files changed

+130
-86
lines changed

9 files changed

+130
-86
lines changed

.circleci/config.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,23 @@ jobs:
585585
- checkout
586586
- run: *setup-artifacts
587587

588-
- restore-cache: *restore-yarn-cache
588+
- restore-cache: *restore-cache-analysis
589589
- run: *yarn
590590

591+
- run:
592+
name: Analyze Shell Scripts
593+
command: |
594+
if [ -n "$CIRCLE_PR_NUMBER" ]; then
595+
echo -e "\\x1B[36mInstalling additional dependencies\\x1B[0m"
596+
sudo apt-get install -y shellcheck
597+
yarn add @octokit/[email protected]
598+
echo -e "\\x1B[36mAnalyzing shell scripts\\x1B[0m"
599+
GITHUB_TOKEN="$PUBLIC_ANALYSISBOT_GITHUB_TOKEN_A""$PUBLIC_ANALYSISBOT_GITHUB_TOKEN_B" ./scripts/circleci/analyze_scripts.sh
600+
else
601+
echo "Skipping shell script analysis."
602+
fi
603+
when: always
604+
591605
- run:
592606
name: Analyze Code
593607
command: |
@@ -599,7 +613,6 @@ jobs:
599613
fi
600614
when: always
601615

602-
- restore-cache: *restore-cache-analysis
603616
- run:
604617
name: Analyze Pull Request
605618
command: |

ContainerShip/scripts/run-android-docker-instrumentation-tests.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mount -o remount,exec /dev/shm
66
AVD_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)
77

88
# create virtual device
9-
echo no | android create avd -n $AVD_UUID -f -t android-19 --abi default/armeabi-v7a
9+
echo no | android create avd -n "$AVD_UUID" -f -t android-19 --abi default/armeabi-v7a
1010

1111
# emulator setup
1212
emulator64-arm -avd $AVD_UUID -no-skin -no-audio -no-window -no-boot-anim &
@@ -28,8 +28,9 @@ watchman shutdown-server
2828
node local-cli/cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/androidTest/js/TestBundle.js --bundle-output ReactAndroid/src/androidTest/assets/AndroidTestBundle.js
2929

3030
# build test APK
31+
# shellcheck disable=SC1091
3132
source ./scripts/android-setup.sh && NO_BUCKD=1 retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1
3233

3334
# run installed apk with tests
34-
node ./ContainerShip/scripts/run-android-ci-instrumentation-tests.js $*
35+
node ./ContainerShip/scripts/run-android-ci-instrumentation-tests.js "$*"
3536
exit $?

ContainerShip/scripts/run-android-docker-unit-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ mount -o remount,exec /dev/shm
99
set -x
1010

1111
# run unit tests
12-
buck test ReactAndroid/src/test/... --config build.threads=$UNIT_TESTS_BUILD_THREADS
12+
buck test ReactAndroid/src/test/... --config build.threads="$UNIT_TESTS_BUILD_THREADS"

ContainerShip/scripts/run-ci-e2e-tests.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ function e2e_suite() {
128128
emulator64-arm -avd "$AVD_UUID" -no-skin -no-audio -no-window -no-boot-anim &
129129

130130
bootanim=""
131+
# shellcheck disable=SC2076
131132
until [[ "$bootanim" =~ "stopped" ]]; do
132133
sleep 5
133134
bootanim=$(adb -e shell getprop init.svc.bootanim 2>&1)
@@ -210,15 +211,15 @@ function e2e_suite() {
210211
fi
211212

212213
# kill packager process
213-
if kill -0 $SERVER_PID; then
214+
if kill -0 "$SERVER_PID"; then
214215
echo "Killing packager $SERVER_PID"
215-
kill -9 $SERVER_PID
216+
kill -9 "$SERVER_PID"
216217
fi
217218

218219
# kill appium process
219-
if kill -0 $APPIUM_PID; then
220+
if kill -0 "$APPIUM_PID"; then
220221
echo "Killing appium $APPIUM_PID"
221-
kill -9 $APPIUM_PID
222+
kill -9 "$APPIUM_PID"
222223
fi
223224

224225
fi

ContainerShip/scripts/run-instrumentation-tests-via-adb-shell.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
2+
# shellcheck disable=SC1117
33
# Python script to run instrumentation tests, copied from https://github.com/circleci/circle-dummy-android
44
# Example: ./scripts/run-android-instrumentation-tests.sh com.facebook.react.tests com.facebook.react.tests.ReactPickerTestCase
55
#
@@ -9,7 +9,7 @@ export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"
99
adb logcat -c
1010

1111
# run tests and check output
12-
python - $1 $2 << END
12+
python - "$1" "$2" << END
1313
1414
import re
1515
import subprocess as sp
@@ -24,7 +24,7 @@ test_class = None
2424
2525
if len(sys.argv) > 2:
2626
test_class = sys.argv[2]
27-
27+
2828
def update():
2929
# prevent CircleCI from killing the process for inactivity
3030
while not done:
@@ -38,10 +38,10 @@ t.start()
3838
def run():
3939
sp.Popen(['adb', 'wait-for-device']).communicate()
4040
if (test_class != None):
41-
p = sp.Popen('adb shell am instrument -w -e class %s %s/android.support.test.runner.AndroidJUnitRunner'
41+
p = sp.Popen('adb shell am instrument -w -e class %s %s/android.support.test.runner.AndroidJUnitRunner'
4242
% (test_class, test_app), shell=True, stdout=sp.PIPE, stderr=sp.PIPE, stdin=sp.PIPE)
4343
else :
44-
p = sp.Popen('adb shell am instrument -w %s/android.support.test.runner.AndroidJUnitRunner'
44+
p = sp.Popen('adb shell am instrument -w %s/android.support.test.runner.AndroidJUnitRunner'
4545
% (test_app), shell=True, stdout=sp.PIPE, stderr=sp.PIPE, stdin=sp.PIPE)
4646
return p.communicate()
4747
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# Copyright (c) Facebook, Inc. and its 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+
7+
IFS=$'\n'
8+
9+
results=( "$(find . -type f -not -path "*node_modules*" -not -path "*third-party*" -name '*.sh' -exec sh -c 'shellcheck "$1" -f json' -- {} \;)" )
10+
11+
cat <(echo shellcheck; printf '%s\n' "${results[@]}" | jq .,[] | jq -s . | jq --compact-output --raw-output '[ (.[] | .[] | . ) ]') | node bots/code-analysis-bot.js
12+
13+
# check status
14+
STATUS=$?
15+
if [ $STATUS == 0 ]; then
16+
echo "Shell scripts analyzed successfully"
17+
else
18+
echo "Shell script analysis failed, error status $STATUS"
19+
fi

0 commit comments

Comments
 (0)