Update conf.yml #24
Workflow file for this run
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}]' | |
# 转换 EXCLUDE_DIRS 和 EXCLUDE_FILES 为 grep 参数 | |
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 | |
echo "Chinese comments found in the following locations:" | |
cat chinese_comments.txt | |
exit 1 # 标记为失败并终止整个工作流 | |
else | |
echo "No Chinese comments found." | |
fi |