Skip to content

Commit

Permalink
Test shellcheck workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Brian J. Murrell <brian.murrell@intel.com>
  • Loading branch information
brianjmurrell committed Jul 9, 2024
1 parent 8f90bbf commit b519d01
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
1 change: 0 additions & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
with:
format: gcc


linting-summary:
name: Linting Summary
runs-on: ubuntu-22.04
Expand Down
69 changes: 69 additions & 0 deletions t
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
INPUT_SCANDIR="."
INPUT_CHECK_TOGETHER=""
INPUT_EXCLUDE_ARGS="! -path *./.git/* ! -path *.go ! -path */mvnw"
INPUT_ADDITIONAL_FILE_ARGS=""
INPUT_SHELLCHECK_OPTIONS="--format=gcc"

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 "${INPUT_SCANDIR}" \
${INPUT_EXCLUDE_ARGS} \
-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' \
${INPUT_ADDITIONAL_FILE_ARGS} \
')' \
-print0)

while IFS= read -r -d '' file; do
head -n1 "$file" | grep -Eqs "$shebangregex" || continue
filepaths+=("$file")
done < <(find "${INPUT_SCANDIR}" \
${INPUT_EXCLUDE_ARGS} \
-type f ! -name '*.*' -perm /111 \
-print0)

if [[ -n "${INPUT_CHECK_TOGETHER}" ]]; then
"/home/runner/work/_actions/ludeeus/action-shellcheck/2.0.0/shellcheck" \
${INPUT_SHELLCHECK_OPTIONS} \
"${filepaths[@]}" || statuscode=$?
else
for file in "${filepaths[@]}"; do
"/home/runner/work/_actions/ludeeus/action-shellcheck/2.0.0/shellcheck" \
${INPUT_SHELLCHECK_OPTIONS} \
"$file" || statuscode=$?
done
fi

echo "filepaths=${filepaths[@]}"
echo "statuscode=$statuscode"
3 changes: 3 additions & 0 deletions tests/test_get_commit_pragmas
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# should fail shellcheck
a=$b

Check failure on line 4 in tests/test_get_commit_pragmas

View workflow job for this annotation

GitHub Actions / ShellCheck

a appears unused. Verify use (or export if used externally). [SC2034]

Check failure on line 4 in tests/test_get_commit_pragmas

View workflow job for this annotation

GitHub Actions / ShellCheck

b is referenced but not assigned. [SC2154]

test_get_commit_pragmas() {
local msg='Use external action
Expand Down

0 comments on commit b519d01

Please sign in to comment.