Skip to content

Non-English Comments Check #10

Non-English Comments Check

Non-English Comments Check #10

Workflow file for this run

name: Check for Chinese Comments
on:
pull_request:
branches:
- main
workflow_dispatch:
jobs:
check_chinese_comments:
runs-on: ubuntu-latest
env:
EXCLUDE_DIRS: ".git docs tests scripts assets node_modules build"
EXCLUDE_FILES: "*.md *.txt *.html *.css *.min.js"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Search for Chinese comments
run: |
set -e
# 定义正则表达式模式匹配中文字符
pattern='[\p{Han}]'
# 处理要排除的目录
exclude_dirs=""
for dir in $EXCLUDE_DIRS; do
exclude_dirs="$exclude_dirs --exclude-dir=$dir"
done
# 处理要排除的文件类型
exclude_files=""
for file in $EXCLUDE_FILES; do
exclude_files="$exclude_files --exclude=$file"
done
# 使用 grep 查找所有包含中文字符的注释并保存到文件
grep -Pnr "$pattern" . $exclude_dirs $exclude_files > chinese_comments.txt || true
- name: Output and fail if Chinese comments are found
run: |
if [ -s chinese_comments.txt ]; then
cat chinese_comments.txt
echo "Chinese comments found in the following locations:"
exit 1 # 标记为失败并终止整个工作流
else
echo "No Chinese comments found."
fi