@@ -23,48 +23,51 @@ jobs:
2323 run : |
2424 unused=()
2525
26- # Find all images in the root and `images/` directory (if it exists)
27- images=$(find . -maxdepth 1 -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.svg" -o -iname "*.gif" \) -printf "%P\n")
26+ # Find all images in the root directory
27+ for img in *.png *.jpg *.jpeg *.svg *.gif; do
28+ [ -f "$img" ] && images="$images $img"
29+ done
30+
31+ # Find all images in the images/ directory (if it exists)
2832 if [ -d "./images" ]; then
29- images+=" $(find ./images -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.svg" -o -iname "*.gif" \) -printf "%P\n")"
33+ for img in ./images/*.png ./images/*.jpg ./images/*.jpeg ./images/*.svg ./images/*.gif; do
34+ [ -f "$img" ] && images="$images $img"
35+ done
36+ fi
37+
38+ # Check if root README.md exists
39+ if [ ! -f "./README.md" ]; then
40+ echo "README.md not found in root directory - skipping image check"
41+ exit 0
3042 fi
3143
32- # Loop through each image to check if it's referenced in any README files
44+ # Loop through each image to check if it's referenced in the root README.md
3345 for img in $images; do
34- found=false
35- while IFS= read -r -d '' readme_file; do
36- if grep -q "!\[.*\](.*$img.*)" "$readme_file"; then
37- found=true
38- break
39- fi
40- done < <(find . -iname "readme.md" -print0)
46+ # Normalize path: remove leading ./
47+ normalized_img="${img#./}"
4148
42- if [ "$found" = false ]; then
43- unused+=("$img")
49+ # Check if the image is referenced in README.md
50+ if ! grep -q "$normalized_img" "./README.md"; then
51+ unused+=("$normalized_img")
4452 fi
4553 done
4654
4755 # Check if there are any unused images
4856 if [ ${#unused[@]} -gt 0 ]; then
49- echo "❌ Unused images found that are not referenced in any README files :"
57+ echo "Unused images found that are not referenced in the root README.md :"
5058 echo "## Unused Images" >> $GITHUB_STEP_SUMMARY
5159 echo "" >> $GITHUB_STEP_SUMMARY
5260 echo "| Image Name | Path |" >> $GITHUB_STEP_SUMMARY
5361 echo "|------------|------|" >> $GITHUB_STEP_SUMMARY
5462
5563 for img in "${unused[@]}"; do
56- if [[ -f "./$img" ]]; then
57- path="./$img"
58- else
59- path="./images/$img"
60- fi
6164 name=$(basename "$img")
62- echo "$name -> $path "
65+ echo "$name -> $img "
6366
64- echo "| $name | $path |" >> $GITHUB_STEP_SUMMARY
67+ echo "| $name | $img |" >> $GITHUB_STEP_SUMMARY
6568 done
6669
6770 exit 1
6871 else
69- echo "✅ No unused images found that are not referenced in README files !"
72+ echo "No unused images found that are not referenced in the root README.md !"
7073 fi
0 commit comments