@@ -22,24 +22,28 @@ jobs:
2222 build :
2323 runs-on : ubuntu-latest
2424 steps :
25- # 1️⃣ main 分支代码
25+ # 1️⃣ main 分支(完整历史)
2626 - uses : actions/checkout@v4
2727 with :
2828 fetch-depth : 0
2929
30- # 2️⃣ docs 分支代码放到 mkdocs/ 目录
30+ # 2️⃣ docs 分支 → mkdocs/ 目录(完整历史)
3131 - uses : actions/checkout@v4
3232 with :
3333 ref : docs
3434 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 # 清理空目录
3542
36- # 3️⃣ 整理目录结构
37- - run : |
38- mv -f mkdocs/* .
3943 mv solution/CONTEST_README.md docs/contest.md
4044 mv solution/CONTEST_README_EN.md docs-en/contest.md
4145
42- # 4️⃣ 配置 Git 身份(供后续提交缓存 )
46+ # 4️⃣ Git 身份(给后续独立 clone 用 )
4347 - name : Configure Git Credentials
4448 run : |
4549 git config user.name github-actions[bot]
5054 with :
5155 python-version : 3.x
5256
53- # 6️⃣ 设置一周一次失效的缓存 key
57+ # 6️⃣ 一周一失效的缓存 key
5458 - run : echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
5559
5660 # 7️⃣ 复用 .cache
6973 python3 -m pip install "mkdocs-material[imaging]"
7074 sudo apt-get install pngquant
7175
72- # 9️⃣ 传递 GitHub Token 池
73- - name : Set MKDOCS_API_KEYS environment variable
76+ # 9️⃣ 注入 GitHub Token 池
77+ - name : Set MKDOCS_API_KEYS
7478 run : echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV
7579
7680 # 🔟 生成导航 & 构建站点
@@ -80,24 +84,29 @@ jobs:
8084 mkdocs build -f mkdocs-en.yml
8185
8286 # 11️⃣ 生成 CNAME
83- - name : Generate CNAME file
87+ - name : Generate CNAME
8488 run : echo "leetcode.doocs.org" > ./site/CNAME
8589
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 }}
8896 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
93103 git add .cache/plugin/git-committers/page-authors.json
94104 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."
95108 fi
96109
97- - name : Push cache back to docs branch
98- if : github.ref == 'refs/heads/main'
99- run : git push origin docs
100-
101110 # 13️⃣ 上传构建产物
102111 - name : Upload artifact
103112 uses : actions/upload-pages-artifact@v3
0 commit comments