@@ -16,53 +16,58 @@ jobs:
1616 check-unused-images :
1717 runs-on : ubuntu-latest
1818 steps :
19- - uses : actions/checkout@v3
19+ - uses : actions/checkout@v6
2020
2121 - name : Check for unused images
22+ continue-on-error : true
2223 run : |
2324 unused=()
2425
25- # Find all images in the root and `images/` directory (if it exists)
26- 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)
2732 if [ -d "./images" ]; then
28- 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
2936 fi
3037
31- # Loop through each image to check if it's referenced in the root README.md file
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
42+ fi
43+
44+ # Loop through each image to check if it's referenced in the root README.md
3245 for img in $images; do
33- found=false
34- if [ -f "./README.md" ]; then
35- if grep -q "$img" "./README.md"; then
36- found=true
37- fi
38- fi
46+ # Normalize path: remove leading ./
47+ normalized_img="${img#./}"
3948
40- if [ "$found" = false ]; then
41- 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")
4252 fi
4353 done
4454
4555 # Check if there are any unused images
4656 if [ ${#unused[@]} -gt 0 ]; then
47- echo "❌ Unused images found that are not referenced in the root README.md file :"
57+ echo "Unused images found that are not referenced in the root README.md:"
4858 echo "## Unused Images" >> $GITHUB_STEP_SUMMARY
4959 echo "" >> $GITHUB_STEP_SUMMARY
5060 echo "| Image Name | Path |" >> $GITHUB_STEP_SUMMARY
5161 echo "|------------|------|" >> $GITHUB_STEP_SUMMARY
5262
5363 for img in "${unused[@]}"; do
54- if [[ -f "./$img" ]]; then
55- path="./$img"
56- else
57- path="./images/$img"
58- fi
5964 name=$(basename "$img")
60- echo "$name -> $path "
65+ echo "$name -> $img "
6166
62- echo "| $name | $path |" >> $GITHUB_STEP_SUMMARY
67+ echo "| $name | $img |" >> $GITHUB_STEP_SUMMARY
6368 done
6469
6570 exit 1
6671 else
67- echo "✅ No unused images found that are not referenced in the root README.md file !"
72+ echo "No unused images found that are not referenced in the root README.md!"
6873 fi
0 commit comments