|
| 1 | +name: Validate Documentation Links |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master ] |
| 6 | + paths: [ 'docs/**/*.md' ] |
| 7 | + pull_request: |
| 8 | + branches: [ main, master ] |
| 9 | + paths: [ 'docs/**/*.md' ] |
| 10 | + |
| 11 | +jobs: |
| 12 | + validate-links: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Setup Node.js |
| 20 | + uses: actions/setup-node@v4 |
| 21 | + with: |
| 22 | + node-version: '18' |
| 23 | + |
| 24 | + - name: Install markdown-link-check |
| 25 | + run: npm install -g markdown-link-check |
| 26 | + |
| 27 | + - name: Create markdown-link-check config |
| 28 | + run: | |
| 29 | + cat > .markdown-link-check.json << 'EOF' |
| 30 | + { |
| 31 | + "ignorePatterns": [ |
| 32 | + { |
| 33 | + "pattern": "^https://github.com/developmentseed/eoapi-k8s" |
| 34 | + }, |
| 35 | + { |
| 36 | + "pattern": "localhost" |
| 37 | + }, |
| 38 | + { |
| 39 | + "pattern": "127.0.0.1" |
| 40 | + } |
| 41 | + ], |
| 42 | + "replacementPatterns": [ |
| 43 | + { |
| 44 | + "pattern": "^./", |
| 45 | + "replacement": "{{BASEURL}}/" |
| 46 | + } |
| 47 | + ], |
| 48 | + "httpHeaders": [ |
| 49 | + { |
| 50 | + "urls": ["https://github.com"], |
| 51 | + "headers": { |
| 52 | + "Accept": "text/html" |
| 53 | + } |
| 54 | + } |
| 55 | + ], |
| 56 | + "timeout": "20s", |
| 57 | + "retryOn429": true, |
| 58 | + "retryCount": 3, |
| 59 | + "fallbackRetryDelay": "30s", |
| 60 | + "aliveStatusCodes": [200, 206, 301, 302, 403, 999] |
| 61 | + } |
| 62 | + EOF |
| 63 | +
|
| 64 | + - name: Validate internal links |
| 65 | + run: | |
| 66 | + echo "Checking internal link patterns..." |
| 67 | + broken_links_found=0 |
| 68 | +
|
| 69 | + while IFS= read -r -d '' file; do |
| 70 | + echo "Checking internal links in: $file" |
| 71 | +
|
| 72 | + # Check for broken relative links |
| 73 | + while IFS=: read -r line_num link; do |
| 74 | + # Extract the link path |
| 75 | + link_path=$(echo "$link" | sed -n 's/.*](\.\///; s/).*//p') |
| 76 | +
|
| 77 | + # Check if it's an image link |
| 78 | + if [[ "$link_path" == images/* ]]; then |
| 79 | + full_path="docs/$link_path" |
| 80 | + else |
| 81 | + full_path="docs/$link_path" |
| 82 | + fi |
| 83 | +
|
| 84 | + if [[ ! -e "$full_path" ]]; then |
| 85 | + echo "❌ Broken internal link in $file:$line_num -> $link_path (resolved to: $full_path)" |
| 86 | + broken_links_found=1 |
| 87 | + else |
| 88 | + echo "✅ Valid internal link: $link_path" |
| 89 | + fi |
| 90 | + done < <(grep -n "](\./" "$file" || true) |
| 91 | + done < <(find docs -name "*.md" -type f -print0) |
| 92 | +
|
| 93 | + if [[ $broken_links_found -eq 1 ]]; then |
| 94 | + echo "❌ Found broken internal links!" |
| 95 | + exit 1 |
| 96 | + else |
| 97 | + echo "✅ All internal links are valid!" |
| 98 | + fi |
| 99 | +
|
| 100 | + - name: Validate external links |
| 101 | + run: | |
| 102 | + echo "Validating external links..." |
| 103 | + find docs -name "*.md" -type f | while read -r file; do |
| 104 | + echo "Checking external links in: $file" |
| 105 | + markdown-link-check "$file" --config .markdown-link-check.json || echo "Some external links failed in $file" |
| 106 | + done |
| 107 | +
|
| 108 | + - name: Check for consistent link patterns |
| 109 | + run: | |
| 110 | + echo "Checking for inconsistent link patterns..." |
| 111 | + inconsistent_found=false |
| 112 | +
|
| 113 | + # Check for bad patterns |
| 114 | + if find docs -name "*.md" -exec grep -l "](docs/" {} \;; then |
| 115 | + echo "❌ Found links using 'docs/' prefix - use relative paths instead" |
| 116 | + find docs -name "*.md" -exec grep -Hn "](docs/" {} \; |
| 117 | + inconsistent_found=true |
| 118 | + fi |
| 119 | +
|
| 120 | + if find docs -name "*.md" -exec grep -l "](\.\./" {} \;; then |
| 121 | + echo "❌ Found links using '../' - use relative paths from docs root instead" |
| 122 | + find docs -name "*.md" -exec grep -Hn "](\.\./" {} \; |
| 123 | + inconsistent_found=true |
| 124 | + fi |
| 125 | +
|
| 126 | + if [[ "$inconsistent_found" == "true" ]]; then |
| 127 | + echo "❌ Found inconsistent link patterns!" |
| 128 | + echo "Use these patterns instead:" |
| 129 | + echo " - [Installation Guide](./installation.md)" |
| 130 | + echo " - [AWS Setup](./aws-eks.md)" |
| 131 | + echo " - [Images](./images/diagram.png)" |
| 132 | + exit 1 |
| 133 | + else |
| 134 | + echo "✅ All link patterns are consistent!" |
| 135 | + fi |
| 136 | +
|
| 137 | + - name: Validate frontmatter |
| 138 | + run: | |
| 139 | + echo "Checking that all markdown files have frontmatter..." |
| 140 | + missing_frontmatter_found=0 |
| 141 | +
|
| 142 | + while IFS= read -r -d '' file; do |
| 143 | + if ! head -1 "$file" | grep -q "^---$"; then |
| 144 | + echo "❌ Missing frontmatter in: $file" |
| 145 | + missing_frontmatter_found=1 |
| 146 | + fi |
| 147 | + done < <(find docs -name "*.md" -not -path "docs/_includes/*" -type f -print0) |
| 148 | +
|
| 149 | + if [[ $missing_frontmatter_found -eq 1 ]]; then |
| 150 | + echo "❌ Some files are missing frontmatter!" |
| 151 | + echo "Add frontmatter like:" |
| 152 | + echo "---" |
| 153 | + echo "title: \"Page Title\"" |
| 154 | + echo "description: \"Page description\"" |
| 155 | + echo "external_links:" |
| 156 | + echo " - name: \"Link Name\"" |
| 157 | + echo " url: \"https://example.com\"" |
| 158 | + echo "---" |
| 159 | + exit 1 |
| 160 | + else |
| 161 | + echo "✅ All markdown files have frontmatter!" |
| 162 | + fi |
0 commit comments