From 49c61bb263b280c9474d8216c5e6aa1a232804f9 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Thu, 21 Mar 2024 17:48:10 +0100 Subject: [PATCH] ci: Add shellcheck Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- .gitlab-ci.yml | 2 ++ .gitlab-ci/shellcheck.sh | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100755 .gitlab-ci/shellcheck.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 76796323..c47e6d45 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -110,6 +110,8 @@ review: codespell --ignore-words-list=keypair,sorce,ned,nd,ue || ERROR=1; ./.gitlab-ci/clang-format-check.sh || ERROR=1; ./.gitlab-ci/git-check-signoff-trailer.sh ${CI_MERGE_REQUEST_DIFF_BASE_SHA} || ERROR=1; + ./.gitlab-ci/git-check-signoff-trailer.sh ${CI_MERGE_REQUEST_DIFF_BASE_SHA} || ERROR=1; + ./.gitlab-ci/shellcheck.sh || ERROR=1; exit $ERROR # the format is not always matching our intentions allow_failure: true diff --git a/.gitlab-ci/shellcheck.sh b/.gitlab-ci/shellcheck.sh new file mode 100755 index 00000000..e7db0b63 --- /dev/null +++ b/.gitlab-ci/shellcheck.sh @@ -0,0 +1,56 @@ +#!/bin/bash +# Simplified and de-github-ed version of +# https://github.com/ludeeus/action-shellcheck/blob/master/action.yaml + +statuscode=0 + +declare -a filepaths +shebangregex="^#! */[^ ]*/(env *)?[abk]*sh" +set -f # temporarily disable globbing so that globs in inputs aren't expanded + +while IFS= read -r -d '' file; do + filepaths+=("$file") +done < <(find . \ + -type f \ + '(' \ + -name '*.bash' \ + -o -name '.bashrc' \ + -o -name 'bashrc' \ + -o -name '.bash_aliases' \ + -o -name '.bash_completion' \ + -o -name '.bash_login' \ + -o -name '.bash_logout' \ + -o -name '.bash_profile' \ + -o -name 'bash_profile' \ + -o -name '*.ksh' \ + -o -name 'suid_profile' \ + -o -name '*.zsh' \ + -o -name '.zlogin' \ + -o -name 'zlogin' \ + -o -name '.zlogout' \ + -o -name 'zlogout' \ + -o -name '.zprofile' \ + -o -name 'zprofile' \ + -o -name '.zsenv' \ + -o -name 'zsenv' \ + -o -name '.zshrc' \ + -o -name 'zshrc' \ + -o -name '*.sh' \ + -o -path '*/.profile' \ + -o -path '*/profile' \ + -o -name '*.shlib' \ + ')' \ + -print0) + +while IFS= read -r -d '' file; do + head -n1 "$file" | grep -Eqs "$shebangregex" || continue + filepaths+=("$file") +done < <(find . \ + -type f ! -name '*.*' -perm /111 \ + -print0) + +shellcheck "${filepaths[@]}" || statuscode=$? + +set +f # re-enable globbing + +exit "$statuscode"