-
Notifications
You must be signed in to change notification settings - Fork 2
50 lines (41 loc) · 1.31 KB
/
comment-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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