-
Notifications
You must be signed in to change notification settings - Fork 37
229 lines (198 loc) · 8.49 KB
/
Copy pathplugin-check.yml
File metadata and controls
229 lines (198 loc) · 8.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
name: WordPress Plugin Check
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
plugin-check:
name: WordPress.org Guidelines Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Neutralize wp-env override
run: |
echo '{}' > .wp-env.override.json
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 20
cache: 'npm'
- name: Install npm dependencies
run: npm ci
- name: Build assets
run: npm run build
- name: Install Composer dependencies
run: composer install --no-dev --optimize-autoloader
- uses: wordpress/plugin-check-action@v1
id: plugin-check
with:
categories: plugin_repo,security,general
exclude-directories: |
node_modules
vendor
build
tests
bin
.github
ignore-codes: |
WordPress.WP.I18n.TextDomainMismatch
textdomain_mismatch
hidden_files
WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound
WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
WordPress.WP.EnqueuedResourceParameters.MissingVersion
include-experimental: true
repo-token: ''
- name: Plugin Check Summary
if: always()
env:
RESULTS_FILE: ${{ runner.temp }}/plugin-check-results.txt
run: |
echo "## WordPress Plugin Check Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ ! -s "$RESULTS_FILE" ]; then
echo "No results file found or file is empty." >> $GITHUB_STEP_SUMMARY
echo "Check the action logs for details." >> $GITHUB_STEP_SUMMARY
exit 0
fi
PARSED=$(RESULTS_FILE="$RESULTS_FILE" python3 << 'PYEOF'
import json, os, re
results_path = os.environ["RESULTS_FILE"]
high_risk_codes = [
"plugin_updater", "code_obfuscation", "no_unfiltered_uploads",
"trademarked_term", "trademarks"
]
high_risk_messages = [
r"Plugin Updater detected", r"Missing.*License.*Plugin Header",
r"restricted term", r"Unescaped parameter.*\$wpdb",
r"Use placeholders and.*\$wpdb->prepare"
]
medium_risk_codes = [
"missing_direct_file_access_protection", "trunk_stable_tag",
"mismatched_plugin_name", "application_detected"
]
medium_risk_messages = [
r"Missing.*\$domain.*parameter", r"has been deprecated",
r"wp_get_sites", r"cURL functions is highly discouraged"
]
high, medium, other = [], [], []
try:
with open(results_path, "r") as f:
content = f.read().strip()
all_issues = []
try:
data = json.loads(content)
if isinstance(data, list):
all_issues = data
elif isinstance(data, dict):
for fp, issues in data.items():
if isinstance(issues, list):
for issue in issues:
issue['_file'] = fp
all_issues.append(issue)
except json.JSONDecodeError:
for line in content.split('\n'):
line = line.strip()
if not line:
continue
try:
parsed = json.loads(line)
if isinstance(parsed, list):
all_issues.extend(parsed)
elif isinstance(parsed, dict):
all_issues.append(parsed)
except json.JSONDecodeError:
continue
for issue in all_issues:
code = issue.get('code', '')
msg = issue.get('message', '')
itype = issue.get('type', 'ERROR')
line_num = issue.get('line', 0)
file_path = issue.get('_file', '')
prefix = "❌" if itype == "ERROR" else "⚠️"
location = ""
if file_path:
location = f" ({file_path}"
if line_num and line_num > 0:
location += f", line {line_num}"
location += ")"
elif line_num and line_num > 0:
location = f" (line {line_num})"
readable = f"{prefix} {msg}{location}"
is_high = code in high_risk_codes
if not is_high:
for p in high_risk_messages:
if re.search(p, msg, re.IGNORECASE):
is_high = True
break
is_medium = code in medium_risk_codes
if not is_medium and not is_high:
for p in medium_risk_messages:
if re.search(p, msg, re.IGNORECASE):
is_medium = True
break
if is_high:
high.append(readable)
elif is_medium:
medium.append(readable)
else:
other.append(readable)
def dedup(lst):
seen = set()
result = []
for item in lst:
if item not in seen:
seen.add(item)
result.append(item)
return result
high, medium, other = dedup(high), dedup(medium), dedup(other)
print("---HIGH---")
for i in high: print(i)
print("---MEDIUM---")
for i in medium: print(i)
print("---OTHER---")
for i in other: print(i)
print("---COUNTS---")
print(f"{len(high)}|{len(medium)}|{len(other)}")
except Exception as e:
print(f"Parse error: {e}", file=__import__('sys').stderr)
print("---HIGH---\n---MEDIUM---\n---OTHER---\n---COUNTS---\n0|0|0")
PYEOF
)
HIGH_SECTION=$(echo "$PARSED" | sed -n '/^---HIGH---$/,/^---MEDIUM---$/p' | sed '1d;$d')
MEDIUM_SECTION=$(echo "$PARSED" | sed -n '/^---MEDIUM---$/,/^---OTHER---$/p' | sed '1d;$d')
OTHER_SECTION=$(echo "$PARSED" | sed -n '/^---OTHER---$/,/^---COUNTS---$/p' | sed '1d;$d')
COUNTS=$(echo "$PARSED" | tail -1)
OTHER_COUNT=$(echo "$COUNTS" | cut -d'|' -f3)
echo "### 🚨 HIGH RISK — Can cause plugin closure or suspension" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -n "$HIGH_SECTION" ]; then
echo "$HIGH_SECTION" >> $GITHUB_STEP_SUMMARY
else
echo "✅ No high-risk issues found." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### ⚠️ MEDIUM RISK — Commonly flagged in wordpress.org reviews" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -n "$MEDIUM_SECTION" ]; then
echo "$MEDIUM_SECTION" >> $GITHUB_STEP_SUMMARY
else
echo "✅ No medium-risk issues found." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "<details>" >> $GITHUB_STEP_SUMMARY
echo "<summary>📋 Other issues ($OTHER_COUNT) — click to expand</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -n "$OTHER_SECTION" ]; then
echo "$OTHER_SECTION" >> $GITHUB_STEP_SUMMARY
else
echo "No other issues." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY