Skip to content

Commit d1a035b

Browse files
authored
feat(ci): 尝试解决冲突,增加返回上一层的目录。
1 parent a9c69c2 commit d1a035b

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

.github/workflows/GenerateDirectoryTree.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ jobs:
3838
3939
# 生成目录树并保存到index.html,排除已有的index.html和隐藏目录
4040
tree -H . -L 2 -o index.html --charset=UTF-8 --ignore-case -I "index.html|.git|.github|.vscode|generate_trees.sh" .
41-
41+
# 将 `<a href="./">.</a>` 替换为 `<a href="../">👆 回到上一级目录</a>`
42+
sed -i 's|<a href="./">.</a>|<a href="../">👆 回到上一级目录</a>|g' index.html
4243
# 添加自定义样式
43-
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
4445
4546
# 返回上一级目录
4647
cd - > /dev/null
@@ -50,20 +51,23 @@ jobs:
5051
# 执行脚本生成所有目录树
5152
chmod +x generate_trees.sh
5253
./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
5356
# 删除脚本文件
5457
rm generate_trees.sh
5558
5659
- name: Commit and push
5760
run: |
5861
git config user.name "GitHub Action"
5962
git config user.email "action@github.com"
60-
63+
# 拉取远程最新代码并rebase,确保本地与远程同步
6164
# 检查是否有文件变更
6265
if [[ -n $(git status --porcelain) ]]; then
6366
git add -A
6467
git commit -m "Update directory trees"
65-
git push
68+
git pull --rebase origin main
69+
# 推送时若有冲突,自动尝试rebase解决(需确保无手动冲突)
70+
git push --force-with-lease origin main
6671
else
6772
echo "No changes to commit"
6873
fi
69-

0 commit comments

Comments
 (0)