Non-English Comments Check #6
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 | |
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 | |
# 如果发现了中文注释,输出注释内容及其位置,并退出 | |
if [ -s "$output_file" ]; then | |
echo "Chinese comments found in the following locations:" | |
cat "$output_file" | |
exit 1 # 退出并标记为失败 | |
else | |
echo "No Chinese comments found." | |
fi | |
- name: Fail step if Chinese comments were found | |
if: failure() | |
run: exit 1 |