@@ -22,39 +22,38 @@ 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
35
fetch-depth : 0
36
36
37
- # 3️⃣ 同步 mkdocs 内容( 排除 .git)
37
+ # 3️⃣ 同步 docs 分支静态内容到根目录, 排除 .git
38
38
- name : Sync docs branch content
39
39
run : |
40
40
rsync -a --remove-source-files --exclude='.git' mkdocs/ ./
41
- rm -rf mkdocs # 清理空目录
42
-
41
+ rm -rf mkdocs
43
42
mv solution/CONTEST_README.md docs/contest.md
44
43
mv solution/CONTEST_README_EN.md docs-en/contest.md
45
44
46
- # 4️⃣ Git 身份(给后续独立 clone 用 )
45
+ # 4️⃣ 配置 Git 身份(备用 )
47
46
- name : Configure Git Credentials
48
47
run : |
49
48
git config user.name github-actions[bot]
50
49
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
51
50
52
- # 5️⃣ Python 环境
51
+ # 5️⃣ 安装 Python
53
52
- uses : actions/setup-python@v5
54
53
with :
55
54
python-version : 3.x
56
55
57
- # 6️⃣ 一周一失效的缓存 key
56
+ # 6️⃣ 一周一次更新的缓存 key
58
57
- run : echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
59
58
60
59
# 7️⃣ 复用 .cache
71
70
python3 -m pip install --upgrade pip
72
71
python3 -m pip install -r requirements.txt
73
72
python3 -m pip install "mkdocs-material[imaging]"
74
- sudo apt-get install pngquant
73
+ sudo apt-get install -y pngquant
75
74
76
75
# 9️⃣ 注入 GitHub Token 池
77
76
- name : Set MKDOCS_API_KEYS
@@ -87,26 +86,29 @@ jobs:
87
86
- name : Generate CNAME
88
87
run : echo "leetcode.doocs.org" > ./site/CNAME
89
88
90
- # 12️⃣ 独立克隆 docs 分支并提交 committer 缓存
89
+ # 12️⃣ 独立 clone docs 分支并提交 committer 缓存
91
90
- name : Commit committer cache to docs branch
92
91
if : github.ref == 'refs/heads/main'
93
92
env :
94
93
GH_REPO : ${{ github.repository }}
95
94
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
96
95
run : |
97
96
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
107
98
echo "Cache file not found; skip commit."
99
+ exit 0
108
100
fi
109
101
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
+
110
112
# 13️⃣ 上传构建产物
111
113
- name : Upload artifact
112
114
uses : actions/upload-pages-artifact@v3
@@ -115,13 +117,13 @@ jobs:
115
117
116
118
deploy :
117
119
needs : build
120
+ runs-on : ubuntu-latest
118
121
permissions :
119
122
pages : write
120
123
id-token : write
121
124
environment :
122
125
name : github_pages
123
126
url : ${{ steps.deployment.outputs.page_url }}
124
- runs-on : ubuntu-latest
125
127
steps :
126
128
- name : Deploy to GitHub Pages
127
129
id : deployment
0 commit comments