-
Notifications
You must be signed in to change notification settings - Fork 3.6k
453 lines (413 loc) · 19 KB
/
Copy pathinfra-link-rot-nightly.yml
File metadata and controls
453 lines (413 loc) · 19 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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
name: '🔧 Infra · 🌙 Link Rot (Nightly)'
# =============================================================================
# 🌙 Link Rot — Nightly Lychee sweep with sticky-issue reporter (Tier 3)
# =============================================================================
#
# Tier 1 (pre-commit) catches new internal-link breakage before it lands.
# Tier 2 (per-site validate-dev) catches external breakage at PR/push time.
# Tier 3 (this workflow) is the long-tail: nightly cron sweep across every
# subsite, with results aggregated into a single sticky GitHub issue so the
# team has one durable list of broken URLs to triage.
#
# Why a sticky issue:
# - One source of truth instead of 100 closed-then-reopened issues.
# - Body is rewritten each run with the current broken-link inventory.
# - Comments preserve trend (week-over-week count delta).
#
# Trigger:
# - schedule: 04:30 UTC daily (low-traffic window, after EU bedtime).
# - workflow_dispatch: manual one-off.
#
# Issue label: link-rot
# Issue title: 🔗 Link Rot Tracker (auto-updated nightly)
#
# =============================================================================
on:
schedule:
- cron: '30 4 * * *' # 04:30 UTC daily
workflow_dispatch:
inputs:
dry_run:
description: 'Skip issue update (just print results to job log)'
required: false
type: boolean
default: false
permissions:
contents: read
issues: write
concurrency:
group: link-rot-nightly
cancel-in-progress: false
jobs:
# =============================================================================
# Sweep each site in parallel via the reusable Lychee workflow.
# We deliberately reuse infra-link-check.yml so any tweak to Lychee args /
# ignore-file handling stays in one place.
# =============================================================================
sweep-book:
name: '📚 Sweep · Book'
uses: ./.github/workflows/infra-link-check.yml
with:
path_pattern: './book/quarto/contents/**/*.qmd'
lycheeignore_path: 'book/config/linting/.lycheeignore'
max_concurrency: 12
fail_on_broken: false
sweep-kits:
name: '📦 Sweep · Kits'
uses: ./.github/workflows/infra-link-check.yml
with:
path_pattern: './kits/**/*.qmd'
lycheeignore_path: 'shared/config/.lycheeignore-nightly'
max_concurrency: 8
fail_on_broken: false
sweep-labs:
name: '🔮 Sweep · Labs'
uses: ./.github/workflows/infra-link-check.yml
with:
path_pattern: './labs/**/*.qmd'
lycheeignore_path: 'shared/config/.lycheeignore-nightly'
max_concurrency: 8
fail_on_broken: false
sweep-mlsysim:
name: '🧮 Sweep · MLSys·im'
uses: ./.github/workflows/infra-link-check.yml
with:
path_pattern: './mlsysim/docs/**/*.qmd'
lycheeignore_path: 'shared/config/.lycheeignore-nightly'
max_concurrency: 8
fail_on_broken: false
sweep-slides:
name: '📊 Sweep · Slides'
uses: ./.github/workflows/infra-link-check.yml
with:
path_pattern: './slides/**/*.{qmd,md}'
lycheeignore_path: 'shared/config/.lycheeignore-nightly'
max_concurrency: 8
fail_on_broken: false
sweep-instructors:
name: '🎓 Sweep · Instructors'
uses: ./.github/workflows/infra-link-check.yml
with:
path_pattern: './instructors/**/*.qmd'
lycheeignore_path: 'shared/config/.lycheeignore-nightly'
max_concurrency: 5
fail_on_broken: false
sweep-tinytorch:
name: '🔥 Sweep · TinyTorch'
uses: ./.github/workflows/infra-link-check.yml
with:
path_pattern: './tinytorch/quarto/**/*.qmd'
lycheeignore_path: 'shared/config/.lycheeignore-nightly'
max_concurrency: 8
fail_on_broken: false
sweep-site:
name: '🌐 Sweep · Unified Site'
uses: ./.github/workflows/infra-link-check.yml
with:
path_pattern: './site/**/*.qmd'
lycheeignore_path: 'shared/config/.lycheeignore-nightly'
max_concurrency: 8
fail_on_broken: false
sweep-staffml:
name: '🎯 Sweep · StaffML'
uses: ./.github/workflows/infra-link-check.yml
with:
path_pattern: './interviews/**/*.{md,mdx,qmd}'
lycheeignore_path: 'shared/config/.lycheeignore-nightly'
max_concurrency: 8
fail_on_broken: false
# =============================================================================
# Aggregate sweep results and act on the tracker issue ONLY when there's
# something to act on. Quiet success is the goal.
#
# Decision matrix:
#
# broken sites | tracker exists | action
# ─────────────|────────────────|────────────────────────────────────────
# 0 | no | do nothing (silent green)
# 0 | yes | close tracker with "all clear" comment
# >0 | no | open tracker with full state + samples
# >0 | yes | edit body; add comment ONLY if state changed
#
# State change = different broken-site set OR different total-count, so
# routine "still broken, no news" runs don't spam comments.
# =============================================================================
report:
name: '📝 Triage link-rot tracker issue'
runs-on: ubuntu-latest
needs:
- sweep-book
- sweep-kits
- sweep-labs
- sweep-mlsysim
- sweep-slides
- sweep-instructors
- sweep-tinytorch
- sweep-site
- sweep-staffml
if: always()
steps:
- name: 📥 Checkout
uses: actions/checkout@v6
# -------------------------------------------------------------------
# 1. Aggregate sweep outputs. We read `needs.<job>.outputs.check-status`
# (the lychee verdict) NOT `needs.<job>.result` (the job result).
# With continue-on-error on the lychee step, the job result is
# always "success" — only the output reflects link health.
# -------------------------------------------------------------------
- name: 🧮 Aggregate sweep results
id: aggregate
env:
# Each pair: status output from the reusable workflow.
STATUS_BOOK: ${{ needs.sweep-book.outputs.check-status }}
STATUS_KITS: ${{ needs.sweep-kits.outputs.check-status }}
STATUS_LABS: ${{ needs.sweep-labs.outputs.check-status }}
STATUS_MLSYSIM: ${{ needs.sweep-mlsysim.outputs.check-status }}
STATUS_SLIDES: ${{ needs.sweep-slides.outputs.check-status }}
STATUS_INSTRUCTORS: ${{ needs.sweep-instructors.outputs.check-status }}
STATUS_TINYTORCH: ${{ needs.sweep-tinytorch.outputs.check-status }}
STATUS_SITE: ${{ needs.sweep-site.outputs.check-status }}
STATUS_STAFFML: ${{ needs.sweep-staffml.outputs.check-status }}
COUNT_BOOK: ${{ needs.sweep-book.outputs.broken-links-count }}
COUNT_KITS: ${{ needs.sweep-kits.outputs.broken-links-count }}
COUNT_LABS: ${{ needs.sweep-labs.outputs.broken-links-count }}
COUNT_MLSYSIM: ${{ needs.sweep-mlsysim.outputs.broken-links-count }}
COUNT_SLIDES: ${{ needs.sweep-slides.outputs.broken-links-count }}
COUNT_INSTRUCTORS: ${{ needs.sweep-instructors.outputs.broken-links-count }}
COUNT_TINYTORCH: ${{ needs.sweep-tinytorch.outputs.broken-links-count }}
COUNT_SITE: ${{ needs.sweep-site.outputs.broken-links-count }}
COUNT_STAFFML: ${{ needs.sweep-staffml.outputs.broken-links-count }}
SAMPLE_BOOK: ${{ needs.sweep-book.outputs.broken-links-sample }}
SAMPLE_KITS: ${{ needs.sweep-kits.outputs.broken-links-sample }}
SAMPLE_LABS: ${{ needs.sweep-labs.outputs.broken-links-sample }}
SAMPLE_MLSYSIM: ${{ needs.sweep-mlsysim.outputs.broken-links-sample }}
SAMPLE_SLIDES: ${{ needs.sweep-slides.outputs.broken-links-sample }}
SAMPLE_INSTRUCTORS: ${{ needs.sweep-instructors.outputs.broken-links-sample }}
SAMPLE_TINYTORCH: ${{ needs.sweep-tinytorch.outputs.broken-links-sample }}
SAMPLE_SITE: ${{ needs.sweep-site.outputs.broken-links-sample }}
SAMPLE_STAFFML: ${{ needs.sweep-staffml.outputs.broken-links-sample }}
# Job results in case the sweep itself died (infra issue, not link rot).
RESULT_BOOK: ${{ needs.sweep-book.result }}
RESULT_KITS: ${{ needs.sweep-kits.result }}
RESULT_LABS: ${{ needs.sweep-labs.result }}
RESULT_MLSYSIM: ${{ needs.sweep-mlsysim.result }}
RESULT_SLIDES: ${{ needs.sweep-slides.result }}
RESULT_INSTRUCTORS: ${{ needs.sweep-instructors.result }}
RESULT_TINYTORCH: ${{ needs.sweep-tinytorch.result }}
RESULT_SITE: ${{ needs.sweep-site.result }}
RESULT_STAFFML: ${{ needs.sweep-staffml.result }}
run: |
set -euo pipefail
NOW=$(date -u +"%Y-%m-%dT%H:%MZ")
BODY_FILE=$(mktemp)
# State-fingerprint = ordered list of "site:count" pairs for sites
# with broken links. Used to decide whether to post a new comment.
FINGERPRINT=""
BROKEN_SITES=0
INFRA_FAIL=0
TOTAL_BROKEN=0
{
echo "# 🔗 Link Rot Tracker"
echo ""
echo "_Auto-updated nightly. Last sweep: **$NOW**._"
echo ""
echo "This tracker is **only opened/updated when broken links are present**. When everything is clean, it is closed automatically — silence is success."
echo ""
echo "## Per-site status"
echo ""
echo "| Site | Status | Broken |"
echo "|------|--------|-------:|"
# Iterate sites by parallel arrays so we can also pull samples.
sites=(
"📚 Book|BOOK"
"📦 Kits|KITS"
"🔮 Labs|LABS"
"🧮 MLSys·im|MLSYSIM"
"📊 Slides|SLIDES"
"🎓 Instructors|INSTRUCTORS"
"🔥 TinyTorch|TINYTORCH"
"🌐 Unified Site|SITE"
"🎯 StaffML|STAFFML"
)
for entry in "${sites[@]}"; do
label="${entry%%|*}"
key="${entry##*|}"
status_var="STATUS_$key"
count_var="COUNT_$key"
result_var="RESULT_$key"
status="${!status_var:-}"
count="${!count_var:-}"
result="${!result_var:-}"
if [ "$result" != "success" ] && [ "$result" != "failure" ]; then
# cancelled / skipped — sweep didn't run normally.
icon="🛑"; label_status="$result (no sweep)"; INFRA_FAIL=$((INFRA_FAIL+1))
elif [ -z "$status" ]; then
# Job ran but didn't produce an output — treat as infra blip.
icon="❓"; label_status="no output"; INFRA_FAIL=$((INFRA_FAIL+1))
elif [ "$status" = "success" ]; then
icon="✅"; label_status="clean"; count="0"
else
icon="❌"; label_status="broken"
BROKEN_SITES=$((BROKEN_SITES+1))
# Numeric add only if we have a real number.
if [[ "$count" =~ ^[0-9]+$ ]]; then
TOTAL_BROKEN=$((TOTAL_BROKEN + count))
FINGERPRINT="${FINGERPRINT}${key}:${count};"
else
FINGERPRINT="${FINGERPRINT}${key}:?;"
fi
fi
echo "| $label | $icon $label_status | ${count:-—} |"
done
echo ""
echo "**Sites with broken links: $BROKEN_SITES** · **Total broken URLs: $TOTAL_BROKEN**"
if [ "$INFRA_FAIL" -gt 0 ]; then
echo ""
echo "> ⚠️ $INFRA_FAIL sweep(s) didn't run cleanly — verdict for those sites is unknown."
fi
# Per-site samples (only render sites that are broken).
if [ "$BROKEN_SITES" -gt 0 ]; then
echo ""
echo "## First broken URLs by site"
echo ""
for entry in "${sites[@]}"; do
label="${entry%%|*}"
key="${entry##*|}"
status_var="STATUS_$key"
sample_var="SAMPLE_$key"
status="${!status_var:-}"
sample="${!sample_var:-}"
[ "$status" = "failure" ] || continue
[ -n "$sample" ] || continue
echo "<details><summary><b>$label</b></summary>"
echo ""
while IFS= read -r url; do
[ -z "$url" ] && continue
echo "- \`$url\`"
done <<< "$sample"
echo ""
echo "</details>"
echo ""
done
fi
echo ""
echo "## Triage notes"
echo ""
echo "- Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
echo "- To intentionally suppress a URL pattern: add it to \`shared/config/.lycheeignore\` (cross-site) or \`book/config/linting/.lycheeignore\` (book-only)."
echo "- To re-trigger now: \`gh workflow run infra-link-rot-nightly.yml\`."
echo ""
echo "<!-- fingerprint: $FINGERPRINT -->"
echo "<sub>Run id: ${{ github.run_id }}</sub>"
} > "$BODY_FILE"
echo "body_file=$BODY_FILE" >> "$GITHUB_OUTPUT"
echo "broken_sites=$BROKEN_SITES" >> "$GITHUB_OUTPUT"
echo "total_broken=$TOTAL_BROKEN" >> "$GITHUB_OUTPUT"
echo "infra_fail=$INFRA_FAIL" >> "$GITHUB_OUTPUT"
echo "fingerprint=$FINGERPRINT" >> "$GITHUB_OUTPUT"
echo ""
echo "===== Report Body (preview) ====="
cat "$BODY_FILE"
echo "================================="
- name: 🪟 Append step summary
run: |
{
echo "## 🌙 Link Rot Sweep"
echo ""
echo "- Broken sites: **${{ steps.aggregate.outputs.broken_sites }}**"
echo "- Total broken URLs: **${{ steps.aggregate.outputs.total_broken }}**"
echo "- Infra failures: **${{ steps.aggregate.outputs.infra_fail }}**"
echo ""
cat "${{ steps.aggregate.outputs.body_file }}"
} >> "$GITHUB_STEP_SUMMARY"
# -------------------------------------------------------------------
# 2. Make sure the label exists. Cheap; harmless to keep on every run.
# -------------------------------------------------------------------
- name: 🏷️ Ensure link-rot label exists
if: ${{ inputs.dry_run != true }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ! gh label list --repo "${{ github.repository }}" --search link-rot --json name --jq '.[].name' | grep -qx 'link-rot'; then
gh label create link-rot \
--repo "${{ github.repository }}" \
--description "Aggregated nightly link-rot tracker" \
--color "ededed" \
|| echo "Label already exists or could not be created (non-fatal)."
fi
# -------------------------------------------------------------------
# 3. Triage the tracker issue per the decision matrix at top of file.
# -------------------------------------------------------------------
- name: 🔁 Triage tracker issue
if: ${{ inputs.dry_run != true }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BODY_FILE: ${{ steps.aggregate.outputs.body_file }}
BROKEN_SITES: ${{ steps.aggregate.outputs.broken_sites }}
TOTAL_BROKEN: ${{ steps.aggregate.outputs.total_broken }}
INFRA_FAIL: ${{ steps.aggregate.outputs.infra_fail }}
FINGERPRINT: ${{ steps.aggregate.outputs.fingerprint }}
run: |
set -euo pipefail
TITLE="🔗 Link Rot Tracker (auto-updated nightly)"
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
# Find an existing open tracker (by label + title prefix).
ISSUE_NUM=$(gh issue list \
--repo "${{ github.repository }}" \
--state open \
--label link-rot \
--search "in:title \"Link Rot Tracker\"" \
--json number \
--jq '.[0].number // empty')
# ---------- BRANCH A: nothing broken ----------
if [ "$BROKEN_SITES" -eq 0 ]; then
if [ -z "$ISSUE_NUM" ]; then
# Quiet green night. Don't open an issue. Don't comment.
echo "::notice::All sites clean and no open tracker. No action taken (silent success)."
exit 0
fi
# An old tracker exists from a previous broken run; close it now.
echo "All sites clean. Closing tracker #$ISSUE_NUM."
ALL_CLEAR_BODY=$(printf '%s\n\n%s\n' \
"✅ All sites clean as of nightly sweep. Auto-closing this tracker." \
"Run: $RUN_URL")
gh issue comment "$ISSUE_NUM" \
--repo "${{ github.repository }}" \
--body "$ALL_CLEAR_BODY"
gh issue close "$ISSUE_NUM" \
--repo "${{ github.repository }}" \
--reason completed
exit 0
fi
# ---------- BRANCH B: at least one site has broken links ----------
if [ -z "$ISSUE_NUM" ]; then
echo "Broken links detected and no open tracker. Creating new tracker."
gh issue create \
--repo "${{ github.repository }}" \
--title "$TITLE" \
--label link-rot \
--body-file "$BODY_FILE"
exit 0
fi
# Tracker exists and we have new findings. Always refresh body so
# the issue reflects current truth. Only post a comment if state
# actually changed since the last sweep — silence when nothing's new.
PREV_FP=$(gh issue view "$ISSUE_NUM" \
--repo "${{ github.repository }}" \
--json body \
--jq '.body' \
| grep -oE 'fingerprint: [^ ]*' \
| head -n1 \
| sed 's/fingerprint: //' || true)
echo "Updating tracker #$ISSUE_NUM (prev fp='${PREV_FP:-<none>}', new fp='$FINGERPRINT')."
gh issue edit "$ISSUE_NUM" \
--repo "${{ github.repository }}" \
--body-file "$BODY_FILE"
if [ "$PREV_FP" != "$FINGERPRINT" ]; then
echo "State changed — posting trend comment."
gh issue comment "$ISSUE_NUM" \
--repo "${{ github.repository }}" \
--body "🔄 Link state changed: **$BROKEN_SITES site(s)**, **$TOTAL_BROKEN broken URL(s)**. See [run]($RUN_URL)."
else
echo "Same broken-link fingerprint as previous sweep — body refreshed, no comment posted."
fi