Add enterprise features: timeout handling, duration tracking, and health checking
- Add timeout handling to PHP syntax validation - Add execution duration tracking to smoke_test and validate_all - Create script_health.sh to validate enterprise standards compliance - Enhance error messages with better context and actionable guidance - Add log_duration helper function to common.sh - Update ENTERPRISE.md and README.md with new features - All scripts now follow complete enterprise standards Co-authored-by: jmiller-moko <230051081+jmiller-moko@users.noreply.github.com>
This commit is contained in:
@@ -35,6 +35,9 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Input validation
|
||||
SRC_DIR="${SRC_DIR:-src}"
|
||||
|
||||
log() { printf '%s\n' "$*"; }
|
||||
|
||||
fail() {
|
||||
@@ -42,10 +45,14 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
SRC_DIR="${SRC_DIR:-src}"
|
||||
|
||||
# Validate SRC_DIR
|
||||
if [ ! -d "${SRC_DIR}" ]; then
|
||||
fail "${SRC_DIR} directory missing"
|
||||
fail "${SRC_DIR} directory missing. Set SRC_DIR environment variable or ensure 'src' directory exists."
|
||||
fi
|
||||
|
||||
# Validate required dependencies
|
||||
if ! command -v python3 >/dev/null 2>&1; then
|
||||
fail "python3 is required but not found. Please install Python 3."
|
||||
fi
|
||||
|
||||
# Candidate discovery policy: prefer explicit known names, otherwise fall back to extension-root manifests.
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Validation timeout (seconds) - prevents hanging on problematic files
|
||||
TIMEOUT="${VALIDATION_TIMEOUT:-30}"
|
||||
SRC_DIR="${SRC_DIR:-src}"
|
||||
|
||||
json_escape() {
|
||||
@@ -56,17 +58,34 @@ fi
|
||||
|
||||
failed=0
|
||||
checked=0
|
||||
failed_files=()
|
||||
|
||||
while IFS= read -r -d '' f; do
|
||||
checked=$((checked+1))
|
||||
if ! php -l "$f" >/dev/null; then
|
||||
failed=1
|
||||
|
||||
# Use timeout if available to prevent hangs
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
if ! timeout "${TIMEOUT}" php -l "$f" >/dev/null 2>&1; then
|
||||
failed=1
|
||||
failed_files+=("$f")
|
||||
fi
|
||||
else
|
||||
if ! php -l "$f" >/dev/null 2>&1; then
|
||||
failed=1
|
||||
failed_files+=("$f")
|
||||
fi
|
||||
fi
|
||||
done < <(find "${SRC_DIR}" -type f -name '*.php' -print0)
|
||||
|
||||
if [ "${failed}" -ne 0 ]; then
|
||||
printf '{"status":"fail","error":"php_lint_failed","files_checked":%s}
|
||||
' "${checked}"
|
||||
{
|
||||
printf '{"status":"fail","error":"php_lint_failed","files_checked":%s,"failed_count":%s,"failed_files":[' "${checked}" "${#failed_files[@]}"
|
||||
for i in "${!failed_files[@]}"; do
|
||||
printf '%s' "$(json_escape "${failed_files[$i]}")"
|
||||
[ "$i" -lt $((${#failed_files[@]} - 1)) ] && printf ','
|
||||
done
|
||||
printf ']}\n'
|
||||
}
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user