mirror of
https://github.com/tiny-pilot/tinypilot.git
synced 2021-09-19 22:56:27 +03:00
Add ShellCheck to Circle CI config. (#569)
* Add shellcheck. * Fix circleci config. * Apply shellcheck recommendations. * Fix check-bash. * Globally ignore SC1091. * Cleanup.
This commit is contained in:
@@ -11,6 +11,17 @@ jobs:
|
||||
- run:
|
||||
name: Check that all text files end in a trailing newline
|
||||
command: ./dev-scripts/check-trailing-newline
|
||||
check_bash:
|
||||
docker:
|
||||
- image: koalaman/shellcheck-alpine:v0.7.1
|
||||
steps:
|
||||
- run:
|
||||
name: Install dependencies
|
||||
command: apk add bash git openssh-client grep
|
||||
- checkout
|
||||
- run:
|
||||
name: Run static analysis on bash scripts
|
||||
command: ./dev-scripts/check-bash
|
||||
build_python:
|
||||
docker:
|
||||
- image: circleci/python:3.7.3
|
||||
@@ -49,6 +60,7 @@ workflows:
|
||||
test:
|
||||
jobs:
|
||||
- check_whitespace
|
||||
- check_bash
|
||||
- build_python
|
||||
- format_frontend
|
||||
- e2e
|
||||
|
||||
3
.shellcheckrc
Normal file
3
.shellcheckrc
Normal file
@@ -0,0 +1,3 @@
|
||||
# Stop shellcheck from complaining about references to files that don't
|
||||
# exist. They'll exist in a production environment, so these flags are noise.
|
||||
disable=SC1091
|
||||
@@ -10,6 +10,7 @@ The steps below show you how to quickly set up a development environment for Tin
|
||||
|
||||
* Python 3.7 or higher
|
||||
* Node.js 13.x or higher
|
||||
* [shellcheck](https://github.com/koalaman/shellcheck#installing)
|
||||
|
||||
### Install packages
|
||||
|
||||
|
||||
@@ -11,5 +11,6 @@ set -u
|
||||
|
||||
./dev-scripts/check-trailing-whitespace
|
||||
./dev-scripts/check-trailing-newline
|
||||
./dev-scripts/check-bash
|
||||
./dev-scripts/build-python
|
||||
./dev-scripts/check-frontend-format
|
||||
|
||||
21
dev-scripts/check-bash
Executable file
21
dev-scripts/check-bash
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Run static analysis on bash scripts.
|
||||
|
||||
# Exit on first failing command.
|
||||
set -e
|
||||
|
||||
# Exit on unset variable.
|
||||
set -u
|
||||
|
||||
BASH_SCRIPTS=()
|
||||
|
||||
while read -r line; do
|
||||
if head -n 1 "${line}" | grep --quiet "#!/bin/bash"; then
|
||||
BASH_SCRIPTS+=("${line}")
|
||||
fi
|
||||
done < <(git ls-files)
|
||||
|
||||
readonly BASH_SCRIPTS
|
||||
|
||||
shellcheck "${BASH_SCRIPTS[@]}"
|
||||
@@ -7,23 +7,18 @@ set -e
|
||||
# Exit on unset variable.
|
||||
set -u
|
||||
|
||||
readonly TEXT_FILES=$(grep \
|
||||
".*" \
|
||||
--files-with-matches \
|
||||
--binary-files=without-match \
|
||||
--exclude="*.svg" \
|
||||
--exclude="*third-party*" \
|
||||
$(git ls-files | xargs)
|
||||
)
|
||||
|
||||
success=0
|
||||
|
||||
for text_file in ${TEXT_FILES[*]}
|
||||
do
|
||||
if ! [[ -s "${text_file}" && -z "$(tail -c 1 "${text_file}")" ]]; then
|
||||
printf "File must end in a trailing newline: ${text_file}\n" >&2
|
||||
success=-1
|
||||
while read -r line; do
|
||||
if ! [[ -s "${line}" && -z "$(tail -c 1 "${line}")" ]]; then
|
||||
printf "File must end in a trailing newline: %s\n" "${line}" >&2
|
||||
success=255
|
||||
fi
|
||||
done
|
||||
done < <(git ls-files \
|
||||
| xargs grep ".*" \
|
||||
--files-with-matches \
|
||||
--binary-files=without-match \
|
||||
--exclude="*.svg" \
|
||||
--exclude="*third-party*")
|
||||
|
||||
exit "${success}"
|
||||
|
||||
@@ -7,12 +7,15 @@ set -e
|
||||
# Exit on unset variable.
|
||||
set -u
|
||||
|
||||
if grep \
|
||||
"\s$" \
|
||||
--line-number \
|
||||
--binary-files=without-match \
|
||||
--exclude="*third-party*" \
|
||||
$(git ls-files | xargs); then
|
||||
echo "ERROR: Found trailing whitespace";
|
||||
exit 1;
|
||||
fi
|
||||
while read -r line; do
|
||||
if grep \
|
||||
"\s$" \
|
||||
--line-number \
|
||||
--with-filename \
|
||||
--binary-files=without-match \
|
||||
--exclude="*third-party*" \
|
||||
"${line}"; then
|
||||
echo "ERROR: Found trailing whitespace";
|
||||
exit 1;
|
||||
fi
|
||||
done < <(git ls-files)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
# Echo commands to stdout.
|
||||
set -x
|
||||
|
||||
2
e2e/test
2
e2e/test
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
# Echo commands to stdout.
|
||||
set -x
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
# Echo commands to stdout.
|
||||
set -x
|
||||
@@ -69,7 +69,7 @@ readonly EXTRA_VARS_PATH
|
||||
# Check if the user is accidentally downgrading from TinyPilot Pro.
|
||||
HAS_PRO_INSTALLED=0
|
||||
|
||||
SCRIPT_DIR="$(dirname $0)"
|
||||
SCRIPT_DIR="$(dirname "$0")"
|
||||
# If they're piping this script in from stdin, guess that TinyPilot is
|
||||
# in the default location.
|
||||
if [ "$SCRIPT_DIR" = "." ]; then
|
||||
@@ -101,7 +101,7 @@ if [ "$HAS_PRO_INSTALLED" = 1 ]; then
|
||||
printf "type the following:\n\n"
|
||||
printf " export FORCE_DOWNGRADE=1\n\n"
|
||||
printf "And then run your previous command again.\n"
|
||||
exit -1
|
||||
exit 255
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
# The canonical way to update is through the update script below,
|
||||
# but this file is here for backwards compatibility.
|
||||
|
||||
Reference in New Issue
Block a user