Skip to content

Commit b3d7d76

Browse files
authored
Merge pull request #5 from OpenListTeam/dezhishen-patch-2
fix(ci): 授予ci写入权限;增加返回上一级的目录。
2 parents 613f89b + d1a035b commit b3d7d76

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

.github/workflows/GenerateDirectoryTree.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches:
66
- main # 主分支
77

8+
permissions:
9+
contents: write
810
jobs:
911
generate-tree:
1012
runs-on: ubuntu-latest
@@ -36,9 +38,10 @@ jobs:
3638
3739
# 生成目录树并保存到index.html,排除已有的index.html和隐藏目录
3840
tree -H . -L 2 -o index.html --charset=UTF-8 --ignore-case -I "index.html|.git|.github|.vscode|generate_trees.sh" .
39-
41+
# 将 `<a href="./">.</a>` 替换为 `<a href="../">👆 回到上一级目录</a>`
42+
sed -i 's|<a href="./">.</a>|<a href="../">👆 回到上一级目录</a>|g' index.html
4043
# 添加自定义样式
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
44+
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; } .back-link { font-weight: bold; color: #0366d6; }</style>' >> index.html
4245
4346
# 返回上一级目录
4447
cd - > /dev/null
@@ -48,20 +51,23 @@ jobs:
4851
# 执行脚本生成所有目录树
4952
chmod +x generate_trees.sh
5053
./generate_trees.sh
54+
# 将生成的index.html `<a href="../">👆 回到上一级目录</a>` 替换为 `<a href="./">.</a>`
55+
sed -i 's|<a href="../">👆 回到上一级目录</a>|<a href="./">.</a>|g' index.html
5156
# 删除脚本文件
5257
rm generate_trees.sh
5358
5459
- name: Commit and push
5560
run: |
5661
git config user.name "GitHub Action"
5762
git config user.email "action@github.com"
58-
63+
# 拉取远程最新代码并rebase,确保本地与远程同步
5964
# 检查是否有文件变更
6065
if [[ -n $(git status --porcelain) ]]; then
6166
git add -A
6267
git commit -m "Update directory trees"
63-
git push
68+
git pull --rebase origin main
69+
# 推送时若有冲突,自动尝试rebase解决(需确保无手动冲突)
70+
git push --force-with-lease origin main
6471
else
6572
echo "No changes to commit"
6673
fi
67-

0 commit comments

Comments
 (0)