|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +jobs: |
| 13 | + markdown-lint: |
| 14 | + name: Markdown Lint |
| 15 | + runs-on: ubuntu-24.04 |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Lint Markdown files |
| 20 | + run: npx markdownlint-cli2 "**/*.md" "#node_modules" |
| 21 | + |
| 22 | + check-links: |
| 23 | + name: Check Internal Links |
| 24 | + runs-on: ubuntu-24.04 |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Check for broken internal links |
| 29 | + shell: bash |
| 30 | + run: | |
| 31 | + rm -f /tmp/broken_links_found |
| 32 | +
|
| 33 | + while IFS= read -r file; do |
| 34 | + dir="$(dirname "$file")" |
| 35 | +
|
| 36 | + # Extract link targets from markdown [text](target) syntax |
| 37 | + grep -oE '\]\([^)]+\)' "$file" \ |
| 38 | + | sed 's/^\](//;s/)$//' \ |
| 39 | + | while IFS= read -r link; do |
| 40 | +
|
| 41 | + # Skip external URLs, pure anchors, and absolute paths |
| 42 | + case "$link" in |
| 43 | + http://*|https://*|mailto:*|ftp://*) continue ;; |
| 44 | + \#*) continue ;; |
| 45 | + /*) continue ;; |
| 46 | + esac |
| 47 | +
|
| 48 | + # Strip anchor fragment for file existence check |
| 49 | + target="${link%%#*}" |
| 50 | + [ -z "$target" ] && continue |
| 51 | +
|
| 52 | + # Resolve relative to the file's directory |
| 53 | + resolved="$dir/$target" |
| 54 | +
|
| 55 | + if [ ! -e "$resolved" ]; then |
| 56 | + echo "::error file=${file}::Broken link: ${link} (resolved to ${resolved})" |
| 57 | + # Write to a temp file to propagate failure out of the pipe subshell |
| 58 | + echo "1" > /tmp/broken_links_found |
| 59 | + fi |
| 60 | + done |
| 61 | + done < <(find . -name '*.md' -not -path './node_modules/*') |
| 62 | +
|
| 63 | + if [ -f /tmp/broken_links_found ]; then |
| 64 | + echo "" |
| 65 | + echo "Found broken internal links. See errors above." |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + echo "All internal links are valid." |
0 commit comments