feat: [SEI-9294]: Adds merge identities docs #139
This file contains 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: MarkDown filename validation | |
on: | |
pull_request: # Trigger on PR events | |
paths: | |
- '**/*.md' # Trigger only when .md files are changed | |
jobs: | |
kebab-case-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 2 | |
- name: Check filenames for kebab case | |
run: | | |
Red='\033[0;31m' # Red | |
Green='\033[0;32m' # Green | |
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 | xargs -n1 basename | grep '\.md$') | |
if [ -z "$changed_files" ]; then | |
echo -e "${Green} No changed Markdown files in this PR.${Reset}" | |
exit 0 | |
fi | |
x=1 | |
echo -e "${Blue} Changed Markdown files are :.${Reset}" | |
echo "$changed_files" | while read -r file; do | |
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]+)*\.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 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 Markdown filenames are in kebab case." | |
fi | |
# Check for Markdown filenames that are not long | |
if [ -n "$long_files" ]; then | |
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 Markdown filenames are of valid length.${Reset}" | |
fi | |
if [ "$failure_flag" -eq 0 ]; then | |
echo -e "${Green} All changed Markdown filenames passed validation.${Reset}" | |
exit 0 | |
else | |
echo -e "${Red} The check has failed.${Reset}" | |
exit 1 | |
fi |