2022-07-27 23:33:53 +03:00
|
|
|
#!/usr/bin/env bash
|
2022-04-13 15:58:11 +03:00
|
|
|
set -euo pipefail
|
|
|
|
|
2022-07-29 00:10:11 +03:00
|
|
|
cd "$(git rev-parse --show-toplevel)"
|
2022-04-13 15:58:11 +03:00
|
|
|
|
2022-07-29 00:10:11 +03:00
|
|
|
mapfile -t files < \
|
|
|
|
<(git ls-files)
|
|
|
|
mapfile -t scripts < \
|
2022-10-13 12:48:43 +03:00
|
|
|
<(awk '/#!(\/usr\/bin\/env bash|\/bin\/sh)/&&FNR==1{print FILENAME}' "${files[@]}")
|
2022-07-29 00:10:11 +03:00
|
|
|
mapfile -t buildfiles < \
|
|
|
|
<(find . \( -name 'WORKSPACE' -o -name 'BUILD' -o -name '*.bzl' \))
|
|
|
|
|
|
|
|
>&2 echo "shellcheck"
|
|
|
|
for f in "${scripts[@]}"; do >&2 echo " $f"; done
|
2022-09-29 12:11:34 +03:00
|
|
|
shellcheck "${scripts[@]}"
|
2022-07-29 00:10:11 +03:00
|
|
|
>&2 echo -e "OK\n"
|
|
|
|
|
2022-09-29 12:11:34 +03:00
|
|
|
>&2 echo "buildifier -mode diff"
|
2022-07-29 00:10:11 +03:00
|
|
|
for f in "${buildfiles[@]}"; do >&2 echo " $f"; done
|
2022-09-29 12:11:34 +03:00
|
|
|
fail=0
|
|
|
|
out=$(buildifier -mode diff -diff_command='diff -u' "${buildfiles[@]}") || fail=1
|
|
|
|
if [[ "$fail" == 1 ]]; then
|
|
|
|
>&2 echo "ERROR: buildifier:"
|
|
|
|
echo "$out"
|
|
|
|
>&2 echo
|
|
|
|
>&2 echo "You may try running:"
|
|
|
|
>&2 echo " buildifier ${buildfiles[*]}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-07-29 00:10:11 +03:00
|
|
|
>&2 echo -e "OK\n"
|