Some checks failed
Test / test (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
116 lines
2.6 KiB
Bash
Executable File
116 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
|
source ~/.bashrc
|
|
# Validate Scripts
|
|
# Validate script syntax and check for common issues
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
SCRIPTS_DIR="$PROJECT_ROOT/scripts"
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
log_info() {
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
}
|
|
|
|
log_warn() {
|
|
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
}
|
|
|
|
log_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
validate_syntax() {
|
|
log_info "Validating script syntax..."
|
|
|
|
local errors=0
|
|
local total=0
|
|
|
|
while IFS= read -r -d '' file; do
|
|
total=$((total + 1))
|
|
|
|
# Check bash syntax
|
|
if bash -n "$file" 2>&1; then
|
|
log_info " ✓ $file: Syntax OK"
|
|
else
|
|
errors=$((errors + 1))
|
|
log_error " ✗ $file: Syntax error"
|
|
fi
|
|
done < <(find "$SCRIPTS_DIR" -name "*.sh" -type f -print0)
|
|
|
|
echo ""
|
|
log_info "Syntax validation complete:"
|
|
log_info " Total scripts: $total"
|
|
log_info " Errors: $errors"
|
|
|
|
if [ $errors -eq 0 ]; then
|
|
log_info "✓ All scripts have valid syntax"
|
|
return 0
|
|
else
|
|
log_error "✗ $errors script(s) have syntax errors"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
check_shebangs() {
|
|
log_info "Checking shebangs..."
|
|
|
|
local missing=0
|
|
|
|
while IFS= read -r -d '' file; do
|
|
if ! head -1 "$file" | grep -q "^#!/bin/bash"; then
|
|
missing=$((missing + 1))
|
|
log_warn " Missing or incorrect shebang: $file"
|
|
fi
|
|
done < <(find "$SCRIPTS_DIR" -name "*.sh" -type f -print0)
|
|
|
|
if [ $missing -eq 0 ]; then
|
|
log_info "✓ All scripts have correct shebangs"
|
|
else
|
|
log_warn "⚠ $missing script(s) missing or have incorrect shebangs"
|
|
fi
|
|
}
|
|
|
|
check_executable() {
|
|
log_info "Checking executable permissions..."
|
|
|
|
local not_executable=0
|
|
|
|
while IFS= read -r -d '' file; do
|
|
if [ ! -x "$file" ]; then
|
|
not_executable=$((not_executable + 1))
|
|
log_warn " Not executable: $file"
|
|
fi
|
|
done < <(find "$SCRIPTS_DIR" -name "*.sh" -type f -print0)
|
|
|
|
if [ $not_executable -eq 0 ]; then
|
|
log_info "✓ All scripts are executable"
|
|
else
|
|
log_warn "⚠ $not_executable script(s) are not executable"
|
|
log_info "Run: find scripts/ -name '*.sh' -exec chmod +x {} \\;"
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
log_info "Script Validation"
|
|
echo ""
|
|
|
|
validate_syntax
|
|
echo ""
|
|
check_shebangs
|
|
echo ""
|
|
check_executable
|
|
echo ""
|
|
log_info "Validation complete"
|
|
}
|
|
|
|
main "$@"
|
|
|