Non-English Comments Check #7
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: 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 | |
id: search_comments | |
run: | | |
set -e | |
# 定义正则表达式模式匹配中文字符 | |
pattern='[\p{Han}]' | |
# 创建一个结果文件 | |
output_file=chinese_comments.txt | |
: > $output_file | |
# 使用 grep 查找所有包含中文字符的注释 | |
grep -Pnr "$pattern" . \ | |
--exclude-dir={$EXCLUDE_DIRS} \ | |
--exclude="$EXCLUDE_FILES" \ | |
|| true | tee -a $output_file | |
- name: Check if Chinese comments were found | |
run: | | |
if [ -s chinese_comments.txt ]; then | |
echo "Chinese comments found in the following locations:" | |
cat chinese_comments.txt | |
exit 1 # 失败并终止整个工作流 | |
else | |
echo "No Chinese comments found." | |
fi |