name: Check Links in README on: workflow_dispatch: jobs: check-links: runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: '20' - name: Install link checker run: npm install -g markdown-link-check - name: Check external links in all markdown files continue-on-error: true run: | # Create config file to handle custom domains and retries cat > .markdown-link-check.json << 'EOF' { "ignorePatterns": [ { "pattern": "^/" } ], "replacementPatterns": [], "httpHeaders": [ { "urls": ["https://git.sulej.net"], "headers": { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" } } ], "timeout": "20s", "retryOn429": true, "retryCount": 3, "fallbackRetryDelay": "30s", "aliveStatusCodes": [200, 206, 301, 302, 307, 308] } EOF echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🌐 Checking External Links in All Markdown Files" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" # Find all markdown files find . -name "*.md" -type f | sort > markdown_files.txt total_files=$(wc -l < markdown_files.txt) echo "📊 Found $total_files markdown files to check" echo "" # Extract and group all external links by context > all_broken_links.txt while IFS= read -r file; do # Run markdown-link-check and capture only errors markdown-link-check "$file" --config .markdown-link-check.json 2>&1 | grep "^\s*\[✖\]" >> all_broken_links.txt || true done < markdown_files.txt # Parse README.md to group links by skin/section if [ -f "README.md" ]; then echo "📋 Grouping broken links by context..." echo "" # Count total broken links total_broken=$(wc -l < all_broken_links.txt) if [ $total_broken -gt 0 ]; then echo "❌ Found $total_broken broken external links" echo "" # Group by category declare -A general_links declare -A skin_links declare -A tag_links while IFS= read -r line; do url=$(echo "$line" | grep -oP 'https://[^\s]+' || echo "$line" | grep -oP 'http://[^\s]+') # Categorize links if [[ "$url" == *"/osc/skins"* ]]; then general_links["$url"]=1 elif [[ "$url" == *"/src/tag/"* ]] || [[ "$url" == *"/media/tag/"* ]]; then tag_links["$url"]=1 elif [[ "$url" == *"/export/"* ]] || [[ "$url" == *"/media/"* ]]; then # Extract skin name from URL skin_name=$(echo "$url" | grep -oP '/export/[^/]+' | sed 's|/export/||' | head -1) if [ -z "$skin_name" ]; then skin_name="Unknown" fi skin_links["$skin_name"]+="$url"$'\n' else general_links["$url"]=1 fi done < all_broken_links.txt # Display grouped results if [ ${#general_links[@]} -gt 0 ]; then echo "🔗 General Links:" for url in "${!general_links[@]}"; do echo " ❌ $url" done echo "" fi if [ ${#skin_links[@]} -gt 0 ]; then echo "🎨 Skin-specific Links:" for skin in "${!skin_links[@]}"; do echo "" echo " $skin:" echo "${skin_links[$skin]}" | while IFS= read -r url; do [ -n "$url" ] && echo " ❌ $url" done done echo "" fi if [ ${#tag_links[@]} -gt 0 ]; then echo "🏷️ Version Tags:" for url in "${!tag_links[@]}"; do echo " ❌ $url" done echo "" fi else echo "✅ All external links are valid!" fi fi - name: Check all links in markdown files run: | #!/bin/bash echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🔍 Checking ALL Links in All Markdown Files" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" # Find all markdown files find . -name "*.md" -type f | sort > all_markdown_files.txt total_files=$(wc -l < all_markdown_files.txt) echo "📊 Found $total_files markdown files to check" echo "" has_errors=0 # Process each markdown file while IFS= read -r md_file; do echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "📄 Checking: $md_file" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" file_has_errors=0 # Extract ALL links from the markdown file # Match both []() and direct URLs grep -oP '\[([^\]]+)\]\(([^\)]+)\)' "$md_file" | sed 's/\[.*\](\(.*\))/\1/' > /tmp/links_$$.txt || true # Also extract image links grep -oP '!\[([^\]]*)\]\(([^\)]+)\)' "$md_file" | sed 's/!\[.*\](\(.*\))/\1/' >> /tmp/links_$$.txt || true link_count=$(wc -l < /tmp/links_$$.txt) if [ $link_count -eq 0 ]; then echo " ℹ️ No links found in this file" echo "" continue fi echo " 📊 Found $link_count links to check" echo "" # Check each link while IFS= read -r link; do # Decode URL-encoded characters decoded_link=$(echo "$link" | sed 's/%20/ /g' | sed 's/%23/#/g' | sed 's/%28/(/g' | sed 's/%29/)/g' | sed 's/%E2%80%A2/•/g' | sed 's/%E1%9A%96/ᚖ/g' | sed 's/%E3%80%8A/《/g' | sed 's/%E3%80%8B/》/g' | sed 's/%E3%80%8E/『/g' | sed 's/%E3%80%8F/』/g' | sed 's/%E2%9B%94/⛔/g' | sed 's/%E2%9C%A8/✨/g' | sed 's/%7B/{/g' | sed 's/%7D/}/g' | sed 's/%2B/+/g' | sed 's/%E3%83%86/テ/g' | sed 's/%E3%83%B3/ン/g' | sed 's/%E3%83%8D/ネ/g' | sed 's/%E3%82%B9/ス/g' | sed 's/%E3%82%A4/イ/g' | sed 's/%E3%83%BB/・/g' | sed 's/%E3%83%95/フ/g' | sed 's/%E3%83%AA/リ/g' | sed 's/%E3%83%BC/ー/g' | sed 's/%E3%83%8A/ナ/g' | sed 's/%5B/[/g' | sed 's/%5D/]/g') # Check if it's an external URL if [[ "$decoded_link" =~ ^https?:// ]]; then # Check external URL with curl if curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$decoded_link" | grep -q "^[23]"; then echo " ✅ $decoded_link" else echo " ❌ $decoded_link (URL not accessible)" file_has_errors=1 has_errors=1 fi else # Local file - remove leading slash if present if [[ "$decoded_link" =~ ^/ ]]; then file_path="${decoded_link#/}" else # Relative path - resolve from markdown file location md_dir=$(dirname "$md_file") file_path="$md_dir/$decoded_link" fi # Normalize path file_path=$(realpath -m "$file_path" 2>/dev/null || echo "$file_path") if [ -f "$file_path" ]; then echo " ✅ $decoded_link" else echo " ❌ $decoded_link (file not found: $file_path)" file_has_errors=1 has_errors=1 fi fi done < /tmp/links_$$.txt rm -f /tmp/links_$$.txt if [ $file_has_errors -eq 0 ]; then echo "" echo " ✅ All links valid in this file" else echo "" echo " ❌ Some links are broken in this file" fi echo "" done < all_markdown_files.txt echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" if [ $has_errors -eq 0 ]; then echo "✅ FINAL RESULT: All links are valid across all markdown files!" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" exit 0 else echo "❌ FINAL RESULT: Some links are broken. Please review the output above." echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" exit 1 fi