#!/bin/bash
set -u
SUMMARY_FILE="${GITEA_STEP_SUMMARY:-${GITHUB_STEP_SUMMARY:-}}"
LIGHTHOUSE_REPORT=".davidson-reports/davidson-lighthouse.json"
if [ -z "$SUMMARY_FILE" ]; then
echo "No Actions summary file available"
exit 0
fi
PHP_COUNT="${DAVIDSON_PHP_COUNT:-0}"
JS_COUNT="${DAVIDSON_JS_COUNT:-0}"
TS_COUNT="${DAVIDSON_TS_COUNT:-0}"
CSS_COUNT="${DAVIDSON_CSS_COUNT:-0}"
PHP_STATUS="${DAVIDSON_PHP_STATUS:-UNKNOWN}"
JS_STATUS="${DAVIDSON_JS_STATUS:-UNKNOWN}"
CSS_STATUS="${DAVIDSON_CSS_STATUS:-UNKNOWN}"
LIGHTHOUSE_STATUS="${DAVIDSON_LIGHTHOUSE_STATUS:-UNKNOWN}"
COMPOSER_AUDIT="${DAVIDSON_COMPOSER_AUDIT:-UNKNOWN}"
NPM_AUDIT="${DAVIDSON_NPM_AUDIT:-UNKNOWN}"
SEMGREP="${DAVIDSON_SEMGREP:-UNKNOWN}"
TRIVY_VULN="${DAVIDSON_TRIVY_VULN:-UNKNOWN}"
TRIVY_SECRET="${DAVIDSON_TRIVY_SECRET:-UNKNOWN}"
SECURITY_STATUS="${DAVIDSON_SECURITY_STATUS:-UNKNOWN}"
status_icon() {
case "$1" in
PASS)
echo "✅ PASS"
;;
FAIL)
echo "❌ FAIL"
;;
SKIP)
echo "➖ SKIP"
;;
*)
echo "⚪ UNKNOWN"
;;
esac
}
lighthouse_icon() {
local score="$1"
if [ "$score" -ge 90 ]; then
echo "🟢"
elif [ "$score" -ge 50 ]; then
echo "🟡"
else
echo "🔴"
fi
}
lighthouse_label() {
local score="$1"
if [ "$score" -ge 90 ]; then
echo "Good"
elif [ "$score" -ge 50 ]; then
echo "Fix"
else
echo "Issue"
fi
}
OVERALL="PASS"
for status in \
"$PHP_STATUS" \
"$JS_STATUS" \
"$CSS_STATUS" \
"$LIGHTHOUSE_STATUS" \
"$SECURITY_STATUS"
do
if [ "$status" = "FAIL" ]; then
OVERALL="FAIL"
fi
done
{
echo "# 🛡️ Davidson CI"
echo
if [ "$OVERALL" = "PASS" ]; then
echo "## ✅ Overall: Passed"
echo
echo "No blocking issues were detected."
else
echo "## ❌ Overall: Failed"
echo
echo "One or more checks require attention."
fi
echo
echo "---"
echo
echo "## Lighthouse"
echo
if [ "$LIGHTHOUSE_STATUS" = "SKIP" ]; then
echo "➖ Lighthouse was not run for this project."
echo
elif [ "$LIGHTHOUSE_STATUS" = "FAIL" ]; then
echo "❌ Lighthouse failed to complete."
echo
elif [ ! -f "$LIGHTHOUSE_REPORT" ]; then
echo "⚪ Lighthouse report unavailable."
echo
else
PERFORMANCE_SCORE="$(php -r '
$data = json_decode(file_get_contents($argv[1]), true);
echo $data["scores"]["performance"]["score"] ?? 0;
' "$LIGHTHOUSE_REPORT")"
ACCESSIBILITY_SCORE="$(php -r '
$data = json_decode(file_get_contents($argv[1]), true);
echo $data["scores"]["accessibility"]["score"] ?? 0;
' "$LIGHTHOUSE_REPORT")"
BEST_PRACTICES_SCORE="$(php -r '
$data = json_decode(file_get_contents($argv[1]), true);
echo $data["scores"]["best-practices"]["score"] ?? 0;
' "$LIGHTHOUSE_REPORT")"
SEO_SCORE="$(php -r '
$data = json_decode(file_get_contents($argv[1]), true);
echo $data["scores"]["seo"]["score"] ?? 0;
' "$LIGHTHOUSE_REPORT")"
FINDING_COUNT="$(php -r '
$data = json_decode(file_get_contents($argv[1]), true);
echo count($data["findings"] ?? []);
' "$LIGHTHOUSE_REPORT")"
echo "| Category | Score | Status |"
echo "|---|---:|---|"
echo "| Performance | $PERFORMANCE_SCORE | $(lighthouse_icon "$PERFORMANCE_SCORE") $(lighthouse_label "$PERFORMANCE_SCORE") |"
echo "| Accessibility | $ACCESSIBILITY_SCORE | $(lighthouse_icon "$ACCESSIBILITY_SCORE") $(lighthouse_label "$ACCESSIBILITY_SCORE") |"
echo "| Best Practices | $BEST_PRACTICES_SCORE | $(lighthouse_icon "$BEST_PRACTICES_SCORE") $(lighthouse_label "$BEST_PRACTICES_SCORE") |"
echo "| SEO | $SEO_SCORE | $(lighthouse_icon "$SEO_SCORE") $(lighthouse_label "$SEO_SCORE") |"
echo
if [ "$FINDING_COUNT" -gt 0 ]; then
echo ""
echo "⚠️ Lighthouse findings ($FINDING_COUNT)
"
echo
php -r '
$data = json_decode(file_get_contents($argv[1]), true);
foreach ($data["findings"] ?? [] as $finding) {
$title = $finding["title"] ?? "Lighthouse finding";
$categories = implode(", ", $finding["categories"] ?? []);
$score = $finding["score"] ?? null;
$impact = $finding["impact"] ?? null;
$problem = $finding["problem"] ?? "";
echo "### " . $title . PHP_EOL;
echo PHP_EOL;
if ($categories !== "") {
echo "**Category:** " . $categories . PHP_EOL;
}
if ($score !== null) {
echo "**Score:** " . $score . PHP_EOL;
}
if ($impact !== null && $impact !== "") {
echo "**Impact:** " . $impact . PHP_EOL;
}
if ($problem !== "") {
echo PHP_EOL . $problem . PHP_EOL;
}
echo PHP_EOL . "---" . PHP_EOL . PHP_EOL;
}
' "$LIGHTHOUSE_REPORT"
echo " "
echo
else
echo "✅ No Lighthouse findings."
echo
fi
fi
echo "---"
echo
echo "## Code Quality"
echo
echo "| Module | Status |"
echo "|---|---|"
echo "| PHP | $(status_icon "$PHP_STATUS") |"
echo "| JavaScript / TypeScript | $(status_icon "$JS_STATUS") |"
echo "| CSS | $(status_icon "$CSS_STATUS") |"
echo
echo "## Security"
echo
echo "| Check | Status |"
echo "|---|---|"
echo "| Composer audit | $(status_icon "$COMPOSER_AUDIT") |"
echo "| npm audit | $(status_icon "$NPM_AUDIT") |"
echo "| Semgrep | $(status_icon "$SEMGREP") |"
echo "| Trivy vulnerabilities | $(status_icon "$TRIVY_VULN") |"
echo "| Trivy secrets | $(status_icon "$TRIVY_SECRET") |"
echo
echo ""
echo "Project detection
"
echo
echo "| Language | Files |"
echo "|---|---:|"
echo "| PHP | $PHP_COUNT |"
echo "| JavaScript | $JS_COUNT |"
echo "| TypeScript | $TS_COUNT |"
echo "| CSS | $CSS_COUNT |"
echo
echo " "
echo
} >> "$SUMMARY_FILE"
echo "Davidson CI report generated"