Skip to content

Commit 08b1c03

Browse files
committed
ci: Add bash script syntax check to CI
This commit introduces a new step to the CI workflow (`ci.yml`) that performs a syntax check on all bash scripts within the repository. The new CI job: - Identifies all `.sh` files and files with a bash shebang (`#!/bin/bash` or `#!/usr/bin/env bash`). - Excludes common directories like `node_modules`, `.git`, and `.augment`. - Uses `bash -n` to perform a non-destructive syntax validation for each identified script. - Reports any syntax errors found, providing detailed output to aid in debugging. This addition aims to proactively catch and prevent syntax errors in shell scripts before they are merged, improving code quality and reliability.
1 parent 7577b80 commit 08b1c03

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,60 @@ jobs:
9696
repository: Arksine/moonraker
9797
path: "moonraker"
9898

99+
- name: Bash Syntax Check
100+
run: |
101+
echo "🔍 Finding bash scripts in the repository..."
102+
103+
# Find all .sh files and files with bash shebangs
104+
bash_files=()
105+
106+
# Add all .sh files
107+
while IFS= read -r -d '' file; do
108+
bash_files+=("$file")
109+
done < <(find . -name "*.sh" -type f -not -path "./src/node_modules/*" -not -path "./.git/*" -not -path "./.augment/*" -print0)
110+
111+
# Add files with bash shebangs (excluding .sh files already found)
112+
while IFS= read -r -d '' file; do
113+
# Skip if it's already a .sh file
114+
if [[ "$file" != *.sh ]]; then
115+
bash_files+=("$file")
116+
fi
117+
done < <(find . -type f -not -path "./src/node_modules/*" -not -path "./.git/*" -not -path "./.augment/*" -exec grep -l "^#!/bin/bash\|^#!/usr/bin/env bash" {} \; -print0 2>/dev/null)
118+
119+
if [ ${#bash_files[@]} -eq 0 ]; then
120+
echo "❌ No bash scripts found in the repository"
121+
exit 1
122+
fi
123+
124+
echo "📋 Found ${#bash_files[@]} bash script(s) to validate:"
125+
printf ' - %s\n' "${bash_files[@]}"
126+
echo
127+
128+
# Validate syntax of each script
129+
failed_scripts=()
130+
for script in "${bash_files[@]}"; do
131+
echo "🔍 Checking syntax of: $script"
132+
if bash -n "$script" 2>/dev/null; then
133+
echo "✅ $script - syntax OK"
134+
else
135+
echo "❌ $script - syntax ERROR:"
136+
bash -n "$script" 2>&1 | sed 's/^/ /'
137+
failed_scripts+=("$script")
138+
fi
139+
echo
140+
done
141+
142+
# Report results
143+
if [ ${#failed_scripts[@]} -eq 0 ]; then
144+
echo "🎉 All bash scripts passed syntax validation!"
145+
else
146+
echo "💥 ${#failed_scripts[@]} script(s) failed syntax validation:"
147+
printf ' - %s\n' "${failed_scripts[@]}"
148+
echo
149+
echo "Please fix the syntax errors in the above scripts before merging."
150+
exit 1
151+
fi
152+
99153
- name: Lint
100154
working-directory: ratos-configurator/src
101155
run: pnpm run lint:ci

0 commit comments

Comments
 (0)