generated from osc/skins-template
Update .gitea/workflows/test-skins.yml
This commit is contained in:
@@ -138,196 +138,109 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Check internal markdown file references
|
- name: Check all links in markdown files
|
||||||
run: |
|
run: |
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
echo "🔍 Checking Internal Markdown File References in All Markdown Files"
|
echo "🔍 Checking ALL Links in All Markdown Files"
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Find all markdown files and extract internal links with context
|
# Find all markdown files
|
||||||
> internal_links_with_context.txt
|
find . -name "*.md" -type f | sort > all_markdown_files.txt
|
||||||
find . -name "*.md" -type f | while IFS= read -r file; do
|
total_files=$(wc -l < all_markdown_files.txt)
|
||||||
# Extract links with the skin name from headers
|
echo "📊 Found $total_files markdown files to check"
|
||||||
current_skin=""
|
|
||||||
while IFS= read -r line; do
|
|
||||||
# Check if it's a header (skin name)
|
|
||||||
if [[ "$line" =~ ^##[[:space:]]+\[([^\]]+)\] ]]; then
|
|
||||||
current_skin="${BASH_REMATCH[1]}"
|
|
||||||
fi
|
|
||||||
# Check for internal markdown links
|
|
||||||
if [[ "$line" =~ \]\((/[^\)]+\.md) ]]; then
|
|
||||||
link="${BASH_REMATCH[1]}"
|
|
||||||
echo "$current_skin|$link" >> internal_links_with_context.txt
|
|
||||||
fi
|
|
||||||
done < "$file"
|
|
||||||
done
|
|
||||||
|
|
||||||
total_count=$(wc -l < internal_links_with_context.txt)
|
|
||||||
echo "📊 Total internal markdown links found: $total_count"
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Group by skin and check
|
has_errors=0
|
||||||
declare -A skin_all_files
|
|
||||||
declare -A skin_missing_files
|
|
||||||
checked_count=0
|
|
||||||
total_missing=0
|
|
||||||
|
|
||||||
while IFS='|' read -r skin link; do
|
# Process each markdown file
|
||||||
checked_count=$((checked_count + 1))
|
while IFS= read -r md_file; do
|
||||||
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
|
echo "📄 Checking: $md_file"
|
||||||
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
|
|
||||||
# Decode URL-encoded characters
|
file_has_errors=0
|
||||||
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')
|
|
||||||
|
|
||||||
# Remove leading slash to make it relative
|
# Extract ALL links from the markdown file
|
||||||
file_path="${decoded_link#/}"
|
# Match both []() and direct URLs
|
||||||
|
grep -oP '\[([^\]]+)\]\(([^\)]+)\)' "$md_file" | sed 's/\[.*\](\(.*\))/\1/' > /tmp/links_$$.txt || true
|
||||||
|
|
||||||
if [ -z "$skin" ]; then
|
# Also extract image links
|
||||||
skin="General"
|
grep -oP '!\[([^\]]*)\]\(([^\)]+)\)' "$md_file" | sed 's/!\[.*\](\(.*\))/\1/' >> /tmp/links_$$.txt || true
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if file exists
|
link_count=$(wc -l < /tmp/links_$$.txt)
|
||||||
if [ -f "$file_path" ]; then
|
|
||||||
skin_all_files["$skin"]+="✅ $file_path"$'\n'
|
|
||||||
else
|
|
||||||
skin_all_files["$skin"]+="❌ $file_path"$'\n'
|
|
||||||
skin_missing_files["$skin"]+="$file_path"$'\n'
|
|
||||||
total_missing=$((total_missing + 1))
|
|
||||||
fi
|
|
||||||
done < internal_links_with_context.txt
|
|
||||||
|
|
||||||
# Report results
|
if [ $link_count -eq 0 ]; then
|
||||||
echo ""
|
echo " ℹ️ No links found in this file"
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
|
|
||||||
if [ $total_missing -gt 0 ]; then
|
|
||||||
echo "⚠️ RESULT: $total_missing of $total_count internal markdown files are MISSING"
|
|
||||||
else
|
|
||||||
echo "✅ RESULT: All $total_count internal markdown files exist!"
|
|
||||||
fi
|
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Display all links grouped by skin
|
|
||||||
if [ ${#skin_all_files[@]} -gt 0 ]; then
|
|
||||||
for skin in "${!skin_all_files[@]}"; do
|
|
||||||
echo "📄 $skin:"
|
|
||||||
# Save to temp file to avoid subshell issues with pipes
|
|
||||||
printf '%s\n' "${skin_all_files[$skin]}" > /tmp/skin_files_$$.txt
|
|
||||||
while IFS= read -r line; do
|
|
||||||
[ -n "$line" ] && echo " $line"
|
|
||||||
done < /tmp/skin_files_$$.txt
|
|
||||||
rm -f /tmp/skin_files_$$.txt
|
|
||||||
echo ""
|
echo ""
|
||||||
done
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo " 📊 Found $link_count links to check"
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
echo ""
|
||||||
|
|
||||||
# Exit with error if files are missing
|
# Check each link
|
||||||
if [ $total_missing -gt 0 ]; then
|
while IFS= read -r link; do
|
||||||
echo "❌ SUMMARY: Workflow failed due to $total_missing missing markdown file(s)"
|
# Decode URL-encoded characters
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
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')
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "✅ SUMMARY: All checks passed!"
|
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Check for broken image references
|
# Check if it's an external URL
|
||||||
run: |
|
if [[ "$decoded_link" =~ ^https?:// ]]; then
|
||||||
#!/bin/bash
|
# 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
|
||||||
|
|
||||||
echo ""
|
# Normalize path
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
file_path=$(realpath -m "$file_path" 2>/dev/null || echo "$file_path")
|
||||||
echo "🖼️ Checking Image References in All Markdown Files"
|
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Extract all image links from all markdown files with context
|
if [ -f "$file_path" ]; then
|
||||||
> image_links_with_context.txt
|
echo " ✅ $decoded_link"
|
||||||
find . -name "*.md" -type f | while IFS= read -r file; do
|
else
|
||||||
current_skin=""
|
echo " ❌ $decoded_link (file not found: $file_path)"
|
||||||
while IFS= read -r line; do
|
file_has_errors=1
|
||||||
# Check if it's a header (skin name)
|
has_errors=1
|
||||||
if [[ "$line" =~ ^##[[:space:]]+\[([^\]]+)\] ]]; then
|
|
||||||
current_skin="${BASH_REMATCH[1]}"
|
|
||||||
fi
|
|
||||||
# Check for image links
|
|
||||||
if [[ "$line" =~ !\[.*\]\(([^\)]+\.(png|jpg|jpeg|gif|webp|svg)) ]]; then
|
|
||||||
link="${BASH_REMATCH[1]}"
|
|
||||||
# Skip external URLs
|
|
||||||
if [[ ! "$link" =~ ^https?:// ]]; then
|
|
||||||
echo "$current_skin|$link" >> image_links_with_context.txt
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done < "$file"
|
done < /tmp/links_$$.txt
|
||||||
done
|
|
||||||
|
|
||||||
total_count=$(wc -l < image_links_with_context.txt)
|
rm -f /tmp/links_$$.txt
|
||||||
echo "📊 Total local image references found: $total_count"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Group by skin and check
|
if [ $file_has_errors -eq 0 ]; then
|
||||||
declare -A skin_all_images
|
|
||||||
declare -A skin_missing_images
|
|
||||||
checked_count=0
|
|
||||||
total_missing=0
|
|
||||||
|
|
||||||
while IFS='|' read -r skin link; do
|
|
||||||
checked_count=$((checked_count + 1))
|
|
||||||
|
|
||||||
# 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')
|
|
||||||
|
|
||||||
# Remove leading slash for absolute paths
|
|
||||||
if [[ "$decoded_link" =~ ^/ ]]; then
|
|
||||||
decoded_link="${decoded_link#/}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$skin" ]; then
|
|
||||||
skin="General"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if file exists
|
|
||||||
if [ -f "$decoded_link" ]; then
|
|
||||||
skin_all_images["$skin"]+="✅ $decoded_link"$'\n'
|
|
||||||
else
|
|
||||||
skin_all_images["$skin"]+="❌ $decoded_link"$'\n'
|
|
||||||
skin_missing_images["$skin"]+="$decoded_link"$'\n'
|
|
||||||
total_missing=$((total_missing + 1))
|
|
||||||
fi
|
|
||||||
done < image_links_with_context.txt
|
|
||||||
|
|
||||||
# Report results
|
|
||||||
echo ""
|
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
|
|
||||||
if [ $total_missing -gt 0 ]; then
|
|
||||||
echo "⚠️ RESULT: $total_missing of $total_count image files are MISSING (non-blocking)"
|
|
||||||
else
|
|
||||||
echo "✅ RESULT: All $total_count image files exist!"
|
|
||||||
fi
|
|
||||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Display all images grouped by skin
|
|
||||||
if [ ${#skin_all_images[@]} -gt 0 ]; then
|
|
||||||
for skin in "${!skin_all_images[@]}"; do
|
|
||||||
echo "🖼️ $skin:"
|
|
||||||
# Save to temp file to avoid subshell issues with pipes
|
|
||||||
printf '%s\n' "${skin_all_images[$skin]}" > /tmp/skin_images_$$.txt
|
|
||||||
while IFS= read -r line; do
|
|
||||||
[ -n "$line" ] && echo " $line"
|
|
||||||
done < /tmp/skin_images_$$.txt
|
|
||||||
rm -f /tmp/skin_images_$$.txt
|
|
||||||
echo ""
|
echo ""
|
||||||
done
|
echo " ✅ All links valid in this file"
|
||||||
fi
|
else
|
||||||
|
echo ""
|
||||||
|
echo " ❌ Some links are broken in this file"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
# Don't fail the workflow for missing images, just warn
|
done < all_markdown_files.txt
|
||||||
exit 0
|
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user