@@ -22,39 +22,38 @@ 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
3535 fetch-depth : 0
3636
37- # 3️⃣ 同步 mkdocs 内容( 排除 .git)
37+ # 3️⃣ 同步 docs 分支静态内容到根目录, 排除 .git
3838 - name : Sync docs branch content
3939 run : |
4040 rsync -a --remove-source-files --exclude='.git' mkdocs/ ./
41- rm -rf mkdocs # 清理空目录
42-
41+ rm -rf mkdocs
4342 mv solution/CONTEST_README.md docs/contest.md
4443 mv solution/CONTEST_README_EN.md docs-en/contest.md
4544
46- # 4️⃣ Git 身份(给后续独立 clone 用 )
45+ # 4️⃣ 配置 Git 身份(备用 )
4746 - name : Configure Git Credentials
4847 run : |
4948 git config user.name github-actions[bot]
5049 git config user.email 41898282+github-actions[bot]@users.noreply.github.com
5150
52- # 5️⃣ Python 环境
51+ # 5️⃣ 安装 Python
5352 - uses : actions/setup-python@v5
5453 with :
5554 python-version : 3.x
5655
57- # 6️⃣ 一周一失效的缓存 key
56+ # 6️⃣ 一周一次更新的缓存 key
5857 - run : echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
5958
6059 # 7️⃣ 复用 .cache
7170 python3 -m pip install --upgrade pip
7271 python3 -m pip install -r requirements.txt
7372 python3 -m pip install "mkdocs-material[imaging]"
74- sudo apt-get install pngquant
73+ sudo apt-get install -y pngquant
7574
7675 # 9️⃣ 注入 GitHub Token 池
7776 - name : Set MKDOCS_API_KEYS
@@ -87,26 +86,29 @@ jobs:
8786 - name : Generate CNAME
8887 run : echo "leetcode.doocs.org" > ./site/CNAME
8988
90- # 12️⃣ 独立克隆 docs 分支并提交 committer 缓存
89+ # 12️⃣ 独立 clone docs 分支并提交 committer 缓存
9190 - name : Commit committer cache to docs branch
9291 if : github.ref == 'refs/heads/main'
9392 env :
9493 GH_REPO : ${{ github.repository }}
9594 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9695 run : |
9796 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
103- git add .cache/plugin/git-committers/page-authors.json
104- git commit -m "chore: update page-authors cache [skip ci]" || echo "No changes to commit"
105- git push origin docs
106- else
97+ if [[ ! -f "$CACHE_FILE" ]]; then
10798 echo "Cache file not found; skip commit."
99+ exit 0
108100 fi
109101
102+ echo "Cloning docs branch ..."
103+ git clone --depth 1 --branch docs "https://x-access-token:${GH_TOKEN}@github.com/${GH_REPO}.git" docs-cache
104+ mkdir -p docs-cache/.cache/plugin/git-committers
105+ cp "$CACHE_FILE" docs-cache/.cache/plugin/git-committers/
106+
107+ cd docs-cache
108+ git add .cache/plugin/git-committers/page-authors.json
109+ git commit -m "chore: update page-authors cache [skip ci]" || echo "No changes to commit"
110+ git push origin docs
111+
110112 # 13️⃣ 上传构建产物
111113 - name : Upload artifact
112114 uses : actions/upload-pages-artifact@v3
@@ -115,13 +117,13 @@ jobs:
115117
116118 deploy :
117119 needs : build
120+ runs-on : ubuntu-latest
118121 permissions :
119122 pages : write
120123 id-token : write
121124 environment :
122125 name : github_pages
123126 url : ${{ steps.deployment.outputs.page_url }}
124- runs-on : ubuntu-latest
125127 steps :
126128 - name : Deploy to GitHub Pages
127129 id : deployment
0 commit comments