Non-English Comments Check #20
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: Non-English Comments Check | |
on: | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
non-english-comments-check: | |
runs-on: ubuntu-latest | |
env: | |
# Directories to be excluded | |
EXCLUDE_DIRS: ".git docs tests scripts assets node_modules build" | |
# Files to be excluded (e.g., markdown, text files) | |
EXCLUDE_FILES: "*.md *.txt *.html *.css *.min.js *.mdx" | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Search for Non-English comments | |
run: | | |
set -e | |
# Define the regex pattern to match Chinese characters | |
pattern='[\p{Han}]' | |
# Process the directories to be excluded | |
exclude_dirs="" | |
for dir in $EXCLUDE_DIRS; do | |
exclude_dirs="$exclude_dirs --exclude-dir=$dir" | |
done | |
# Use grep to find all comments containing Non-English characters | |
grep -Pnr "$pattern" . $exclude_dirs | while read -r line ; do | |
file_name=$(echo "$line" | cut -d':' -f1) | |
# Check if the file matches any pattern in EXCLUDE_FILES | |
skip_file=false | |
for file_pattern in $EXCLUDE_FILES; do | |
# Use echo and grep to match the file name with the pattern | |
if echo "$file_name" | grep -q "$file_pattern"; then | |
skip_file=true | |
break | |
fi | |
done | |
# If the file matches an exclude pattern, skip it | |
if [ "$skip_file" = true ]; then | |
continue | |
fi | |
# Write the result to the non_english_comments.txt file | |
echo "$line" >> non_english_comments.txt | |
done || true | |
- name: Output non-English comments if found | |
run: | | |
if [ -s non_english_comments.txt ]; then | |
echo "Non-English comments found in the following locations:" | |
cat non_english_comments.txt | |
exit 1 # terminate the workflow | |
else | |
echo "No Non-English comments found." | |
fi |