refact(ci): ShellCheck (#887)

* ci: add shfmt

* refact: shellcheck
This commit is contained in:
JEEVITHA KANNAN K S 2024-10-31 23:23:06 +05:30 committed by GitHub
parent 696110eae5
commit 23954aa8bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,9 +1,9 @@
name: ShellCheck name: Script Checks
on: on:
pull_request: pull_request:
paths: paths:
- 'core/tabs/**/*.sh' - '**/*.sh'
workflow_dispatch: workflow_dispatch:
jobs: jobs:
@ -11,45 +11,24 @@ jobs:
name: Shellcheck name: Shellcheck
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - name: Checkout sources
- run: git fetch origin ${{ github.base_ref }} uses: actions/checkout@v4
- name: Download, setup, and run ShellCheck - name: Run ShellCheck
shell: bash {0} uses: reviewdog/action-shellcheck@v1
run : | with:
SC_URL="https://github.com/koalaman/shellcheck/releases/download/v0.10.0/shellcheck-v0.10.0.linux.x86_64.tar.xz" reviewdog_flags: '-fail-level=any'
curl -fsSL "$SC_URL" | tar -Jx
chmod +x "./shellcheck-v0.10.0/shellcheck"
error=0 shfmt:
files_to_check=$(git diff --name-only origin/${{ github.base_ref }} HEAD core/tabs) name: Shell Fomatting
runs-on: ubuntu-latest
needs: shellcheck
steps:
- name: Checkout sources
uses: actions/checkout@v4
for file in $files_to_check; do - name: Run shfmt
if [[ "$file" == *.sh ]] && [[ -f "$file" ]]; then uses: reviewdog/action-shfmt@v1
sc_output=$(./shellcheck-v0.10.0/shellcheck -fgcc -Serror "$file") with:
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') shfmt_flags: '-i 4 -ci'
reviewdog_flags: '-fail-level=any'
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 error 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