44 pull_request :
55 types : [opened, synchronize, reopened]
66 push :
7- branches : [ main ] # 可根据需要指定分支,例如 "main", "master"
7+ branches : [ main ]
88
99jobs :
1010 check-signoff :
@@ -13,17 +13,74 @@ jobs:
1313 - name : Checkout code
1414 uses : actions/checkout@v4
1515 with :
16- fetch-depth : 0 # 获取所有历史和分支,以便正确比较
16+ fetch-depth : 0
1717
1818 - name : Check for Sign-off
1919 run : |
2020 check_commit() {
2121 local commit_hash=$1
2222 local commit_msg=$(git show -s --format=%B "$commit_hash")
23- if ! echo "$commit_msg" | grep -q "Signed-off-by:"; then
24- echo "提交 $commit_hash 缺少 Signed-off-by 签署。"
25- echo "请使用 'git commit -s' 添加签署,或手动在提交信息中包含 'Signed-off-by: Your Name <[email protected] >'。" 26- return 1
23+ local commit_title=$(git show -s --format=%s "$commit_hash")
24+
25+ # 跳过各种自动生成的提交
26+ case "$commit_title" in
27+ # GitHub 合并提交
28+ "Merge pull request"*)
29+ echo "跳过 GitHub PR 合并提交: $commit_hash - $commit_title"
30+ return 0
31+ ;;
32+ # Git 合并提交
33+ "Merge branch"*|"Merge remote-tracking"*|"Merge tag"*)
34+ echo "跳过 Git 合并提交: $commit_hash - $commit_title"
35+ return 0
36+ ;;
37+ # Revert 提交
38+ "Revert"*|"This reverts commit"*)
39+ echo "跳过还原提交: $commit_hash - $commit_title"
40+ return 0
41+ ;;
42+ # 自动版本发布提交
43+ "chore(release):"*|"release:"*|"Version"*|"Bump version"*)
44+ echo "跳过版本发布提交: $commit_hash - $commit_title"
45+ return 0
46+ ;;
47+ # 依赖更新提交 (Dependabot, Renovate等)
48+ "chore(deps):"*|"build(deps):"*|"Update dependency"*|"Bump"*)
49+ echo "跳过依赖更新提交: $commit_hash - $commit_title"
50+ return 0
51+ ;;
52+ # 自动化工具提交
53+ "chore: auto-update"*|"ci:"*|"Automated"*)
54+ echo "跳过自动化工具提交: $commit_hash - $commit_title"
55+ return 0
56+ ;;
57+ esac
58+
59+ # 检查提交信息中是否包含跳过标记
60+ if echo "$commit_msg" | grep -q -E "\[skip ci\]|\[ci skip\]|\[no signoff\]"; then
61+ echo "跳过标记了 [skip ci] 的提交: $commit_hash"
62+ return 0
63+ fi
64+
65+ # 检查合并提交 (通过父提交数量判断)
66+ local parent_count=$(git show --no-patch --format="%P" "$commit_hash" | wc -w)
67+ if [ "$parent_count" -gt 1 ]; then
68+ echo "跳过合并提交(多父提交): $commit_hash - $commit_title"
69+ return 0
70+ fi
71+
72+ # 检查空提交 (没有文件变更)
73+ if git show --format= --name-only "$commit_hash" | grep -q .; then
74+ # 有文件变更,检查 Sign-off
75+ if ! echo "$commit_msg" | grep -q "Signed-off-by:"; then
76+ echo "提交 $commit_hash 缺少 Signed-off-by 签署。"
77+ echo "提交标题: $commit_title"
78+ echo "请使用 'git commit -s' 添加签署,或手动在提交信息中包含 'Signed-off-by: Your Name <[email protected] >'。" 79+ return 1
80+ fi
81+ else
82+ echo "跳过空提交: $commit_hash - $commit_title"
83+ return 0
2784 fi
2885 }
2986
3895 fi
3996
4097 if [ -z "$COMMITS_TO_CHECK" ]; then
98+ echo "没有需要检查的提交"
4199 exit 0
42100 fi
43101
102+ echo "需要检查的提交:"
44103 echo "$COMMITS_TO_CHECK"
45104
46105 HAS_ERROR=0
54113 echo "::error::部分提交缺少开发者签署认证(DCO)。"
55114 exit 1
56115 else
57- echo "所有提交均已签署 。"
116+ echo "所有提交均已签署或已跳过 。"
58117 fi
0 commit comments