Skip to content

Commit 613f89b

Browse files
authored
Merge pull request #4 from OpenListTeam/dezhishen-patch-1
feat(ci):Add Create Generate Directory Tree Workflow
2 parents 7d59550 + 8aecc9c commit 613f89b

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Generate Directory Tree
2+
3+
on:
4+
push:
5+
branches:
6+
- main # 主分支
7+
8+
jobs:
9+
generate-tree:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # 获取完整的仓库历史
17+
18+
- name: Generate directory tree
19+
run: |
20+
# 安装tree命令
21+
sudo apt-get install tree -y
22+
23+
# 创建生成目录树的脚本
24+
cat > generate_trees.sh << 'EOF'
25+
#!/bin/bash
26+
27+
# 查找所有文件夹,排除特定目录
28+
find . -type d \( ! -path "*/.git/*" -a ! -path "*/.github/*" -a ! -path "*/.vscode/*" \) | while read -r dir; do
29+
# 排除顶级隐藏目录
30+
if [[ "$dir" == "./.git" || "$dir" == "./.github" || "$dir" == "./.vscode" ]]; then
31+
continue
32+
fi
33+
34+
# 进入目录
35+
cd "$dir" || continue
36+
37+
# 生成目录树并保存到index.html,排除已有的index.html和隐藏目录
38+
tree -H . -L 2 -o index.html --charset=UTF-8 --ignore-case -I "index.html|.git|.github|.vscode|generate_trees.sh" .
39+
40+
# 添加自定义样式
41+
echo '<style>body { font-family: Arial, sans-serif; } .tree { margin: 20px; } .tree ul { list-style-type: none; margin-left: 20px; padding-left: 1em; position: relative; } .tree ul ul::before { content: ""; display: block; position: absolute; left: 0; top: 0; bottom: 0; width: 1px; background-color: #ccc; } .tree li { margin: 5px 0; padding-left: 1.5em; position: relative; } .tree li::before { content: ""; display: block; position: absolute; left: 0; top: 0.7em; width: 10px; height: 1px; background-color: #ccc; } .tree a { color: #0366d6; text-decoration: none; } .tree a:hover { text-decoration: underline; }</style>' >> index.html
42+
43+
# 返回上一级目录
44+
cd - > /dev/null
45+
done
46+
EOF
47+
48+
# 执行脚本生成所有目录树
49+
chmod +x generate_trees.sh
50+
./generate_trees.sh
51+
# 删除脚本文件
52+
rm generate_trees.sh
53+
54+
- name: Commit and push
55+
run: |
56+
git config user.name "GitHub Action"
57+
git config user.email "action@github.com"
58+
59+
# 检查是否有文件变更
60+
if [[ -n $(git status --porcelain) ]]; then
61+
git add -A
62+
git commit -m "Update directory trees"
63+
git push
64+
else
65+
echo "No changes to commit"
66+
fi
67+

0 commit comments

Comments
 (0)