Skip to content

Commit ceeac84

Browse files
Update actions
fix check-readme add check-images
1 parent 4d73021 commit ceeac84

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

.github/workflows/check-images.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

.github/workflows/check-readme.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ jobs:
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

0 commit comments

Comments
 (0)