@@ -22,94 +22,80 @@ jobs:
22
22
build :
23
23
runs-on : ubuntu-latest
24
24
steps :
25
- # 1️⃣ 拉取 main 分支(完整历史)
26
25
- uses : actions/checkout@v4
27
26
with :
28
27
fetch-depth : 0
29
28
30
- # 2️⃣ 拉取 docs 分支到 mkdocs/(完整历史)
31
29
- uses : actions/checkout@v4
32
30
with :
33
31
ref : docs
34
32
path : mkdocs
35
33
fetch-depth : 0
36
34
37
- # 3️⃣ 同步 docs 分支静态内容到根目录,排除 .git
38
35
- name : Sync docs branch content
39
36
run : |
40
37
rsync -a --remove-source-files --exclude='.git' mkdocs/ ./
41
38
rm -rf mkdocs
42
39
mv solution/CONTEST_README.md docs/contest.md
43
40
mv solution/CONTEST_README_EN.md docs-en/contest.md
44
41
45
- # 4️⃣ 配置 Git 身份(备用)
46
42
- name : Configure Git Credentials
47
43
run : |
48
44
git config user.name github-actions[bot]
49
45
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
50
46
51
- # 5️⃣ 安装 Python
52
47
- uses : actions/setup-python@v5
53
48
with :
54
49
python-version : 3.x
55
50
56
- # 6️⃣ 一周一次更新的缓存 key
57
51
- run : echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
58
52
59
- # 7️⃣ 复用 .cache
60
53
- uses : actions/cache@v4
61
54
with :
62
55
key : mkdocs-material-${{ env.cache_id }}
63
56
path : .cache
64
57
restore-keys : |
65
58
mkdocs-material-
66
59
67
- # 8️⃣ 安装依赖
68
60
- name : Install dependencies
69
61
run : |
70
62
python3 -m pip install --upgrade pip
71
63
python3 -m pip install -r requirements.txt
72
64
python3 -m pip install "mkdocs-material[imaging]"
73
65
sudo apt-get install -y pngquant
74
66
75
- # 9️⃣ 注入 GitHub Token 池
76
67
- name : Set MKDOCS_API_KEYS
77
68
run : echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV
78
69
79
- # 🔟 生成导航 & 构建站点
80
70
- run : |
81
71
python3 main.py
82
72
mkdocs build -f mkdocs.yml
83
73
mkdocs build -f mkdocs-en.yml
84
74
85
- # 11️⃣ 生成 CNAME
86
75
- name : Generate CNAME
87
76
run : echo "leetcode.doocs.org" > ./site/CNAME
88
-
89
- # 12️⃣ 独立 clone docs 分支并提交 committer 缓存
77
+
90
78
- name : Commit committer cache to docs branch
91
79
if : github.ref == 'refs/heads/main'
92
80
env :
93
81
GH_REPO : ${{ github.repository }}
94
82
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
95
83
run : |
96
- CACHE_FILE=".cache/plugin/ git-committers/page-authors .json"
84
+ CACHE_FILE=".git-committers-cache .json"
97
85
if [[ ! -f "$CACHE_FILE" ]]; then
98
86
echo "Cache file not found; skip commit."
99
87
exit 0
100
88
fi
101
89
102
90
echo "Cloning docs branch ..."
103
91
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/
92
+ cp "$CACHE_FILE" docs-cache/
106
93
107
94
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"
95
+ git add .git-committers-cache .json
96
+ git commit -m "chore: update committer cache [skip ci]" || echo "No changes to commit"
110
97
git push origin docs
111
98
112
- # 13️⃣ 上传构建产物
113
99
- name : Upload artifact
114
100
uses : actions/upload-pages-artifact@v3
115
101
with :
0 commit comments