Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/broken-img.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Validating Images

on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- '**/*.md'

jobs:
read-markdown:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: validate image formats
run: |
changed_files=$(git diff --name-only HEAD^ HEAD | grep '\.md$')

has_invalid_images=false

for file in $changed_files; do
if [ -f "$file" ]; then
echo "Checking $file for invalid image lines:"
# Find lines in ![alt](image-path) format
grep -n -E '!\[.*\]\(.*\)' "$file" | while IFS= read -r line; do
# Extract the image path syntax
image_path=$(echo "$line" | sed -E 's/.*!\[.*\]\((.*)\).*/\1/')

# Check if image path is empty
if [ -z "$image_path" ]; then
echo "::warning file=$file::Empty image path in line: $line"
has_invalid_images=true
continue
fi

# Check image path extension (png, jpg, jpeg, gif, svg, webp)

if ! echo "$image_path" | grep -qE '\.(png|jpg|jpeg|gif|svg|webp)$'; then
echo "::warning file=$file::Invalid or missing image extension in line: $line"
has_invalid_images=true
fi
done
else
echo "::warning::File $file not found"
has_invalid_images=true
fi
done

if [ "$has_invalid_images" = true ]; then
echo "Validation failed: Found invalid image formats in Markdown files"
exit 1
else
echo "All image formats are valid"
fi