generated from osc/skins-template
182 lines
8.2 KiB
YAML
182 lines
8.2 KiB
YAML
name: Check Links in README
|
||
|
||
on:
|
||
workflow_dispatch:
|
||
|
||
jobs:
|
||
check-links:
|
||
runs-on: ubuntu-latest
|
||
|
||
steps:
|
||
- name: Checkout repository
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Check all links in markdown files
|
||
run: |
|
||
#!/bin/bash
|
||
set -o pipefail
|
||
|
||
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
|
||
{
|
||
# Markdown links []()
|
||
grep -oP '\]\(([^\)]+)\)' "$md_file" 2>/dev/null | sed 's/](\(.*\))/\1/' || true
|
||
# Image links ![]()
|
||
grep -oP '!\[[^\]]*\]\(([^\)]+)\)' "$md_file" 2>/dev/null | sed 's/!\[.*\](\(.*\))/\1/' || true
|
||
# Video src attributes
|
||
grep -oP '<video[^>]+src="([^"]+)"' "$md_file" 2>/dev/null | sed 's/.*src="\([^"]*\)".*/\1/' || true
|
||
} > /tmp/links_$$.txt
|
||
|
||
link_count=$(wc -l < /tmp/links_$$.txt 2>/dev/null || echo "0")
|
||
|
||
if [ $link_count -eq 0 ]; then
|
||
echo " ℹ️ No links found in this file"
|
||
echo ""
|
||
continue
|
||
fi
|
||
|
||
echo " 📊 Found $link_count links to check"
|
||
echo ""
|
||
|
||
# Categorize and check links
|
||
> /tmp/download_$$.txt
|
||
> /tmp/media_$$.txt
|
||
> /tmp/video_$$.txt
|
||
> /tmp/tags_$$.txt
|
||
|
||
# Check each link
|
||
while IFS= read -r link; do
|
||
[ -z "$link" ] && continue
|
||
|
||
# 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')
|
||
|
||
# Determine link category and validation status
|
||
status="✅"
|
||
|
||
# Check if it's an external URL
|
||
if [[ "$decoded_link" =~ ^https?:// ]]; then
|
||
# Check external URL with curl
|
||
http_code=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 \
|
||
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" \
|
||
"$link" 2>/dev/null || echo "000")
|
||
|
||
# Accept 2xx and 3xx status codes as valid
|
||
if ! [[ "$http_code" =~ ^[23][0-9][0-9]$ ]]; then
|
||
status="❌ (HTTP $http_code)"
|
||
file_has_errors=1
|
||
has_errors=1
|
||
fi
|
||
|
||
# Categorize external URLs
|
||
if [[ "$decoded_link" =~ /export/.*\.(osk|osz)$ ]]; then
|
||
echo " $status $decoded_link" >> /tmp/download_$$.txt
|
||
elif [[ "$decoded_link" =~ /media/gameplay/.*\.(mp4|webm)$ ]]; then
|
||
echo " $status $decoded_link" >> /tmp/video_$$.txt
|
||
elif [[ "$decoded_link" =~ /src/tag/ ]]; then
|
||
echo " $status $decoded_link" >> /tmp/tags_$$.txt
|
||
elif [[ "$decoded_link" =~ /media/(panel|icons|thumbnail)/ ]]; then
|
||
echo " $status $decoded_link" >> /tmp/media_$$.txt
|
||
else
|
||
echo " $status $decoded_link" >> /tmp/download_$$.txt
|
||
fi
|
||
else
|
||
# Local file - remove leading slash if present
|
||
if [[ "$decoded_link" =~ ^/ ]]; then
|
||
file_path="${decoded_link#/}"
|
||
else
|
||
md_dir=$(dirname "$md_file")
|
||
file_path="$md_dir/$decoded_link"
|
||
fi
|
||
|
||
# Check if file exists
|
||
if ! [ -f "$file_path" ]; then
|
||
status="❌ (not found)"
|
||
file_has_errors=1
|
||
has_errors=1
|
||
fi
|
||
|
||
# Categorize local files
|
||
if [[ "$decoded_link" =~ \.(webp|png|jpg|jpeg)$ ]]; then
|
||
echo " $status $decoded_link" >> /tmp/media_$$.txt
|
||
elif [[ "$decoded_link" =~ \.md$ ]]; then
|
||
echo " $status $decoded_link" >> /tmp/tags_$$.txt
|
||
else
|
||
echo " $status $decoded_link" >> /tmp/download_$$.txt
|
||
fi
|
||
fi
|
||
done < /tmp/links_$$.txt
|
||
|
||
# Display categorized results
|
||
if [ -s /tmp/download_$$.txt ]; then
|
||
echo "download:"
|
||
cat /tmp/download_$$.txt
|
||
echo ""
|
||
fi
|
||
|
||
if [ -s /tmp/media_$$.txt ]; then
|
||
echo "media:"
|
||
cat /tmp/media_$$.txt
|
||
echo ""
|
||
fi
|
||
|
||
if [ -s /tmp/video_$$.txt ]; then
|
||
echo "video:"
|
||
cat /tmp/video_$$.txt
|
||
echo ""
|
||
fi
|
||
|
||
if [ -s /tmp/tags_$$.txt ]; then
|
||
echo "tags:"
|
||
cat /tmp/tags_$$.txt
|
||
echo ""
|
||
fi
|
||
|
||
rm -f /tmp/download_$$.txt /tmp/media_$$.txt /tmp/video_$$.txt /tmp/tags_$$.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
|