-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (165 loc) · 6.78 KB
/
sync-wiki.yml
File metadata and controls
209 lines (165 loc) · 6.78 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Sync Wiki
on:
push:
branches:
- main
paths:
- 'docs/learns/**/*.md'
- 'docs/best-choices/**/*.md'
workflow_dispatch:
permissions:
contents: write
jobs:
sync-wiki:
runs-on: ubuntu-latest
steps:
- name: Checkout main repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout wiki
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}.wiki
path: wiki
token: ${{ secrets.GITHUB_TOKEN }}
- name: Clean wiki
run: |
# Remove old tag pages and directories
rm -rf wiki/tags
rm -f wiki/Tags.md
# Clean learns and best-choices for fresh sync
rm -rf wiki/learns
rm -rf wiki/best-choices
- name: Sync docs to wiki
run: |
# Create directories
mkdir -p wiki/learns
# Sync learns with directory structure preserved
if [ -d "docs/learns" ]; then
find docs/learns -name "*.md" -type f ! -name "README.md" | while read file; do
# Get relative path from docs/learns
rel_path="${file#docs/learns/}"
target_file="wiki/learns/$rel_path"
target_dir=$(dirname "$target_file")
# Create directory and copy file
mkdir -p "$target_dir"
cp "$file" "$target_file"
done
fi
# Create best-choices directory
mkdir -p wiki/best-choices
# Sync best-choices
if [ -d "docs/best-choices" ]; then
find docs/best-choices -maxdepth 1 -name "*.md" -type f ! -name "README.md" | while read file; do
cp "$file" "wiki/best-choices/"
done
fi
- name: Generate Home page
run: |
cat > wiki/Home.md << EOF
# Agent Group 知识库 Wiki
欢迎访问 Agent Group Wiki!本 Wiki 自动同步自 [主仓库](${{ github.server_url }}/${{ github.repository }})。
## 学习笔记
EOF
# 递归生成学习笔记目录树
process_home_tree() {
local dir="$1"
local level="$2"
local base_path="$3"
find "$dir" -mindepth 1 -maxdepth 1 -type d | sort | while read subdir; do
local dirname=$(basename "$subdir")
# 检查是否有非 README 的 md 文件(递归检查)
local has_content=$(find "$subdir" -name "*.md" ! -name "README.md" -type f | head -1)
if [ -n "$has_content" ]; then
# 生成标题前缀 (# 数量根据层级)
local heading=""
local i=0
while [ $i -lt $level ]; do
heading="${heading}#"
i=$((i + 1))
done
heading="${heading}###"
echo "" >> wiki/Home.md
echo "${heading} ${dirname}" >> wiki/Home.md
echo "" >> wiki/Home.md
# 当前目录下的 md 文件
find "$subdir" -maxdepth 1 -name "*.md" ! -name "README.md" -type f | sort | while read file; do
local filename=$(basename "$file")
local name="${filename%.md}"
local rel_path="${base_path}${dirname}/${name}"
echo "- [${name}](./learns/${rel_path})" >> wiki/Home.md
done
# 递归处理子目录
process_home_tree "$subdir" $((level + 1)) "${base_path}${dirname}/"
fi
done
}
if [ -d "docs/learns" ]; then
process_home_tree "docs/learns" 0 ""
fi
cat >> wiki/Home.md << 'EOF'
## 最佳实践
EOF
if [ -d "docs/best-choices" ]; then
find docs/best-choices -maxdepth 1 -name "*.md" ! -name "README.md" -type f | sort | while read file; do
filename=$(basename "$file")
name="${filename%.md}"
echo "- [${name}](./best-choices/${name})" >> wiki/Home.md
done
fi
echo "" >> wiki/Home.md
echo "---" >> wiki/Home.md
echo "*最后同步:$(date -u '+%Y-%m-%d %H:%M:%S UTC')*" >> wiki/Home.md
- name: Generate Sidebar
run: |
cat > wiki/_Sidebar.md << 'EOF'
## 导航
**[首页](./Home)**
### 学习笔记
EOF
# 递归处理 learns 目录
process_sidebar_tree() {
local dir="$1"
local indent="$2"
local base_path="$3"
find "$dir" -mindepth 1 -maxdepth 1 -type d | sort | while read subdir; do
local dirname=$(basename "$subdir")
# 检查是否有非 README 的 md 文件
local has_content=$(find "$subdir" -name "*.md" ! -name "README.md" -type f | head -1)
if [ -n "$has_content" ]; then
# 目录标题
echo "${indent}**${dirname}**" >> wiki/_Sidebar.md
# 当前目录下的 md 文件
find "$subdir" -maxdepth 1 -name "*.md" ! -name "README.md" -type f | sort | while read file; do
local filename=$(basename "$file")
local name="${filename%.md}"
local rel_path="${base_path}${dirname}/${name}"
echo "${indent}- [${name}](./learns/${rel_path})" >> wiki/_Sidebar.md
done
# 递归处理子目录(增加缩进)
process_sidebar_tree "$subdir" "${indent} " "${base_path}${dirname}/"
fi
done
}
if [ -d "docs/learns" ]; then
process_sidebar_tree "docs/learns" "" ""
fi
cat >> wiki/_Sidebar.md << 'EOF'
### 最佳实践
EOF
if [ -d "docs/best-choices" ]; then
find docs/best-choices -maxdepth 1 -name "*.md" ! -name "README.md" -type f | sort | while read file; do
filename=$(basename "$file")
name="${filename%.md}"
echo "- [${name}](./best-choices/${name})" >> wiki/_Sidebar.md
done
fi
- name: Commit and push wiki
run: |
cd wiki
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add -A
git diff --quiet && git diff --staged --quiet || git commit -m "Sync from main repo: $(date -u '+%Y-%m-%d %H:%M')"
git push origin master || git push origin main