-
Notifications
You must be signed in to change notification settings - Fork 0
394 lines (351 loc) · 11.9 KB
/
ci.yml
File metadata and controls
394 lines (351 loc) · 11.9 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
lint-python:
name: Lint Python examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install linting tools
run: pip install ruff
- name: Check Python syntax and style
run: ruff check articles/*/python/ --select=E,F,W --ignore=E501
lint-node:
name: Lint Node.js examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Check JavaScript syntax
run: |
npm install -g acorn
find articles/*/node -name "*.js" -exec acorn --ecma2020 {} \;
lint-php:
name: Lint PHP examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
- name: Check PHP syntax
run: find articles/*/php -name "*.php" -exec php -l {} \;
lint-go:
name: Lint Go examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Check Go syntax
run: |
errors=0
for dir in articles/*/go; do
if [ -f "$dir/solve.go" ]; then
cd "$dir"
if [ -f "go.mod" ]; then
go vet ./... 2>&1 || errors=$((errors + 1))
else
gofmt -e solve.go > /dev/null 2>&1 || errors=$((errors + 1))
fi
cd - > /dev/null
fi
done
if [ $errors -gt 0 ]; then
echo "Found $errors Go errors"
exit 1
fi
echo "All Go examples pass syntax check"
lint-ruby:
name: Lint Ruby examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
- name: Check Ruby syntax
run: find articles/*/ruby -name "*.rb" -exec ruby -c {} \;
lint-bash:
name: Lint Bash examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install ShellCheck
run: sudo apt-get install -y shellcheck
- name: Check Bash syntax
run: |
errors=0
for f in articles/*/bash/solve.sh; do
if [ -f "$f" ]; then
bash -n "$f" 2>&1 || errors=$((errors + 1))
shellcheck -S warning "$f" 2>&1 || true
fi
done
if [ $errors -gt 0 ]; then
echo "Found $errors Bash syntax errors"
exit 1
fi
echo "All Bash examples pass syntax check"
lint-java:
name: Lint Java examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"
- name: Check Java syntax
run: |
errors=0
for f in articles/*/java/Solve.java; do
if [ -f "$f" ]; then
javac -d /tmp/java_check "$f" 2>&1 || errors=$((errors + 1))
rm -rf /tmp/java_check/*
fi
done
if [ $errors -gt 0 ]; then
echo "Found $errors Java compilation errors"
exit 1
fi
echo "All Java examples compile"
lint-kotlin:
name: Lint Kotlin examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Kotlin
run: |
curl -sL https://github.com/JetBrains/kotlin/releases/download/v1.9.24/kotlin-compiler-1.9.24.zip -o kotlin.zip
unzip -q kotlin.zip -d /opt/kotlin
echo "/opt/kotlin/kotlinc/bin" >> $GITHUB_PATH
- name: Check Kotlin syntax
run: |
errors=0
for f in articles/*/kotlin/solve.kt; do
if [ -f "$f" ]; then
/opt/kotlin/kotlinc/bin/kotlinc -script "$f" -nowarn 2>&1 | head -5 || errors=$((errors + 1))
fi
done
if [ $errors -gt 0 ]; then
echo "Found $errors Kotlin errors"
fi
echo "Kotlin syntax check complete"
lint-csharp:
name: Lint C# examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Check C# syntax
run: |
errors=0
for dir in articles/*/csharp; do
if [ -f "$dir/Solve.cs" ] && [ -f "$dir/Solve.csproj" ]; then
cd "$dir"
if ! dotnet build --nologo -v q 2>&1; then
errors=$((errors + 1))
fi
rm -rf bin obj
cd - > /dev/null
fi
done
if [ $errors -gt 0 ]; then
echo "Found $errors C# compilation errors"
exit 1
fi
echo "All C# examples compile"
lint-rust:
name: Lint Rust examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Check Rust syntax
run: |
errors=0
for dir in articles/*/rust; do
if [ -f "$dir/Cargo.toml" ]; then
cd "$dir"
if ! cargo check --message-format=short 2>&1; then
errors=$((errors + 1))
fi
rm -rf target
cd - > /dev/null
fi
done
if [ $errors -gt 0 ]; then
echo "Found $errors Rust compilation errors"
exit 1
fi
echo "All Rust examples compile"
validate-structure:
name: Validate example pack structure
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check required files and at least one supported implementation
run: |
errors=0
ALL_LANGS="python node php go java csharp ruby rust kotlin bash"
for dir in articles/*/; do
slug=$(basename "$dir")
# Required files
if [ ! -f "$dir/README.md" ]; then
echo "ERROR: $dir is missing README.md"
errors=$((errors + 1))
fi
if [ ! -f "$dir/.env.example" ]; then
echo "ERROR: $dir is missing .env.example"
errors=$((errors + 1))
fi
# At least one supported language directory required
lang_count=0
for lang in $ALL_LANGS; do
if [ -d "$dir/$lang" ]; then
lang_count=$((lang_count + 1))
fi
done
if [ $lang_count -eq 0 ]; then
echo "ERROR: $dir does not contain a supported language directory"
errors=$((errors + 1))
fi
done
if [ $errors -gt 0 ]; then
echo "Found $errors structural errors"
exit 1
fi
echo "All example packs have required files and at least one supported implementation"
- name: Check no .env files committed
run: |
if find . -name ".env" -not -path "./.git/*" | grep -q .; then
echo "ERROR: .env files should not be committed"
find . -name ".env" -not -path "./.git/*"
exit 1
fi
echo "No .env files found (good)"
- name: Check README links to blog
run: |
errors=0
for dir in articles/*/; do
slug=$(basename "$dir")
readme="$dir/README.md"
if [ -f "$readme" ]; then
if ! grep -q "blog.captchaai.com" "$readme"; then
echo "ERROR: $readme does not link to blog.captchaai.com"
errors=$((errors + 1))
fi
fi
done
if [ $errors -gt 0 ]; then
echo "Found $errors README files without blog links"
exit 1
fi
echo "All READMEs link to the blog"
validate-quality:
name: Validate content quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check for mojibake in markdown files
run: |
# Detect common UTF-8 double-encoding artifacts
errors=0
while IFS= read -r -d '' file; do
if grep -Pq '\xC3\xA2\xC2\x80' "$file" 2>/dev/null; then
echo "ERROR: $file contains mojibake (double-encoded UTF-8)"
errors=$((errors + 1))
fi
done < <(find articles -name "*.md" -print0)
if [ $errors -gt 0 ]; then
echo "Found $errors files with encoding issues"
exit 1
fi
echo "No mojibake detected"
- name: Check for null CAPTCHA type labels in README index
run: |
if grep -P '\|\s*null\s*\|' README.md; then
echo "ERROR: README.md contains null CAPTCHA type labels"
exit 1
fi
echo "No null labels in README index"
- name: Validate solver method matches CAPTCHA type
run: |
errors=0
for dir in articles/*/; do
slug=$(basename "$dir")
solve_py="$dir/python/solve.py"
if [ -f "$solve_py" ]; then
method=$(grep -oP '"method"\s*:\s*"\K[^"]+' "$solve_py" 2>/dev/null || true)
if [ -n "$method" ]; then
# Check response field consistency
case "$method" in
userrecaptcha)
if ! grep -q "g-recaptcha-response" "$solve_py" 2>/dev/null; then
if grep -q "cf-turnstile-response\|h-captcha-response" "$solve_py" 2>/dev/null; then
echo "ERROR: $slug uses method=userrecaptcha but wrong response field"
errors=$((errors + 1))
fi
fi
;;
turnstile)
if ! grep -q "cf-turnstile-response" "$solve_py" 2>/dev/null; then
if grep -q "g-recaptcha-response\|h-captcha-response" "$solve_py" 2>/dev/null; then
echo "ERROR: $slug uses method=turnstile but wrong response field"
errors=$((errors + 1))
fi
fi
;;
hcaptcha)
if ! grep -q "h-captcha-response" "$solve_py" 2>/dev/null; then
if grep -q "g-recaptcha-response\|cf-turnstile-response" "$solve_py" 2>/dev/null; then
echo "ERROR: $slug uses method=hcaptcha but wrong response field"
errors=$((errors + 1))
fi
fi
;;
esac
fi
fi
done
if [ $errors -gt 0 ]; then
echo "Found $errors solver/response-field mismatches"
exit 1
fi
echo "All solver methods match their response fields"
- name: Validate index completeness
run: |
errors=0
# Check every pack directory is listed in README
for dir in articles/*/; do
slug=$(basename "$dir")
if ! grep -q "articles/$slug/" README.md; then
echo "ERROR: $slug exists but is not in README.md index"
errors=$((errors + 1))
fi
done
# Check no phantom entries
for slug in $(grep -oP 'articles/\K[^/]+(?=/)' README.md | sort -u); do
if [ ! -d "articles/$slug" ]; then
echo "ERROR: README references articles/$slug/ but directory does not exist"
errors=$((errors + 1))
fi
done
if [ $errors -gt 0 ]; then
echo "Found $errors index integrity errors"
exit 1
fi
echo "README index is complete and accurate"