@@ -119,49 +119,61 @@ jobs:
119119 path : bandit-report.html
120120 retention-days : 30
121121# -----------------------------
122- # 2) Clamav Scan
122+ # 3) ShellCheck Scan
123123# -----------------------------
124- clamav-scan :
124+ shellcheck_scan :
125+ name : ShellCheck script analysis
125126 runs-on : self-hosted
126127 permissions :
127128 contents : read
128129 steps :
129130 - uses : actions/checkout@v4
130131
131132 - name : Create report directory
132- run : mkdir -p clamav -reports
133+ run : mkdir -p shellcheck -reports
133134
134- - name : Run ClamAV Scan using Docker
135- id : clamav
135+ - name : Install ShellCheck
136+ run : |
137+ # Check if shellcheck is already installed
138+ if ! command -v shellcheck &> /dev/null; then
139+ wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv
140+ sudo cp shellcheck-stable/shellcheck /usr/local/bin/
141+ rm -rf shellcheck-stable
142+ fi
143+ shellcheck --version
144+
145+ - name : Find shell scripts
146+ id : find_scripts
147+ run : |
148+ SCRIPT_COUNT=$(find . -type f -name "*.sh" ! -path "./.git/*" | wc -l)
149+ echo "Shell scripts found: $SCRIPT_COUNT"
150+ echo "script_count=$SCRIPT_COUNT" >> $GITHUB_OUTPUT
151+
152+ - name : Run ShellCheck
153+ if : steps.find_scripts.outputs.script_count > 0
136154 continue-on-error : true
137155 run : |
138- # Pull ClamAV Docker image
139- docker pull clamav/clamav:latest
156+ echo "ShellCheck Analysis Report" > shellcheck-reports/shellcheck-report.txt
157+ echo "==========================" >> shellcheck-reports/shellcheck-report.txt
158+ echo "" >> shellcheck-reports/shellcheck-report.txt
140159
141- # Run ClamAV scan in container
142- docker run --rm \
143- -v ${{ github.workspace }}:/scan:ro \
144- -v ${{ github.workspace }}/clamav-reports:/reports \
145- clamav/clamav:latest \
146- clamscan -r \
147- --exclude-dir=".git" \
148- --exclude-dir="tests" \
149- --exclude-dir=".pytest_cache" \
150- --exclude-dir="__pycache__" \
151- --exclude-dir=".venv" \
152- --exclude-dir="node_modules" \
153- /scan | tee /reports/clamav_scan_report.txt || true
160+ find . -type f -name "*.sh" ! -path "./.git/*" | while read -r script; do
161+ echo "Checking: $script" >> shellcheck-reports/shellcheck-report.txt
162+ shellcheck -f gcc "$script" >> shellcheck-reports/shellcheck-report.txt 2>&1 || true
163+ echo "" >> shellcheck-reports/shellcheck-report.txt
164+ done
154165
155- # Alternatively, if Docker pull fails, skip ClamAV scan
156- if [ $? -ne 0 ]; then
157- echo "ClamAV scan skipped due to installation/network issues" > clamav-reports/clamav_scan_report.txt
158- echo "Status: Skipped" >> clamav-reports/clamav_scan_report.txt
159- echo "Reason: Unable to install or run ClamAV on this runner" >> clamav-reports/clamav_scan_report.txt
160- fi
161-
162- - name : Upload Report
166+ cat shellcheck-reports/shellcheck-report.txt
167+
168+ - name : Create empty report if no scripts
169+ if : steps.find_scripts.outputs.script_count == 0
170+ run : |
171+ echo "ShellCheck Analysis Report" > shellcheck-reports/shellcheck-report.txt
172+ echo "No shell scripts found to analyze." >> shellcheck-reports/shellcheck-report.txt
173+
174+ - name : Upload ShellCheck Report
163175 if : always()
164176 uses : actions/upload-artifact@v4
165177 with :
166- name : clamav -report
167- path : clamav -reports/clamav_scan_report .txt
178+ name : shellcheck -report
179+ path : shellcheck -reports/shellcheck-report .txt
0 commit comments