Skip to content

Commit 5d8a063

Browse files
committed
CI: add check depend all workflow
deepin inclusion category: other check if upstream have someone fix which commits in our tree. Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 55f8d8b commit 5d8a063

2 files changed

Lines changed: 194 additions & 0 deletions

File tree

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
REMOTE_NAME="${REMOTE_NAME:-torvalds}"
6+
REMOTE_URL="${REMOTE_URL:-https://github.com/torvalds/linux.git}"
7+
TARGET_BRANCH="${2:-master}"
8+
9+
log_info() { echo -e "\033[32m[INFO]\033[0m $*" >&2; }
10+
log_error() { echo -e "\033[31m[ERROR]\033[0m $*" >&2; }
11+
12+
main() {
13+
[ $# -lt 1 ] && { echo "Usage: $0 <range> [branch]" >&2; exit 1; }
14+
15+
local range="$1"
16+
17+
if ! git remote get-url torvalds >/dev/null 2>&1; then
18+
git remote add torvalds "${REMOTE_URL}"
19+
else
20+
git remote set-url torvalds "${REMOTE_URL}"
21+
fi
22+
23+
git fetch torvalds
24+
25+
if ! git rev-parse --verify "$TARGET_BRANCH^{commit}" >/dev/null 2>&1; then
26+
log_error "目标分支不存在: $TARGET_BRANCH"
27+
exit 1
28+
fi
29+
30+
local tmp_target=$(mktemp)
31+
32+
log_info "正在导出 $TARGET_BRANCH 标题..."
33+
git log --format="%s" "$TARGET_BRANCH" 2>/dev/null > "$tmp_target"
34+
local target_count=$(wc -l < "$tmp_target")
35+
log_info "目标分支共 $target_count 个标题"
36+
37+
local total=$(git rev-list --count "$range" 2>/dev/null || echo "0")
38+
log_info "检查范围 $range (共 $total 个提交)..."
39+
40+
log_info "开始筛选..."
41+
echo "========================================"
42+
43+
# 使用标准AWK(兼容mawk/gawk),避免match()数组捕获
44+
git log --format="%H%n%s%n%b%n---COMMIT_END---" --reverse "$range" 2>/dev/null | \
45+
awk -v target_file="$tmp_target" -v total="$total" '
46+
BEGIN {
47+
# 加载目标分支标题到数组
48+
while ((getline line < target_file) > 0) {
49+
if (length(line) > 0) target[line] = 1
50+
}
51+
close(target_file)
52+
53+
matched = 0
54+
dup = 0
55+
no_fixes = 0
56+
no_ref = 0
57+
processed = 0
58+
59+
# 读取状态:0=读hash, 1=读subject, 2=读body
60+
state = 0
61+
}
62+
63+
/---COMMIT_END---/ {
64+
# 处理完一个commit
65+
if (hash != "") {
66+
processed++
67+
if (processed % 10 == 0) {
68+
printf "\r[INFO] 进度: %d/%d | 匹配:%d 重复:%d 无Fixes:%d 缺依赖:%d",
69+
processed, total, matched, dup, no_fixes, no_ref > "/dev/stderr"
70+
}
71+
72+
# 条件1:标题是否已存在?
73+
if (subject in target) {
74+
dup++
75+
} else {
76+
# 条件2:查找 Fixes: 行
77+
has_fixes = 0
78+
ref_found = 0
79+
80+
# 分割body行查找 Fixes:
81+
n = split(body, lines, /\n/)
82+
for (i=1; i<=n; i++) {
83+
if (lines[i] ~ /^Fixes:/) {
84+
has_fixes = 1
85+
86+
# 提取 ("...") 中的内容(兼容所有awk版本)
87+
line_content = lines[i]
88+
start_pos = index(line_content, "(\"")
89+
90+
if (start_pos > 0) {
91+
# 找到 (" 的位置,提取到 ") 结束
92+
temp = substr(line_content, start_pos + 2)
93+
end_pos = index(temp, "\")")
94+
95+
if (end_pos > 0) {
96+
ref_title = substr(temp, 1, end_pos - 1)
97+
98+
# 检查引用是否在目标分支
99+
if (ref_title in target) {
100+
ref_found = 1
101+
break
102+
}
103+
}
104+
}
105+
}
106+
}
107+
108+
if (!has_fixes) {
109+
no_fixes++
110+
} else if (!ref_found) {
111+
no_ref++
112+
} else {
113+
# 符合条件:有Fixes且引用存在,且标题不重复
114+
matched++
115+
printf "\r\033[K" > "/dev/stderr" # 清行
116+
print hash " " subject
117+
}
118+
}
119+
}
120+
121+
state = 0
122+
hash = ""
123+
subject = ""
124+
body = ""
125+
next
126+
}
127+
128+
state == 0 {
129+
hash = $0
130+
state = 1
131+
next
132+
}
133+
134+
state == 1 {
135+
subject = $0
136+
state = 2
137+
next
138+
}
139+
140+
state == 2 {
141+
# 累积body行
142+
if (body == "") body = $0
143+
else body = body "\n" $0
144+
next
145+
}
146+
147+
END {
148+
printf "\r\033[K" > "/dev/stderr"
149+
print "[INFO] 完成: 总计 " processed " | 匹配 " matched " | 重复 " dup " | 无Fixes " no_fixes " | 缺依赖 " no_ref > "/dev/stderr"
150+
}
151+
'
152+
153+
echo "========================================" >&2
154+
155+
rm -f "$tmp_target"
156+
}
157+
158+
main "$@"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: check depend all
2+
on:
3+
pull_request:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "0 2 * * *"
7+
8+
env:
9+
KBUILD_BUILD_USER: deepin-kernel-sig
10+
KBUILD_BUILD_HOST: deepin-kernel-builder
11+
email: support@deepin.org
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
permissions:
18+
pull-requests: read
19+
20+
jobs:
21+
check-depend-all:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v6
25+
with:
26+
fetch-depth: '0'
27+
- name: "Install Deps"
28+
run: |
29+
git config --global user.email $email
30+
git config --global user.name $KBUILD_BUILD_USER
31+
32+
- name: "Check Depend for all commit"
33+
run: |
34+
# Use commits in v6.6..torvalds which has Fixes Tag to check (0,pr_sha) to checkdepends
35+
bash .github/tools/check_kernel_commits.sh v6.6..torvalds/master ${{ github.event.pull_request.head.sha }}
36+

0 commit comments

Comments
 (0)