-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- id: differential-shellcheck | ||
name: Differential ShellCheck | ||
description: Static analysis tool for changed shell scripts | ||
language: docker | ||
entry: /action/pre-commit.sh | ||
types: [shell] | ||
verbose: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
INPUT_SEVERITY="style" | ||
|
||
for arg | ||
do | ||
case "${arg}" in | ||
-S=*|--severity=*) | ||
INPUT_SEVERITY="${arg#*=}" | ||
shift | ||
;; | ||
-S|--severity) | ||
# shellcheck disable=SC2034 | ||
INPUT_SEVERITY="$2" | ||
# shellcheck disable=SC2016 | ||
shift 2 || { echo 'option `--severity` requires an argument SEVERITY' >&2; exit 1; } | ||
;; | ||
-x|--external-sources) | ||
# shellcheck disable=SC2034 | ||
INPUT_EXTERNAL_SOURCES=y | ||
shift | ||
;; | ||
*) | ||
break | ||
;; | ||
esac | ||
done | ||
|
||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")/" | ||
Check warning Code scanning / shellcheck Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore). Warning
Consider invoking this command separately to avoid masking its return value (or use '|| true' to ignore).
|
||
export SCRIPT_DIR | ||
|
||
# shellcheck source=functions.sh | ||
. "${SCRIPT_DIR-}functions.sh" | ||
Check warning Code scanning / shellcheck Not following: functions.sh: openBinaryFile: does not exist (No such file or directory) Warning
Not following: functions.sh: openBinaryFile: does not exist (No such file or directory)
|
||
|
||
WORK_DIR="$(mktemp -d)/" | ||
export WORK_DIR | ||
|
||
export GROUP="" | ||
export ENDGROUP="" | ||
|
||
only_changed_scripts=("$@") | ||
|
||
echo -e "${VERSIONS_HEADING}" | ||
Check warning Code scanning / shellcheck VERSIONS_HEADING is referenced but not assigned. Warning
VERSIONS_HEADING is referenced but not assigned.
|
||
show_versions | ||
|
||
echo -e "${MAIN_HEADING}" | ||
Check warning Code scanning / shellcheck MAIN_HEADING is referenced but not assigned. Warning
MAIN_HEADING is referenced but not assigned.
|
||
|
||
echo -e "📜 ${WHITE}List of shell scripts for scanning${NOCOLOR}" | ||
Check warning Code scanning / shellcheck WHITE is referenced but not assigned. Warning
WHITE is referenced but not assigned.
Check warning Code scanning / shellcheck NOCOLOR is referenced but not assigned. Warning
NOCOLOR is referenced but not assigned.
|
||
echo "${only_changed_scripts[@]}" | ||
echo | ||
|
||
# ------------ # | ||
# SHELLCHECK # | ||
# ------------ # | ||
|
||
exit_status=0 | ||
|
||
execute_shellcheck "${only_changed_scripts[@]}" > "${WORK_DIR}head-shellcheck.err" | ||
|
||
git stash >/dev/null | ||
|
||
execute_shellcheck "${only_changed_scripts[@]}" > "${WORK_DIR}base-shellcheck.err" | ||
|
||
git stash apply --index >/dev/null | ||
|
||
get_fixes "${WORK_DIR}base-shellcheck.err" "${WORK_DIR}head-shellcheck.err" | ||
evaluate_and_print_fixes | ||
|
||
get_defects "${WORK_DIR}head-shellcheck.err" "${WORK_DIR}base-shellcheck.err" | ||
|
||
echo | ||
|
||
evaluate_and_print_defects | ||
exit_status=$? | ||
|
||
summary | ||
|
||
exit "${exit_status}" |