@@ -22,24 +22,28 @@ jobs:
22
22
build :
23
23
runs-on : ubuntu-latest
24
24
steps :
25
- # 1️⃣ main 分支代码
25
+ # 1️⃣ main 分支(完整历史)
26
26
- uses : actions/checkout@v4
27
27
with :
28
28
fetch-depth : 0
29
29
30
- # 2️⃣ docs 分支代码放到 mkdocs/ 目录
30
+ # 2️⃣ docs 分支 → mkdocs/ 目录(完整历史)
31
31
- uses : actions/checkout@v4
32
32
with :
33
33
ref : docs
34
34
path : mkdocs
35
+ fetch-depth : 0
36
+
37
+ # 3️⃣ 同步 mkdocs 内容(排除 .git)
38
+ - name : Sync docs branch content
39
+ run : |
40
+ rsync -a --remove-source-files --exclude='.git' mkdocs/ ./
41
+ rm -rf mkdocs # 清理空目录
35
42
36
- # 3️⃣ 整理目录结构
37
- - run : |
38
- mv -f mkdocs/* .
39
43
mv solution/CONTEST_README.md docs/contest.md
40
44
mv solution/CONTEST_README_EN.md docs-en/contest.md
41
45
42
- # 4️⃣ 配置 Git 身份(供后续提交缓存 )
46
+ # 4️⃣ Git 身份(给后续独立 clone 用 )
43
47
- name : Configure Git Credentials
44
48
run : |
45
49
git config user.name github-actions[bot]
50
54
with :
51
55
python-version : 3.x
52
56
53
- # 6️⃣ 设置一周一次失效的缓存 key
57
+ # 6️⃣ 一周一失效的缓存 key
54
58
- run : echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
55
59
56
60
# 7️⃣ 复用 .cache
69
73
python3 -m pip install "mkdocs-material[imaging]"
70
74
sudo apt-get install pngquant
71
75
72
- # 9️⃣ 传递 GitHub Token 池
73
- - name : Set MKDOCS_API_KEYS environment variable
76
+ # 9️⃣ 注入 GitHub Token 池
77
+ - name : Set MKDOCS_API_KEYS
74
78
run : echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV
75
79
76
80
# 🔟 生成导航 & 构建站点
@@ -80,24 +84,29 @@ jobs:
80
84
mkdocs build -f mkdocs-en.yml
81
85
82
86
# 11️⃣ 生成 CNAME
83
- - name : Generate CNAME file
87
+ - name : Generate CNAME
84
88
run : echo "leetcode.doocs.org" > ./site/CNAME
85
89
86
- # 12️⃣ 👉 提交 committer 缓存回 docs 分支
87
- - name : Commit committer cache
90
+ # 12️⃣ 独立克隆 docs 分支并提交 committer 缓存
91
+ - name : Commit committer cache to docs branch
92
+ if : github.ref == 'refs/heads/main'
93
+ env :
94
+ GH_REPO : ${{ github.repository }}
95
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
88
96
run : |
89
- if [[ -f .cache/plugin/git-committers/page-authors.json ]]; then
90
- git switch docs
91
- mkdir -p .cache/plugin/git-committers
92
- cp ../.cache/plugin/git-committers/page-authors.json .cache/plugin/git-committers/
97
+ CACHE_FILE=".cache/plugin/git-committers/page-authors.json"
98
+ if [[ -f "$CACHE_FILE" ]]; then
99
+ git clone --depth 1 --branch docs "https://x-access-token:${GH_TOKEN}@github.com/${GH_REPO}.git" docs-cache
100
+ mkdir -p docs-cache/.cache/plugin/git-committers
101
+ cp "$CACHE_FILE" docs-cache/.cache/plugin/git-committers/
102
+ cd docs-cache
93
103
git add .cache/plugin/git-committers/page-authors.json
94
104
git commit -m "chore: update page-authors cache [skip ci]" || echo "No changes to commit"
105
+ git push origin docs
106
+ else
107
+ echo "Cache file not found; skip commit."
95
108
fi
96
109
97
- - name : Push cache back to docs branch
98
- if : github.ref == 'refs/heads/main'
99
- run : git push origin docs
100
-
101
110
# 13️⃣ 上传构建产物
102
111
- name : Upload artifact
103
112
uses : actions/upload-pages-artifact@v3
0 commit comments