From de6e4391c618d4598795d1dbbeb31c8218ab7fa6 Mon Sep 17 00:00:00 2001 From: Floze <88098863+floze-the-genius@users.noreply.github.com> Date: Fri, 14 Aug 2026 15:27:45 +0400 Subject: [PATCH] fix: validate rendered README media --- scripts/audit.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++--- tests/run.sh | 60 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 3 deletions(-) diff --git a/scripts/audit.sh b/scripts/audit.sh index 10f5079..b50a385 100644 --- a/scripts/audit.sh +++ b/scripts/audit.sh @@ -67,6 +67,65 @@ check_any() { fi } +# Print only README content that can render: HTML comments and fenced examples +# must not satisfy audit checks merely by mentioning image or badge syntax. +rendered_readme() { + if [ ! -f "$REPO/README.md" ]; then + return 0 + fi + + awk ' + BEGIN { in_comment = 0; fence = "" } + { + line = $0 + + while (1) { + if (in_comment) { + comment_end = index(line, "-->") + if (comment_end == 0) { + line = "" + break + } + line = substr(line, comment_end + 3) + in_comment = 0 + } + + comment_start = index(line, "") + if (comment_end == 0) { + line = before_comment + in_comment = 1 + break + } + line = before_comment substr(after_comment, comment_end + 3) + } + + if (fence == "backtick") { + if (line ~ /^[[:space:]]*```/) fence = "" + next + } + if (fence == "tilde") { + if (line ~ /^[[:space:]]*~~~/) fence = "" + next + } + if (line ~ /^[[:space:]]*```/) { + fence = "backtick" + next + } + if (line ~ /^[[:space:]]*~~~/) { + fence = "tilde" + next + } + + print line + } + ' "$REPO/README.md" 2>/dev/null +} + echo "" bold "OSS Audit: $REPO" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" @@ -107,8 +166,9 @@ check_any "CI workflow (test/build/lint)" "Copy a starter from $TPL/.github/work echo "" bold "── README Quality ──" +README_RENDERED="$(rendered_readme)" TOTAL=$((TOTAL + 1)) -if grep -qi "demo\|screenshot\|gif" "$REPO/README.md" 2>/dev/null; then +if grep -Eqi '!\[[^]]*\]\([^)]+\.(gif|png|jpe?g|webp|svg)([?#][^)]*)?\)|]*src[[:space:]]*=' <<<"$README_RENDERED"; then green " $PASS README references a demo/screenshot" SCORE=$((SCORE + 1)) else @@ -126,11 +186,11 @@ else fi TOTAL=$((TOTAL + 1)) -if grep -q "img.shields.io\|badge\|actions/workflows" "$REPO/README.md" 2>/dev/null; then +if grep -Eqi '\[!\[[^]]*\]\([^)]+\)\]\([^)]+\)|!\[[^]]*\]\([^)]*(img\.shields\.io|badge|actions/workflows|contrib\.rocks)[^)]*\)' <<<"$README_RENDERED"; then green " $PASS README has badges" SCORE=$((SCORE + 1)) else - yellow " $WARN README missing build/license badges" + red " $FAIL README missing build/license badges" yellow " Fix: add a badges row at the top (see references/github-metadata.md)" fi diff --git a/tests/run.sh b/tests/run.sh index e7578bf..fc610d7 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -16,6 +16,8 @@ TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT FAILURES=0 +PASS_SYMBOL="✓" +FAIL_SYMBOL="✗" score_of() { # score_of -> numeric score out of 16 bash "$ROOT/scripts/audit.sh" "$1" 2>&1 | sed -n 's/.*Score: \([0-9]\+\)\/16.*/\1/p' @@ -32,6 +34,17 @@ assert_score() { # assert_score