Skip to content

Commit

Permalink
revert static file checker
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanmrzan100 committed Jan 15, 2025
1 parent 3b55bbb commit 67412c0
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions .github/workflows/markdown-and-image-file-validation.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
name: MarkDown and image filename validation
name: MarkDown filename validation

on:
pull_request:
pull_request: # Trigger on PR events
paths:
- '**/*.md'
- '**/*.jpg'
- '**/*.png'
- '**/*.jpeg'
- '**/*.svg'
- '**/*.md' # Trigger only when .md files are changed

jobs:
kebab-case-check:
Expand All @@ -26,57 +22,51 @@ jobs:
Yellow='\033[0;33m' # Yellow
Blue='\033[0;34m' # Blue
Reset='\033[0m' # Reset
echo -e "${Blue} Checking all changed Markdown files ..."
changed_files=$(git diff --name-only HEAD^1 HEAD | grep -E '\.(md|jpg|png|jpeg|svg)$')
echo -e "${Blue} Checking all changed Markdown files ..."
changed_files=$(git diff --name-only HEAD^1 HEAD | xargs -n1 basename | grep '\.md$')
if [ -z "$changed_files" ]; then
echo -e "${Green} No changed files in this PR.${Reset}"
echo -e "${Green} No changed Markdown files in this PR.${Reset}"
exit 0
fi
x=1
echo -e "${Blue} Changed static files are :${Reset}"
echo -e "${Blue} Changed Markdown files are :.${Reset}"
echo "$changed_files" | while read -r file; do
dir=$(dirname "$file")
base=$(basename "$file")
parent_folder=$(basename "$dir")
if [ "$parent_folder" = "." ]; then
parent_folder="root"
fi
combined_info="$parent_folder/$base" # Treat folder name as part of the file name
echo -e "${Yellow} $x. $combined_info${Reset}"
echo -e "${Yellow} $x. $file${Reset}"
x=$((x + 1))
done
# Find invalid filenames
invalid_kebab_case=$(echo "$changed_files" | grep -vE '^([a-z0-9]+(-[a-z0-9]+)*)(/([a-z0-9]+(-[a-z0-9]+)*))*\.(md|jpg|png|jpeg|svg)$' || true)
# Check for filenames that are not in kebab case
invalid_kebab_case=$(echo "$changed_files" | grep -vE '^[a-z0-9]+(-[a-z0-9]+)*\.md$' || true)
# Find long filenames
long_files=$(echo "$changed_files" | awk 'length > 100')
failure_flag=0
# Check for Markdown filenames that are not in kebab case
if [ -n "$invalid_kebab_case" ]; then
echo -e "${Blue} The following paths are not in kebab case:${Reset}"
echo -e "${Blue} The following Markdown filenames are not in kebab case:${Reset}"
x=1
echo "$invalid_kebab_case" | while read -r file; do
echo -e "${Red}$x. $file${Reset}"
x=$((x + 1))
done
failure_flag=1
else
echo -e "${Green} All changed filenames are in kebab case."
echo -e "${Green} All changed Markdown filenames are in kebab case."
fi
changed_files=$(git diff --name-only HEAD^1 HEAD | grep -E '\.(md|jpg|png|jpeg|svg)$')
long_files=$(echo "$changed_files" | awk 'length > 100')
# Check for filenames that are not long
# Check for Markdown filenames that are not long
if [ -n "$long_files" ]; then
echo -e "${Blue} The following filenames exceed 100 characters:${Reset}"
echo -e "${Blue} The following Markdown filenames exceed 100 characters:${Reset}"
x=1
echo "$long_files$" | while read -r file; do
echo -e "${Red}$x. $long_files${Reset}"
x=$((x + 1))
done
failure_flag=1
else
echo -e "${Green} All changed filenames are of valid length.${Reset}"
echo -e "${Green} All changed Markdown filenames are of valid length.${Reset}"
fi
if [ "$failure_flag" -eq 0 ]; then
echo -e "${Green} All changed filenames passed validation.${Reset}"
echo -e "${Green} All changed Markdown filenames passed validation.${Reset}"
exit 0
else
echo -e "${Red} The check has failed.${Reset}"
exit 1
fi
fi

0 comments on commit 67412c0

Please sign in to comment.