Commit ed89881583

ed89881583dbc3dae1653bafe28db2eece3ac502

parent: 1fd2d1a61c

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-04-19 20:33 UTC

Workflow to flag dead links and bad listings

Layout: unified · split

.github/workflows/health-check.yml added +69
@@ -0,0 +1,69 @@
1name: 🩺 Listing Health Checks
2
3on:
4 workflow_dispatch:
5 inputs:
6 category:
7 description: Just run for specific category (optional)
8 type: string
9 section:
10 description: Just run for a specific section (optional)
11 type: string
12 service:
13 description: Just run for a specific entry (optional)
14 type: string
15
16permissions:
17 contents: read
18
19jobs:
20 health-check:
21 name: Health check
22 runs-on: ubuntu-latest
23 steps:
24 - uses: actions/checkout@v5
25
26 - uses: actions/setup-python@v6
27 with:
28 python-version: "3.12"
29
30 - name: Install dependencies
31 run: pip install -q -r lib/requirements.txt
32
33 - name: Run health check
34 id: check
35 continue-on-error: true
36 env:
37 GITHUB_TOKEN: ${{ github.token }}
38 CATEGORY: ${{ inputs.category }}
39 SECTION: ${{ inputs.section }}
40 SERVICE: ${{ inputs.service }}
41 run: |
42 args=()
43 [ -n "$CATEGORY" ] && args+=(--category "$CATEGORY")
44 [ -n "$SECTION" ] && args+=(--section "$SECTION")
45 [ -n "$SERVICE" ] && args+=(--service "$SERVICE")
46 python lib/review-listings.py "${args[@]}" \
47 --save-json /tmp/findings.json \
48 --save-markdown /tmp/findings.md
49
50 - name: Write summary
51 if: always()
52 run: |
53 if [ -f /tmp/findings.md ]; then
54 cat /tmp/findings.md >> "$GITHUB_STEP_SUMMARY"
55 else
56 echo "We somehow lost the /tmp/findings.md file"
57 fi
58
59 - name: Upload findings JSON
60 if: always()
61 uses: actions/upload-artifact@v6
62 with:
63 name: listing-health-findings
64 path: /tmp/findings.json
65 if-no-files-found: ignore
66
67 - name: Fail if critical issues
68 if: steps.check.outcome == 'failure'
69 run: exit 1
lib/review-listings.py +76 −69
@@ -23,14 +23,13 @@ Findings have three severities: error (must fix), warn (should review), info (FY
2323HTTP 403/429 on reachability checks is demoted from error to warn (bot-blocking).
2424
2525Flags:
26- --output {list,table,json,markdown}: report format (default list)
27- --output-file PATH: also write the report to a file
26- --save-json PATH: save a JSON report to this file
27- --save-markdown PATH: save a markdown report to this file (for GH Actions summaries)
2828- --category / --section / --service: narrow to one entry
2929- --only / --skip: pick or drop checks by name
3030- --severity {all,warn,error}: filter findings
3131- --max-workers N: parallel workers (default 8)
3232- --timeout N: HTTP timeout in seconds (default 10)
33- --inactive-days N: info threshold for github-activity (default 365; warn at 2x)
3433- --token: GitHub token, else $GITHUB_TOKEN
3534- --no-color: disable ANSI colors
3635- --list-checks: list checks and exit
@@ -46,6 +45,7 @@ import signal
4645import sys
4746from concurrent.futures import ThreadPoolExecutor, as_completed
4847from dataclasses import asdict, dataclass, field
48from datetime import datetime, timezone
4949from threading import Lock
5050from time import monotonic
5151from typing import Callable, Iterable
@@ -57,17 +57,22 @@ except ImportError as exc:
5757 print(f"ERROR: missing dependency ({exc}). Run `make install_lib_deps`.", file=sys.stderr)
5858 sys.exit(2)
5959
60INACTIVE_DAYS = 365
6160MIN_DESC = 50
6261MAX_DESC = 280
6362MAX_DESC_HARD = 420
6463DEFAULT_WORKERS = 8
6564DEFAULT_TIMEOUT = 10
66DEFAULT_OUTPUT = "list"
65
66# github-activity age bands (days since last push). Order matters: most severe first.
67ACTIVITY_BANDS = (
68 (365 * 8, "error"),
69 (365 * 3, "warn"),
70 (365, "info"),
71)
6772
6873SEVERITIES = ("error", "warn", "info")
6974_SEV_COLOR = {"error": "red", "warn": "yellow", "info": "cyan"}
70_SEV_EMOJI = {"error": "🔴", "warn": "🟡", "info": "🔵"}
75_SEV_EMOJI = {"error": "🔴", "warn": "🟠", "info": "🟡"}
7176_SOFT_HTTP = {403, 429}
7277_PKG_RE = re.compile(r"^[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)+$")
7378
@@ -98,7 +103,6 @@ class Context:
98103 session: object
99104 token: str
100105 timeout: int
101 inactive_days: int
102106 url_occurrences: dict = field(default_factory=dict)
103107 repo_cache: dict = field(default_factory=dict)
104108 repo_lock: Lock = field(default_factory=Lock)
@@ -305,17 +309,14 @@ def _github_fork(entry: Entry, ctx: Context) -> Iterable[Finding]:
305309
306310@check("github-activity", needs_github=True)
307311def _github_activity(entry: Entry, ctx: Context) -> Iterable[Finding]:
308 """GitHub repo has been pushed to recently."""
312 """GitHub repo has been pushed to recently (info at 1y, warn at 3y, error at 8y)."""
309313 age = utils.repo_pushed_days_ago(_get_repo(entry, ctx))
310314 if age is None:
311315 return
312 if age > ctx.inactive_days * 2:
313 sev = "warn"
314 elif age > ctx.inactive_days:
315 sev = "info"
316 else:
317 return
318 yield _finding(entry, "github-activity", sev, f"last push {age} days ago")
316 for threshold, sev in ACTIVITY_BANDS:
317 if age >= threshold:
318 yield _finding(entry, "github-activity", sev, f"last push {age} days ago")
319 return
319320
320321
321322@check("github-license", needs_github=True)
@@ -362,7 +363,6 @@ def build_context(args, data, token):
362363 session=utils.make_session(),
363364 token=token,
364365 timeout=args.timeout,
365 inactive_days=args.inactive_days,
366366 )
367367 for cat, sec, svc in utils.iter_services(data):
368368 url = _normalize_url(svc.get("url"))
@@ -475,12 +475,12 @@ def _markdown_summary(s):
475475 return "\n".join([
476476 "### Summary",
477477 "",
478 f"- {s['services_scanned']} listings scanned "
478 f"- ℹ️ {s['services_scanned']} listings scanned "
479479 f"({s['total_checks']} checks, {s['pass_rate']:.1f}% pass rate)",
480 f"- {s['findings']} findings "
480 f"- ⚠️ {s['findings']} findings "
481481 f"({s['errors']} errors, {s['warnings']} warnings, {s['info']} info)",
482 f"- {s['services_passed']} listings passed all checks",
483 f"- Took {s['elapsed_seconds']:.1f}s",
482 f"- ✅ {s['services_passed']} listings passed all checks",
483 f"- ⏱️ Triggered at {s['triggered_at']}, took {s['elapsed_seconds']:.1f}s",
484484 ])
485485
486486
@@ -501,33 +501,6 @@ def render_list(findings, colors, summary):
501501 return "\n".join(lines)
502502
503503
504def render_table(findings, colors, summary):
505 header = ("Service", "Path", "Check", "Sev", "Message")
506 rows = [header] + [
507 (
508 f.service[:30],
509 f"{f.category} > {f.section}"[:40],
510 f.check,
511 f.severity.upper()[:5],
512 f.message[:80],
513 )
514 for f in findings
515 ]
516 widths = [max(len(r[i]) for r in rows) for i in range(len(header))]
517 lines = []
518 for i, row in enumerate(rows):
519 cells = [row[j].ljust(widths[j]) for j in range(len(row))]
520 if i == 0:
521 lines.append(colors["bold"](" ".join(cells)))
522 lines.append(colors["dim"](" ".join("-" * w for w in widths)))
523 else:
524 cells[3] = _sev_color(row[3].lower(), colors)(cells[3])
525 lines.append(" ".join(cells))
526 lines.append("")
527 lines.append(_summary(summary, colors))
528 return "\n".join(lines)
529
530
531504def render_json(findings, colors, summary):
532505 return json.dumps(
533506 {"summary": summary, "findings": [asdict(f) for f in findings]},
@@ -554,7 +527,38 @@ def _md_message(msg, url_limit=42):
554527def render_markdown(findings, colors, summary):
555528 def cell(s):
556529 return str(s).replace("|", "\\|").replace("\n", " ")
557 lines = ["| Service | Review Required |", "|---|---|"]
530
531 lines = []
532
533 lines += ["# Awesome Privacy Auto Checks", ""]
534
535 need_review = summary["findings"] - summary["errors"]
536 lines += [
537 f"_Ran {summary['total_checks']} checks across {summary['services_scanned']} "
538 f"listings, with a {summary['pass_rate']:.1f}% pass rate._",
539 f"_{summary['errors']} issues require action, plus another {need_review} "
540 f"findings need reviewing._",
541 "",
542 ]
543
544 errors = [f for f in findings if f.severity == "error"]
545 if errors:
546 lines += ["### Critical Issues", ""]
547 for f in errors:
548 lines.append(
549 f"- {_SEV_EMOJI[f.severity]} **{cell(f.service)}** - "
550 f"{_md_message(cell(f.message))}"
551 )
552 lines.append("")
553
554 lines += [
555 "---",
556 "",
557 "### Full Issue List",
558 "",
559 "| Service | Review Required |",
560 "|---|---|",
561 ]
558562 grouped: dict = {}
559563 for f in findings:
560564 grouped.setdefault((f.category, f.section, f.service), []).append(f)
@@ -568,20 +572,17 @@ def render_markdown(findings, colors, summary):
568572 f"| **{cell(name)}** [↗]({link})<br>"
569573 f"<sup>{cell(cat)} > {cell(sec)}</sup> | {review} |"
570574 )
571 lines += ["", _markdown_summary(summary)]
575 lines += ["", "---", "", _markdown_summary(summary)]
576 lines += [
577 "",
578 "> [!IMPORTANT]",
579 "> The automated checks can produce false positives, fail to include real issues, and does not "
580 "take the context of the listings into account. Careful human review is needed!",
581 ""
582 ]
572583 return "\n".join(lines)
573584
574585
575RENDERERS = {"list": render_list, "table": render_table, "json": render_json,
576 "markdown": render_markdown}
577
578_ANSI_RE = re.compile(r"\x1b\[[0-9;]*m")
579
580
581def strip_ansi(s: str) -> str:
582 return _ANSI_RE.sub("", s)
583
584
585586def _csv(s):
586587 return [x.strip() for x in s.split(",") if x.strip()]
587588
@@ -590,8 +591,9 @@ def parse_args():
590591 p = argparse.ArgumentParser(
591592 description="Review all listings in awesome-privacy.yml against our criteria.",
592593 )
593 p.add_argument("--output", choices=RENDERERS.keys(), default=DEFAULT_OUTPUT)
594 p.add_argument("--output-file", help="also write the report here (ANSI stripped)")
594 p.add_argument("--save-json", metavar="PATH", help="save a JSON report to this file")
595 p.add_argument("--save-markdown", metavar="PATH",
596 help="save a markdown report to this file (for GH Actions summaries)")
595597 p.add_argument("--category", help="filter to a single category")
596598 p.add_argument("--section", help="filter to a single section")
597599 p.add_argument("--service", help="filter to a single service")
@@ -600,7 +602,6 @@ def parse_args():
600602 p.add_argument("--severity", choices=["all", "warn", "error"], default="all")
601603 p.add_argument("--max-workers", type=int, default=DEFAULT_WORKERS)
602604 p.add_argument("--timeout", type=int, default=DEFAULT_TIMEOUT)
603 p.add_argument("--inactive-days", type=int, default=INACTIVE_DAYS)
604605 p.add_argument("--token", help="GitHub token (else $GITHUB_TOKEN)")
605606 p.add_argument("--no-color", action="store_true")
606607 p.add_argument("--list-checks", action="store_true", help="list available checks and exit")
@@ -675,24 +676,30 @@ def main():
675676 logging.info("Reviewing %d service(s) with %d check(s): %s",
676677 len(entries), len(enabled), ", ".join(enabled))
677678
679 triggered_at = datetime.now(timezone.utc)
678680 start = monotonic()
679681 findings = run_checks(entries, enabled, ctx, args.max_workers)
680682 elapsed = monotonic() - start
681683
682684 summary = _compute_summary(findings, entries, enabled, elapsed)
685 summary["triggered_at"] = triggered_at.strftime("%Y-%m-%d %H:%M UTC")
683686 display = filter_severity(findings, args.severity)
684687 display.sort(key=lambda f: (f.category, f.section, f.service, f.check))
685688
686 report = RENDERERS[args.output](display, colors, summary)
687 print(report)
689 print(render_list(display, colors, summary))
688690
689 if args.output_file:
691 for path, renderer in (
692 (args.save_json, render_json),
693 (args.save_markdown, render_markdown),
694 ):
695 if not path:
696 continue
690697 try:
691 with open(args.output_file, "w") as f:
692 f.write(strip_ansi(report) + "\n")
693 logging.info("Wrote report to %s", args.output_file)
698 with open(path, "w") as f:
699 f.write(renderer(display, colors, summary) + "\n")
700 logging.info("Wrote %s", path)
694701 except OSError as exc:
695 logging.warning("Could not write %s: %s", args.output_file, exc)
702 logging.warning("Could not write %s: %s", path, exc)
696703
697704 sys.exit(1 if any(f.severity == "error" for f in findings) else 0)
698705