-
Notifications
You must be signed in to change notification settings - Fork 4
69 lines (59 loc) · 2.17 KB
/
check-images.yml
File metadata and controls
69 lines (59 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
name: Check Unused Images
on:
push:
paths:
- '**/*.md'
- '*.png'
- '*.jpg'
- '*.jpeg'
- '*.svg'
- '*.gif'
- 'images/**'
pull_request:
jobs:
check-unused-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check for unused images
run: |
unused=()
# Find all images in the root and `images/` directory (if it exists)
images=$(find . -maxdepth 1 -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.svg" -o -iname "*.gif" \) -printf "%P\n")
if [ -d "./images" ]; then
images+=" $(find ./images -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.svg" -o -iname "*.gif" \) -printf "%P\n")"
fi
# Loop through each image to check if it's referenced in any README files
for img in $images; do
found=false
while IFS= read -r -d '' readme_file; do
if grep -q "!\[.*\](.*$img.*)" "$readme_file"; then
found=true
break
fi
done < <(find . -iname "readme.md" -print0)
if [ "$found" = false ]; then
unused+=("$img")
fi
done
# Check if there are any unused images
if [ ${#unused[@]} -gt 0 ]; then
echo "❌ Unused images found that are not referenced in any README files:"
echo "## Unused Images" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Image Name | Path |" >> $GITHUB_STEP_SUMMARY
echo "|------------|------|" >> $GITHUB_STEP_SUMMARY
for img in "${unused[@]}"; do
if [[ -f "./$img" ]]; then
path="./$img"
else
path="./images/$img"
fi
name=$(basename "$img")
echo "$name -> $path"
echo "| $name | $path |" >> $GITHUB_STEP_SUMMARY
done
exit 1
else
echo "✅ No unused images found that are not referenced in README files!"
fi