ci: Add basic shellcheck, whitespace & format checks
This commit is contained in:
parent
af23daadf1
commit
a6eae6f98e
4 changed files with 182 additions and 0 deletions
35
ci/shellcheck
Executable file
35
ci/shellcheck
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
# Template generated by https://github.com/coreos/repo-templates; do not edit downstream
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
main() {
|
||||
local found_errors="false"
|
||||
# Let's start with error, then we can do warning, info, style
|
||||
local -r severity="error"
|
||||
|
||||
while IFS= read -r -d '' f; do
|
||||
# Skip non-text files that are very unlikely to be shell scripts
|
||||
if [[ "$(file -b --mime-type "${f}" | sed 's|/.*||')" != "text" ]]; then
|
||||
continue
|
||||
fi
|
||||
shebang="$(head -1 "${f}")"
|
||||
if [[ "${f}" == *.sh ]] || \
|
||||
[[ ${shebang} =~ ^#!/.*/bash.* ]] || \
|
||||
[[ ${shebang} =~ ^#!/.*/env\ bash ]]; then
|
||||
echo "[+] Checking ${f}"
|
||||
shellcheck --external-sources --shell bash --severity="${severity}" "${f}" || found_errors="true"
|
||||
bash -n "${f}" || found_errors="true"
|
||||
fi
|
||||
done< <(find . -path "./.git" -prune -o -path "./vendor" -prune -o -type f -print0)
|
||||
|
||||
if [[ "${found_errors}" != "false" ]]; then
|
||||
echo "[+] Found errors with ShellCheck"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[+] No error found with ShellCheck"
|
||||
exit 0
|
||||
}
|
||||
|
||||
main "${@}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue