|
79 | 79 | body: body |
80 | 80 | }); |
81 | 81 | } |
| 82 | +
|
| 83 | + link-integrity: |
| 84 | + name: Link Integrity |
| 85 | + runs-on: ubuntu-latest |
| 86 | + |
| 87 | + steps: |
| 88 | + - name: Checkout code |
| 89 | + uses: actions/checkout@v6 |
| 90 | + |
| 91 | + - name: Check internal markdown links resolve |
| 92 | + run: | |
| 93 | + rm -f /tmp/broken_links |
| 94 | +
|
| 95 | + # Escape %, newline, CR for GitHub Actions workflow commands |
| 96 | + escape_annotation() { |
| 97 | + local s="$1" |
| 98 | + s="${s//'%'/'%25'}" |
| 99 | + s="${s//$'\n'/'%0A'}" |
| 100 | + s="${s//$'\r'/'%0D'}" |
| 101 | + printf '%s' "$s" |
| 102 | + } |
| 103 | +
|
| 104 | + while IFS= read -r file; do |
| 105 | + dir=$(dirname "$file") |
| 106 | +
|
| 107 | + # Extract markdown links [text](path.md) or [text](path.md#anchor) |
| 108 | + grep -oE '\[[^]]*\]\([^)]+\.md(#[^)]*)?\)' "$file" 2>/dev/null \ |
| 109 | + | grep -oE '\([^)]+\.md' \ |
| 110 | + | sed 's/^(//' \ |
| 111 | + | sed 's/#.*//' \ |
| 112 | + | while IFS= read -r link; do |
| 113 | +
|
| 114 | + # Skip URLs |
| 115 | + case "$link" in http://*|https://*) continue ;; esac |
| 116 | +
|
| 117 | + # Resolve relative path |
| 118 | + resolved=$(cd "$dir" && realpath -q "$link" 2>/dev/null || echo "") |
| 119 | + if [ -z "$resolved" ] || [ ! -f "$resolved" ]; then |
| 120 | + safe_file="$(escape_annotation "$file")" |
| 121 | + safe_link="$(escape_annotation "$link")" |
| 122 | + echo "::warning file=${safe_file}::Broken link: ${safe_link} (target not found)" |
| 123 | + echo "$file -> $link" >> /tmp/broken_links |
| 124 | + fi |
| 125 | + done |
| 126 | + done < <(find . -name '*.md' \ |
| 127 | + -not -path './node_modules/*' \ |
| 128 | + -not -path './.git/*' \ |
| 129 | + -not -path './.taskmaster/*' \ |
| 130 | + -not -path './.claude/*') |
| 131 | +
|
| 132 | + if [ -f /tmp/broken_links ]; then |
| 133 | + count=$(wc -l < /tmp/broken_links) |
| 134 | + echo "" |
| 135 | + echo "Found $count broken link(s):" |
| 136 | + cat /tmp/broken_links |
| 137 | + echo "" |
| 138 | + echo "These are warnings for now. Fix broken links to keep docs navigable." |
| 139 | + else |
| 140 | + echo "All internal markdown links resolve." |
| 141 | + fi |
0 commit comments