File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Check Unused Images
2+
3+ on :
4+ push :
5+ paths :
6+ - ' **/*.md'
7+ - ' *.png'
8+ - ' *.jpg'
9+ - ' *.jpeg'
10+ - ' *.svg'
11+ - ' *.gif'
12+ - ' images/**'
13+ pull_request :
14+
15+ jobs :
16+ check-unused-images :
17+ runs-on : ubuntu-latest
18+ steps :
19+ - uses : actions/checkout@v3
20+
21+ - name : Check for unused images
22+ run : |
23+ unused=()
24+
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")
27+ 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")"
29+ fi
30+
31+ # Loop through each image to check if it's referenced in any README files
32+ 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)
40+
41+ if [ "$found" = false ]; then
42+ unused+=("$img")
43+ fi
44+ done
45+
46+ # Check if there are any unused images
47+ if [ ${#unused[@]} -gt 0 ]; then
48+ echo "❌ Unused images found that are not referenced in any README files:"
49+ echo "## Unused Images" >> $GITHUB_STEP_SUMMARY
50+ echo "" >> $GITHUB_STEP_SUMMARY
51+ echo "| Image Name | Path |" >> $GITHUB_STEP_SUMMARY
52+ echo "|------------|------|" >> $GITHUB_STEP_SUMMARY
53+
54+ for img in "${unused[@]}"; do
55+ if [[ -f "./$img" ]]; then
56+ path="./$img"
57+ else
58+ path="./images/$img"
59+ fi
60+ name=$(basename "$img")
61+ echo "$name -> $path"
62+
63+ echo "| $name | $path |" >> $GITHUB_STEP_SUMMARY
64+ done
65+
66+ exit 1
67+ else
68+ echo "✅ No unused images found that are not referenced in README files!"
69+ fi
Original file line number Diff line number Diff line change 2323 uses : lycheeverse/lychee-action@v1
2424 with :
2525 args : --verbose --no-progress './**/[Rr][Ee][Aa][Dd][Mm][Ee].md' --exclude-file .lycheeignore
26+ fail : true
You can’t perform that action at this time.
0 commit comments