Skip to content

Commit e1af1c4

Browse files
Improve plugin check summary readability - parse JSON into clean messages
1 parent e71cf21 commit e1af1c4

1 file changed

Lines changed: 117 additions & 53 deletions

File tree

.github/workflows/plugin-check.yml

Lines changed: 117 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -54,75 +54,139 @@ jobs:
5454
exit 0
5555
fi
5656
57-
# === HIGH RISK: Issues that can get your plugin closed or suspended ===
58-
echo "### 🚨 HIGH RISK — Can cause plugin closure or suspension" >> $GITHUB_STEP_SUMMARY
59-
echo "" >> $GITHUB_STEP_SUMMARY
60-
61-
HIGH_RISK_PATTERNS=(
62-
"Plugin Updater detected"
63-
"Missing.*License.*Plugin Header"
64-
"restricted term"
65-
"trademarked_term"
66-
"trademarks"
67-
"Unescaped parameter.*\\$wpdb"
68-
"Use placeholders and.*\\$wpdb->prepare"
69-
"code_obfuscation"
70-
"plugin_updater"
71-
"no_unfiltered_uploads"
57+
PARSED=$(python3 << 'PYEOF'
58+
import json, sys, re
59+
60+
high_risk_codes = [
61+
"plugin_updater", "code_obfuscation", "no_unfiltered_uploads",
62+
"trademarked_term", "trademarks"
63+
]
64+
high_risk_messages = [
65+
"Plugin Updater detected", "Missing.*License.*Plugin Header",
66+
"restricted term", "Unescaped parameter.*\\$wpdb",
67+
"Use placeholders and.*\\$wpdb->prepare"
68+
]
69+
medium_risk_codes = [
70+
"missing_direct_file_access_protection", "trunk_stable_tag",
71+
"mismatched_plugin_name", "application_detected"
72+
]
73+
medium_risk_messages = [
74+
"Missing.*\\$domain.*parameter", "has been deprecated",
75+
"wp_get_sites", "cURL functions is highly discouraged"
76+
]
77+
78+
high, medium, other = [], [], []
79+
80+
try:
81+
with open("${RUNNER_TEMP}/plugin-check-results.txt", "r") as f:
82+
content = f.read().strip()
83+
84+
all_issues = []
85+
try:
86+
data = json.loads(content)
87+
if isinstance(data, list):
88+
all_issues = data
89+
elif isinstance(data, dict):
90+
for fp, issues in data.items():
91+
if isinstance(issues, list):
92+
for issue in issues:
93+
issue['_file'] = fp
94+
all_issues.append(issue)
95+
except json.JSONDecodeError:
96+
for line in content.split('\n'):
97+
line = line.strip()
98+
if not line: continue
99+
try:
100+
parsed = json.loads(line)
101+
if isinstance(parsed, list): all_issues.extend(parsed)
102+
elif isinstance(parsed, dict): all_issues.append(parsed)
103+
except json.JSONDecodeError: continue
104+
105+
for issue in all_issues:
106+
code = issue.get('code', '')
107+
msg = issue.get('message', '')
108+
itype = issue.get('type', 'ERROR')
109+
line_num = issue.get('line', 0)
110+
file_path = issue.get('_file', '')
111+
112+
prefix = "❌" if itype == "ERROR" else "⚠️"
113+
location = ""
114+
if file_path:
115+
location = f" ({file_path}"
116+
if line_num and line_num > 0: location += f", line {line_num}"
117+
location += ")"
118+
elif line_num and line_num > 0:
119+
location = f" (line {line_num})"
120+
121+
readable = f"{prefix} {msg}{location}"
122+
123+
is_high = code in high_risk_codes
124+
if not is_high:
125+
for p in high_risk_messages:
126+
if re.search(p, msg, re.IGNORECASE): is_high = True; break
127+
128+
is_medium = code in medium_risk_codes
129+
if not is_medium and not is_high:
130+
for p in medium_risk_messages:
131+
if re.search(p, msg, re.IGNORECASE): is_medium = True; break
132+
133+
if is_high: high.append(readable)
134+
elif is_medium: medium.append(readable)
135+
else: other.append(readable)
136+
137+
def dedup(lst):
138+
seen = set(); result = []
139+
for item in lst:
140+
if item not in seen: seen.add(item); result.append(item)
141+
return result
142+
143+
high, medium, other = dedup(high), dedup(medium), dedup(other)
144+
145+
print("---HIGH---")
146+
for i in high: print(i)
147+
print("---MEDIUM---")
148+
for i in medium: print(i)
149+
print("---OTHER---")
150+
for i in other: print(i)
151+
print("---COUNTS---")
152+
print(f"{len(high)}|{len(medium)}|{len(other)}")
153+
except Exception as e:
154+
print(f"Parse error: {e}", file=sys.stderr)
155+
print("---HIGH---\n---MEDIUM---\n---OTHER---\n---COUNTS---\n0|0|0")
156+
PYEOF
72157
)
73158
74-
HIGH_RISK_REGEX=$(IFS='|'; echo "${HIGH_RISK_PATTERNS[*]}")
75-
HIGH_RISK_FOUND=$(grep -iE "$HIGH_RISK_REGEX" "$RESULTS_FILE" || true)
159+
HIGH_SECTION=$(echo "$PARSED" | sed -n '/^---HIGH---$/,/^---MEDIUM---$/p' | sed '1d;$d')
160+
MEDIUM_SECTION=$(echo "$PARSED" | sed -n '/^---MEDIUM---$/,/^---OTHER---$/p' | sed '1d;$d')
161+
OTHER_SECTION=$(echo "$PARSED" | sed -n '/^---OTHER---$/,/^---COUNTS---$/p' | sed '1d;$d')
162+
COUNTS=$(echo "$PARSED" | tail -1)
163+
OTHER_COUNT=$(echo "$COUNTS" | cut -d'|' -f3)
76164
77-
if [ -n "$HIGH_RISK_FOUND" ]; then
78-
echo '```' >> $GITHUB_STEP_SUMMARY
79-
echo "$HIGH_RISK_FOUND" | sort -u >> $GITHUB_STEP_SUMMARY
80-
echo '```' >> $GITHUB_STEP_SUMMARY
165+
echo "### 🚨 HIGH RISK — Can cause plugin closure or suspension" >> $GITHUB_STEP_SUMMARY
166+
echo "" >> $GITHUB_STEP_SUMMARY
167+
if [ -n "$HIGH_SECTION" ]; then
168+
echo "$HIGH_SECTION" >> $GITHUB_STEP_SUMMARY
81169
else
82170
echo "✅ No high-risk issues found." >> $GITHUB_STEP_SUMMARY
83171
fi
84-
85172
echo "" >> $GITHUB_STEP_SUMMARY
86173
87-
# === MEDIUM RISK: Issues wordpress.org reviews flag ===
88174
echo "### ⚠️ MEDIUM RISK — Commonly flagged in wordpress.org reviews" >> $GITHUB_STEP_SUMMARY
89175
echo "" >> $GITHUB_STEP_SUMMARY
90-
91-
MEDIUM_RISK_PATTERNS=(
92-
"missing_direct_file_access_protection"
93-
"trunk_stable_tag"
94-
"mismatched_plugin_name"
95-
"Missing.*\\$domain.*parameter"
96-
"has been deprecated"
97-
"wp_get_sites"
98-
"curl_curl_"
99-
"WordPress.WP.AlternativeFunctions"
100-
"application_detected"
101-
)
102-
103-
MEDIUM_RISK_REGEX=$(IFS='|'; echo "${MEDIUM_RISK_PATTERNS[*]}")
104-
MEDIUM_RISK_FOUND=$(grep -iE "$MEDIUM_RISK_REGEX" "$RESULTS_FILE" || true)
105-
106-
if [ -n "$MEDIUM_RISK_FOUND" ]; then
107-
echo '```' >> $GITHUB_STEP_SUMMARY
108-
echo "$MEDIUM_RISK_FOUND" | sort -u >> $GITHUB_STEP_SUMMARY
109-
echo '```' >> $GITHUB_STEP_SUMMARY
176+
if [ -n "$MEDIUM_SECTION" ]; then
177+
echo "$MEDIUM_SECTION" >> $GITHUB_STEP_SUMMARY
110178
else
111179
echo "✅ No medium-risk issues found." >> $GITHUB_STEP_SUMMARY
112180
fi
113-
114181
echo "" >> $GITHUB_STEP_SUMMARY
115182
116-
# === ALL OTHER ISSUES (collapsed) ===
117-
TOTAL=$(wc -l < "$RESULTS_FILE" | tr -d ' ')
118-
HIGH_COUNT=$(echo "$HIGH_RISK_FOUND" | grep -c '.' || echo "0")
119-
MEDIUM_COUNT=$(echo "$MEDIUM_RISK_FOUND" | grep -c '.' || echo "0")
120-
OTHER_COUNT=$((TOTAL - HIGH_COUNT - MEDIUM_COUNT))
121-
122183
echo "<details>" >> $GITHUB_STEP_SUMMARY
123184
echo "<summary>📋 Other issues ($OTHER_COUNT) — click to expand</summary>" >> $GITHUB_STEP_SUMMARY
124185
echo "" >> $GITHUB_STEP_SUMMARY
125-
echo '```' >> $GITHUB_STEP_SUMMARY
126-
grep -ivE "$HIGH_RISK_REGEX|$MEDIUM_RISK_REGEX" "$RESULTS_FILE" >> $GITHUB_STEP_SUMMARY || true
127-
echo '```' >> $GITHUB_STEP_SUMMARY
186+
if [ -n "$OTHER_SECTION" ]; then
187+
echo "$OTHER_SECTION" >> $GITHUB_STEP_SUMMARY
188+
else
189+
echo "No other issues." >> $GITHUB_STEP_SUMMARY
190+
fi
191+
echo "" >> $GITHUB_STEP_SUMMARY
128192
echo "</details>" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)