timescaledb/scripts/check_unreferenced_files.sh
Alexander Kuzmenkov 4a17d4c402 Add shellcheck to CI
Writing a shell script correctly can be hard even for a skilled
programmer. shellcheck is a static analysis tool that helps catch
common errors in shell scripts. We now have 36 executable scripts in
our repository, for which shellcheck reports 126 errors (calculated
like find . -type f -executable -exec bash -c '[ "$(file --brief
--mime-type "$1")" == "text/x-shellscript" ]' sh {} \; -exec shellcheck
-f gcc --exclude=SC2086 {} \; | cut -d: -f1 | sort | uniq | wc -l).
This commit fixes these warnings and adds a GitHub actions workflow
that runs shellcheck on all the executable shell scripts in the
repository. The warning SC2086: Double quote to prevent globbing and
word splitting is disabled globally, because it has little practical
consequences, sometimes leads to false positives, and is general is too
widespread because people forget to quote.
2021-11-15 14:54:14 +03:00

36 lines
842 B
Bash
Executable File

#!/bin/bash
SCRIPT_DIR=$(dirname ${0})
BASE_DIR=$(pwd)/$SCRIPT_DIR/..
unreferenced=0
function get_filenames {
echo ./*.$2 ./*.$2.in | xargs git ls-files | xargs -IFILE basename FILE
}
function check_directory {
cd $BASE_DIR/$1 || exit
test_files=$(get_filenames $1 $2)
for file in $test_files; do
output=$(grep --files-without-match $file CMakeLists.txt)
# return value from grep --files-without-match seems to differ
# between grep versions so we use output instead of return value
if [ "$output" != "" ]; then
echo -e "\nUnreferenced file in $1: $file\n"
unreferenced=1
fi
done
}
check_directory test/sql sql
check_directory tsl/test/sql sql
check_directory tsl/test/shared/sql sql
check_directory test/isolation/specs spec
check_directory tsl/test/isolation/specs spec
exit $unreferenced