Showcase of using data.js #5
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| continue-on-error: true | |
| run: | | |
| unused=() | |
| # Find all images in the root directory | |
| for img in *.png *.jpg *.jpeg *.svg *.gif; do | |
| [ -f "$img" ] && images="$images $img" | |
| done | |
| # Find all images in the images/ directory (if it exists) | |
| if [ -d "./images" ]; then | |
| for img in ./images/*.png ./images/*.jpg ./images/*.jpeg ./images/*.svg ./images/*.gif; do | |
| [ -f "$img" ] && images="$images $img" | |
| done | |
| fi | |
| # Check if root README.md exists | |
| if [ ! -f "./README.md" ]; then | |
| echo "README.md not found in root directory - skipping image check" | |
| exit 0 | |
| fi | |
| # Loop through each image to check if it's referenced in the root README.md | |
| for img in $images; do | |
| # Normalize path: remove leading ./ | |
| normalized_img="${img#./}" | |
| # Check if the image is referenced in README.md | |
| if ! grep -q "$normalized_img" "./README.md"; then | |
| unused+=("$normalized_img") | |
| fi | |
| done | |
| # Check if there are any unused images | |
| if [ ${#unused[@]} -gt 0 ]; then | |
| echo "Unused images found that are not referenced in the root README.md:" | |
| 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 | |
| name=$(basename "$img") | |
| echo "$name -> $img" | |
| echo "| $name | $img |" >> $GITHUB_STEP_SUMMARY | |
| done | |
| exit 1 | |
| else | |
| echo "No unused images found that are not referenced in the root README.md!" | |
| fi |