Skip to content

Commit 3dbf8cc

Browse files
Fix image check workflow to only validate root README.md
- Removed GNU-specific -printf flag for cross-platform compatibility - Simplified image finding using shell globs instead of find command - Changed to only check root README.md instead of all README files - Fixed path normalization to handle ./prefix correctly - Changed README.md missing case to pass with warning instead of fail - Updated messages to clarify checking only root README.md
1 parent 2b738dd commit 3dbf8cc

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

.github/workflows/check-images.yml

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,51 @@ jobs:
2222
run: |
2323
unused=()
2424
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")
25+
# Find all images in the root directory
26+
for img in *.png *.jpg *.jpeg *.svg *.gif; do
27+
[ -f "$img" ] && images="$images $img"
28+
done
29+
30+
# Find all images in the images/ directory (if it exists)
2731
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")"
32+
for img in ./images/*.png ./images/*.jpg ./images/*.jpeg ./images/*.svg ./images/*.gif; do
33+
[ -f "$img" ] && images="$images $img"
34+
done
35+
fi
36+
37+
# Check if root README.md exists
38+
if [ ! -f "./README.md" ]; then
39+
echo "README.md not found in root directory - skipping image check"
40+
exit 0
2941
fi
3042
31-
# Loop through each image to check if it's referenced in any README files
43+
# Loop through each image to check if it's referenced in the root README.md
3244
for img in $images; do
33-
found=false
34-
while IFS= read -r -d '' readme_file; do
35-
if grep -q "!\[.*\](.*$img.*)" "$readme_file"; then
36-
found=true
37-
break
38-
fi
39-
done < <(find . -iname "readme.md" -print0)
45+
# Normalize path: remove leading ./
46+
normalized_img="${img#./}"
4047
41-
if [ "$found" = false ]; then
42-
unused+=("$img")
48+
# Check if the image is referenced in README.md
49+
if ! grep -q "$normalized_img" "./README.md"; then
50+
unused+=("$normalized_img")
4351
fi
4452
done
4553
4654
# Check if there are any unused images
4755
if [ ${#unused[@]} -gt 0 ]; then
48-
echo "Unused images found that are not referenced in any README files:"
56+
echo "Unused images found that are not referenced in the root README.md:"
4957
echo "## Unused Images" >> $GITHUB_STEP_SUMMARY
5058
echo "" >> $GITHUB_STEP_SUMMARY
5159
echo "| Image Name | Path |" >> $GITHUB_STEP_SUMMARY
5260
echo "|------------|------|" >> $GITHUB_STEP_SUMMARY
5361
5462
for img in "${unused[@]}"; do
55-
if [[ -f "./$img" ]]; then
56-
path="./$img"
57-
else
58-
path="./images/$img"
59-
fi
6063
name=$(basename "$img")
61-
echo "$name -> $path"
64+
echo "$name -> $img"
6265
63-
echo "| $name | $path |" >> $GITHUB_STEP_SUMMARY
66+
echo "| $name | $img |" >> $GITHUB_STEP_SUMMARY
6467
done
6568
6669
exit 1
6770
else
68-
echo "No unused images found that are not referenced in README files!"
71+
echo "No unused images found that are not referenced in the root README.md!"
6972
fi

0 commit comments

Comments
 (0)