Skip to content

Commit 70623c5

Browse files
committed
feat(ci): optimize shell script validation with parallel processing
• Implement parallel validation using xargs -P for faster execution • Determine optimal parallelism based on CPU cores (max 8 for GitHub Actions) • Replace serial for-loop with parallel processing to reduce CI execution time • Add proper error handling and exit code propagation in parallel execution • Maintain clear error reporting that identifies which specific scripts failed • Use temporary files to collect validation results from parallel processes • Export validation function for use by xargs subprocess execution • Preserve existing validation behavior and error message formatting Performance Improvements: - Parallel execution scales with available CPU cores - Significantly faster validation for repositories with many shell scripts - Optimal resource utilization without overwhelming GitHub Actions runners - Maintains backward compatibility with existing script validation expectations Technical Implementation: - Use nproc to detect available CPU cores, capped at 8 for stability - Export bash function for subprocess access in parallel execution - Temporary files for result aggregation from parallel processes - Proper cleanup of temporary files regardless of success/failure outcome - Clear progress indication with parallel process count logging
1 parent cc4f7d8 commit 70623c5

File tree

1 file changed

+48
-8
lines changed

1 file changed

+48
-8
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,31 +127,71 @@ jobs:
127127
printf ' - %s\n' "${bash_files[@]}"
128128
echo
129129
130-
# Validate syntax of each script
131-
failed_scripts=()
132-
for script in "${bash_files[@]}"; do
130+
# Create a temporary file to store validation results
131+
validation_results=$(mktemp)
132+
validation_errors=$(mktemp)
133+
134+
# Function to validate a single script (will be used by xargs)
135+
validate_script() {
136+
local script="$1"
137+
local results_file="$2"
138+
local errors_file="$3"
139+
133140
echo "🔍 Checking syntax of: $script"
134141
if bash -n "$script" 2>/dev/null; then
135142
echo "✅ $script - syntax OK"
143+
echo "$script:OK" >> "$results_file"
136144
else
137145
echo "❌ $script - syntax ERROR:"
138146
bash -n "$script" 2>&1 | sed 's/^/ /'
139-
failed_scripts+=("$script")
147+
echo "$script:ERROR" >> "$results_file"
148+
echo "$script" >> "$errors_file"
140149
fi
141150
echo
142-
done
151+
}
152+
153+
# Export the function so xargs can use it
154+
export -f validate_script
155+
156+
# Determine optimal parallelism (use number of CPU cores, max 8 to avoid overwhelming GitHub Actions)
157+
max_parallel=$(nproc)
158+
if [ "$max_parallel" -gt 8 ]; then
159+
max_parallel=8
160+
fi
161+
162+
echo "🚀 Running validation in parallel (max $max_parallel processes)..."
163+
echo
164+
165+
# Run validation in parallel using xargs
166+
printf '%s\n' "${bash_files[@]}" | xargs -I {} -P "$max_parallel" bash -c 'validate_script "$@"' _ {} "$validation_results" "$validation_errors"
167+
168+
# Read results and count failures
169+
failed_count=0
170+
if [ -f "$validation_errors" ]; then
171+
failed_count=$(wc -l < "$validation_errors" 2>/dev/null || echo 0)
172+
fi
143173
144174
# Report results
145-
if [ ${#failed_scripts[@]} -eq 0 ]; then
175+
if [ "$failed_count" -eq 0 ]; then
146176
echo "🎉 All bash scripts passed syntax validation!"
147177
else
148-
echo "💥 ${#failed_scripts[@]} script(s) failed syntax validation:"
149-
printf ' - %s\n' "${failed_scripts[@]}"
178+
echo "💥 $failed_count script(s) failed syntax validation:"
179+
if [ -f "$validation_errors" ]; then
180+
while IFS= read -r failed_script; do
181+
echo " - $failed_script"
182+
done < "$validation_errors"
183+
fi
150184
echo
151185
echo "Please fix the syntax errors in the above scripts before merging."
186+
187+
# Cleanup temporary files
188+
rm -f "$validation_results" "$validation_errors"
152189
exit 1
153190
fi
154191
192+
# Cleanup temporary files
193+
rm -f "$validation_results" "$validation_errors"
194+
155195
- name: Lint
156196
working-directory: ratos-configurator/src
157197
run: pnpm run lint:ci

0 commit comments

Comments
 (0)