Skip to content

Commit 2ccaea8

Browse files
authored
ci: feat: add ci-shellcheck.yml (#33)
Add ./shellcheck to check on all shell files.
1 parent 22de217 commit 2ccaea8

14 files changed

+558
-301
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: CI - ShellCheck
2+
on:
3+
push:
4+
branches: ["**"]
5+
pull_request:
6+
branches: ["**"]
7+
workflow_dispatch:
8+
permissions:
9+
contents: read
10+
jobs:
11+
shellcheck:
12+
name: ShellCheck Analysis
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
- name: Make shellcheck executable
20+
run: chmod +x ./shellcheck
21+
- name: Find all shell scripts
22+
id: find-scripts
23+
run: |
24+
echo "Found shell scripts:"
25+
find . -type f -name "*.sh" -not -path "./.git/*" | tee scripts.txt
26+
- name: Run ShellCheck on all .sh files
27+
run: |
28+
set -e
29+
exit_code=0
30+
31+
echo "=== Running ShellCheck on all shell scripts ==="
32+
33+
while IFS= read -r script; do
34+
echo ""
35+
echo "Checking: $script"
36+
if ./shellcheck "$script"; then
37+
echo "$script passed"
38+
else
39+
echo "$script failed"
40+
exit_code=1
41+
fi
42+
done < scripts.txt
43+
44+
echo ""
45+
if [ $exit_code -eq 0 ]; then
46+
echo "=== All shell scripts passed ShellCheck ==="
47+
else
48+
echo "=== Some shell scripts failed ShellCheck ==="
49+
fi
50+
51+
exit $exit_code
52+
- name: ShellCheck summary
53+
if: always()
54+
run: |-
55+
script_count=$(wc -l < scripts.txt)
56+
echo "Total shell scripts checked: $script_count"

format.bat

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
@echo off
22
setlocal enabledelayedexpansion
33

4-
REM Formats Java and YAML files using Google Java Format and yamlfmt
4+
REM Formats Java, YAML, and Shell files using Google Java Format, yamlfmt, and shfmt
55
REM Windows-native batch script
66

77
REM Security: Ensure we're in the project directory
88
cd /d "%~dp0" || exit /b 1
99

1010
set "YAMLFMT_DIR=yamllint"
11+
set "SHFMT_DIR=shfmt"
1112
set "JAVA_FORMATTER=google-java-format-1.28.0-all-deps.jar"
1213
set "JAVA_SOURCE_DIR=src"
1314
set "EXIT_CODE=0"
@@ -60,12 +61,30 @@ goto :main
6061
)
6162
exit /b 0
6263

64+
:detect_shfmt_binary
65+
set "ARCH=%PROCESSOR_ARCHITECTURE%"
66+
67+
if /i "%ARCH%"=="AMD64" (
68+
set "SHFMT_BINARY=shfmt_v3.12.0_windows_amd64.exe"
69+
) else if /i "%ARCH%"=="X86" (
70+
set "SHFMT_BINARY=shfmt_v3.12.0_windows_386.exe"
71+
) else (
72+
call :log_error "Unsupported Windows architecture for shfmt: %ARCH%"
73+
set "SHFMT_BINARY=unsupported"
74+
)
75+
exit /b 0
76+
6377
:validate_environment
6478
if not exist "%YAMLFMT_DIR%" (
6579
call :log_error "yamlfmt directory not found: %YAMLFMT_DIR%"
6680
exit /b 1
6781
)
6882

83+
if not exist "%SHFMT_DIR%" (
84+
call :log_warning "shfmt directory not found: %SHFMT_DIR%"
85+
call :log_warning "Skipping shell script formatting"
86+
)
87+
6988
if not exist "%JAVA_FORMATTER%" (
7089
call :log_error "Java formatter not found: %JAVA_FORMATTER%"
7190
exit /b 1
@@ -186,6 +205,45 @@ goto :main
186205
call :log_success "YAML files formatted successfully"
187206
exit /b 0
188207

208+
:format_shell
209+
set "SHFMT_PATH=%SHFMT_DIR%\%SHFMT_BINARY%"
210+
211+
call :log_info "Formatting shell script files..."
212+
213+
if not exist "%SHFMT_PATH%" (
214+
call :log_error "shfmt binary not found: %SHFMT_PATH%"
215+
call :log_info "Available binaries in %SHFMT_DIR%:"
216+
dir /b "%SHFMT_DIR%\shfmt_*" 2>nul || call :log_info " None found"
217+
exit /b 1
218+
)
219+
220+
REM Count shell script files
221+
set "SHELL_FILE_COUNT=0"
222+
for /r %%f in (*.sh *.bash) do (
223+
set "FILEPATH=%%f"
224+
echo !FILEPATH! | findstr /i /c:".git" >nul
225+
if errorlevel 1 (
226+
set /a SHELL_FILE_COUNT+=1
227+
)
228+
)
229+
230+
if %SHELL_FILE_COUNT% equ 0 (
231+
call :log_warning "No shell script files found"
232+
exit /b 0
233+
)
234+
235+
call :log_info "Found %SHELL_FILE_COUNT% shell script file(s)"
236+
237+
REM Format shell scripts using shfmt -l -w .
238+
"%SHFMT_PATH%" -l -w . 2>&1
239+
if errorlevel 1 (
240+
call :log_error "Shell script formatting failed"
241+
exit /b 1
242+
)
243+
244+
call :log_success "Shell script files formatted successfully"
245+
exit /b 0
246+
189247
:main
190248
call :log_info "Starting code formatting for the current project"
191249

@@ -201,28 +259,40 @@ goto :main
201259
)
202260

203261
call :detect_yamlfmt_binary
262+
call :detect_shfmt_binary
204263

205264
if "%YAMLFMT_BINARY%"=="unsupported" (
206265
call :log_warning "Platform not supported for yamlfmt"
207266
call :log_warning "Architecture: %PROCESSOR_ARCHITECTURE%"
208-
call :log_warning "Skipping YAML formatting, but continuing with Java formatting"
209-
210-
if %VALIDATE_RESULT% neq 2 (
211-
call :format_java
212-
if errorlevel 1 exit /b 1
213-
)
214-
exit /b 0
267+
call :log_warning "Skipping YAML formatting"
268+
) else (
269+
call :log_info "Using yamlfmt binary: %YAMLFMT_BINARY%"
215270
)
216271

217-
call :log_info "Using yamlfmt binary: %YAMLFMT_BINARY%"
272+
if "%SHFMT_BINARY%"=="unsupported" (
273+
call :log_warning "Platform not supported for shfmt"
274+
call :log_warning "Architecture: %PROCESSOR_ARCHITECTURE%"
275+
call :log_warning "Skipping shell script formatting"
276+
) else (
277+
call :log_info "Using shfmt binary: %SHFMT_BINARY%"
278+
)
218279

219280
if %VALIDATE_RESULT% neq 2 (
220281
call :format_java
221282
if errorlevel 1 exit /b 1
222283
)
223284

224-
call :format_yaml
225-
if errorlevel 1 exit /b 1
285+
if not "%YAMLFMT_BINARY%"=="unsupported" (
286+
call :format_yaml
287+
if errorlevel 1 exit /b 1
288+
)
289+
290+
if not "%SHFMT_BINARY%"=="unsupported" (
291+
if exist "%SHFMT_DIR%" (
292+
call :format_shell
293+
if errorlevel 1 exit /b 1
294+
)
295+
)
226296

227297
echo.
228298
call :log_success "All formatting completed successfully"

0 commit comments

Comments
 (0)