@@ -22,55 +22,89 @@ jobs:
22
22
build :
23
23
runs-on : ubuntu-latest
24
24
steps :
25
+ # 1️⃣ Checkout main 分支代码到 ./main 目录
25
26
- uses : actions/checkout@v4
27
+ with :
28
+ path : main
29
+
30
+ # 2️⃣ Checkout docs 分支到 ./mkdocs 目录
26
31
- uses : actions/checkout@v4
27
32
with :
28
33
ref : docs
29
34
path : mkdocs
30
- - run : |
31
- mv -f mkdocs/* .
32
- mv solution/CONTEST_README.md docs/contest.md
33
- mv solution/CONTEST_README_EN.md docs-en/contest.md
35
+
36
+ # 3️⃣ 移动竞赛专属 README 到 docs 结构中
37
+ - name : Move contest files
38
+ run : |
39
+ cp main/solution/CONTEST_README.md mkdocs/docs/contest.md
40
+ cp main/solution/CONTEST_README_EN.md mkdocs/docs-en/contest.md
41
+
42
+ # 4️⃣ 配置 Git 用户信息(后续 commit 缓存用)
34
43
- name : Configure Git Credentials
35
44
run : |
36
45
git config user.name github-actions[bot]
37
46
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
38
47
48
+ # 5️⃣ 安装 Python
39
49
- uses : actions/setup-python@v5
40
50
with :
41
51
python-version : 3.x
42
52
53
+ # 6️⃣ 设置缓存 Key(按周)
43
54
- run : echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
44
55
56
+ # 7️⃣ 缓存 mkdocs-material 依赖缓存
45
57
- uses : actions/cache@v4
46
58
with :
47
59
key : mkdocs-material-${{ env.cache_id }}
48
- path : .cache
60
+ path : mkdocs/ .cache
49
61
restore-keys : |
50
62
mkdocs-material-
51
-
63
+
64
+ # 8️⃣ 安装依赖
52
65
- name : Install dependencies
66
+ working-directory : mkdocs
53
67
run : |
54
68
python3 -m pip install --upgrade pip
55
69
python3 -m pip install -r requirements.txt
56
70
python3 -m pip install "mkdocs-material[imaging]"
57
71
sudo apt-get install pngquant
58
-
72
+
73
+ # 9️⃣ 设置 API token 环境变量
59
74
- name : Set MKDOCS_API_KEYS environment variable
60
75
run : echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV
61
76
62
- - run : |
77
+ # 🔟 执行构建(main.py 中访问的是 main/ 下的内容)
78
+ - name : Build site
79
+ working-directory : mkdocs
80
+ run : |
63
81
python3 main.py
64
82
mkdocs build -f mkdocs.yml
65
83
mkdocs build -f mkdocs-en.yml
84
+ echo "leetcode.doocs.org" > ./site/CNAME
85
+
86
+ # 1️⃣1️⃣ 提交缓存(包括 path-map.json 和 page-authors.json)回 docs 分支
87
+ - name : Commit cache files back to docs branch
88
+ working-directory : mkdocs
89
+ run : |
90
+ git config user.name "github-actions[bot]"
91
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
92
+
93
+ git add .cache/path-map.json
94
+ git add .cache/plugin/git-committers/page-authors.json
66
95
67
- - name : Generate CNAME file
68
- run : echo "leetcode.doocs.org" > ./site/CNAME
96
+ if git diff --cached --quiet; then
97
+ echo "No changes to commit"
98
+ else
99
+ git commit -m "chore: update committers and path map [bot]"
100
+ git push origin HEAD:docs
101
+ fi
69
102
103
+ # 1️⃣2️⃣ 上传站点构建产物
70
104
- name : Upload artifact
71
105
uses : actions/upload-pages-artifact@v3
72
106
with :
73
- path : . /site
107
+ path : mkdocs /site
74
108
75
109
deploy :
76
110
needs : build
0 commit comments