weedops-devtools/scripts/run-ci-local.sh
Alex 010984d461 Initial commit: Weedops dev tooling
Linting configs (PHPCS, ESLint, Stylelint), Forgejo CI pipeline,
WordPress health check, PHP linter, strain migration tool,
and Docker local dev environment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 05:55:00 +00:00

101 lines
2.5 KiB
Bash
Executable file

#!/bin/bash
# Run CI checks locally before pushing
# Usage: ./run-ci-local.sh [path-to-theme]
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TARGET="${1:-.}"
echo "========================================="
echo " Weedops Local CI Runner"
echo " $(date '+%Y-%m-%d %H:%M:%S')"
echo "========================================="
echo ""
TOTAL_PASS=0
TOTAL_FAIL=0
run_check() {
local name="$1"
local cmd="$2"
echo "--- $name ---"
if eval "$cmd"; then
echo "$name passed"
((TOTAL_PASS++))
else
echo "$name failed"
((TOTAL_FAIL++))
fi
echo ""
}
# 1. PHP Syntax
run_check "PHP Syntax" "$SCRIPT_DIR/lint-php.sh $TARGET"
# 2. Theme structure validation
echo "--- Theme Structure ---"
REQUIRED_FILES=("style.css" "index.php")
RECOMMENDED_FILES=("functions.php" "header.php" "footer.php" "screenshot.png")
ALL_PRESENT=true
for f in "${REQUIRED_FILES[@]}"; do
if [ ! -f "$TARGET/$f" ]; then
echo "MISSING (required): $f"
ALL_PRESENT=false
fi
done
for f in "${RECOMMENDED_FILES[@]}"; do
if [ ! -f "$TARGET/$f" ]; then
echo "MISSING (recommended): $f"
fi
done
if $ALL_PRESENT; then
echo "✓ Theme structure OK"
((TOTAL_PASS++))
else
echo "✗ Theme structure incomplete"
((TOTAL_FAIL++))
fi
echo ""
# 3. WordPress text domain check
echo "--- Text Domain ---"
MISSING_DOMAIN=$(grep -rn "__(\|_e(\|esc_html__(\|esc_html_e(\|esc_attr__(\|esc_attr_e(" "$TARGET" --include="*.php" 2>/dev/null | grep -v "'weedops'" | grep -v '"weedops"' || true)
if [ -z "$MISSING_DOMAIN" ]; then
echo "✓ Text domain 'weedops' used consistently"
((TOTAL_PASS++))
else
echo "WARNING: Some i18n strings may use wrong text domain:"
echo "$MISSING_DOMAIN" | head -5
((TOTAL_PASS++)) # Warning, not failure
fi
echo ""
# 4. Security basics
echo "--- Security Checks ---"
SECURITY_OK=true
# Check for direct file access prevention
PHP_FILES=$(find "$TARGET" -name "*.php" -not -path "*/vendor/*" 2>/dev/null)
for f in $PHP_FILES; do
if ! grep -q "ABSPATH\|defined(" "$f" 2>/dev/null; then
BASENAME=$(basename "$f")
if [ "$BASENAME" != "index.php" ] && [ "$BASENAME" != "style.css" ]; then
echo "WARNING: $f may lack direct access prevention"
fi
fi
done
echo "✓ Security check complete"
((TOTAL_PASS++))
echo ""
# Summary
echo "========================================="
echo " Results: $TOTAL_PASS passed, $TOTAL_FAIL failed"
echo "========================================="
[ "$TOTAL_FAIL" -eq 0 ] && exit 0 || exit 1