From 6bec5f82837978a58f476dd6cc602d8aa568c984 Mon Sep 17 00:00:00 2001 From: Carter Canedy Date: Tue, 24 Sep 2024 09:08:05 -0700 Subject: [PATCH] make shellcheck emit all errors found and check for tab indentation --- .github/workflows/shellcheck.yml | 43 +++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml index e91ad941..b8d03ab8 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/shellcheck.yml @@ -14,17 +14,42 @@ jobs: - uses: actions/checkout@v4 - run: git fetch origin ${{ github.base_ref }} - - name: Download and set up shellcheck + - name: Download, setup, and run ShellCheck + shell: bash {0} run : | - wget https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.linux.x86_64.tar.xz - tar -xf shellcheck-v0.10.0.linux.x86_64.tar.xz - cd shellcheck-v0.10.0 - chmod +x shellcheck + SC_URL="https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.linux.x86_64.tar.xz" + curl -fsSL "$SC_URL" | tar -Jx + chmod +x "./shellcheck-v0.10.0/shellcheck" - - name: Run shellcheck - run: | - for file in $(git diff --name-only origin/${{ github.base_ref }} HEAD core/tabs); do + error=0 + files_to_check=$(git diff --name-only origin/${{ github.base_ref }} HEAD core/tabs) + + for file in $files_to_check; do if [[ "$file" == *.sh ]] && [[ -f "$file" ]]; then - ./shellcheck-v0.10.0/shellcheck -S error "$file" + sc_output=$(./shellcheck-v0.10.0/shellcheck -fgcc -Serror "$file") + iter_safe_parsed_errors=$(echo -e "$sc_output" | sed -n 's/\(.\+\)\:\([0-9]\+\)\:\([0-9]\+\)\: \(.*\)/::error file=\1,line=\2,col=\3::\4/p' | sed 's/ /:space:/g') + + for error in $iter_safe_parsed_errors; do + echo "$error" | sed 's/:space:/ /g' + error=1 + done + + tabs_detected=$(grep -nP '^\t+\S+' "$file") + + # fast fail on the action runner would fail immediately if there weren't any tabs found + # this check makes sure that we don't continue if there's something really weird going on + if [ "$?" = "2" ]; then + echo "::error file=$file::There was a critical while grepping $file, aborting" + exit 1 + fi + + iter_safe_parsed_tabs_detected=$(echo "$tabs_detected" | sed -n 's,\([0-9]\+\).*,::error file='"$file"'\,line=\1::Found tab indentations,p' | sed 's/ /:space:/g') + + for error in $iter_safe_parsed_tabs_detected; do + echo "$error" | sed 's/:space:/ /g' + error=1 + done fi done + + exit $error