comment-check.yml 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. name: Non-English Comments Check
  2. on:
  3. pull_request:
  4. branches:
  5. - main
  6. workflow_dispatch:
  7. jobs:
  8. non-english-comments-check:
  9. runs-on: ubuntu-latest
  10. env:
  11. # need ignore Dirs
  12. EXCLUDE_DIRS: ".git docs tests scripts assets node_modules build"
  13. # need ignore Files
  14. EXCLUDE_FILES: "*.md *.txt *.html *.css *.min.js *.mdx"
  15. steps:
  16. - uses: actions/checkout@v4
  17. - name: Search for Non-English comments
  18. run: |
  19. set -e
  20. # Define the regex pattern to match Chinese characters
  21. pattern='[\p{Han}]'
  22. # Process the directories to be excluded
  23. exclude_dirs=""
  24. for dir in $EXCLUDE_DIRS; do
  25. exclude_dirs="$exclude_dirs --exclude-dir=$dir"
  26. done
  27. # Process the file types to be excluded
  28. exclude_files=""
  29. for file in $EXCLUDE_FILES; do
  30. exclude_files="$exclude_files --exclude=$file"
  31. done
  32. # Use grep to find all comments containing Non-English characters and save to file
  33. grep -Pnr "$pattern" . $exclude_dirs $exclude_files > non_english_comments.txt || true
  34. - name: Output non-English comments are found
  35. run: |
  36. if [ -s non_english_comments.txt ]; then
  37. echo "Non-English comments found in the following locations:"
  38. cat non_english_comments.txt
  39. exit 1 # terminate the workflow
  40. else
  41. echo "No Non_English comments found."
  42. fi