Skip to content

Commit 498055f

Browse files
committed
chore: update workflow
1 parent dacb2d0 commit 498055f

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

.github/workflows/deploy.yml

+45-11
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,89 @@ jobs:
2222
build:
2323
runs-on: ubuntu-latest
2424
steps:
25+
# 1️⃣ Checkout main 分支代码到 ./main 目录
2526
- uses: actions/checkout@v4
27+
with:
28+
path: main
29+
30+
# 2️⃣ Checkout docs 分支到 ./mkdocs 目录
2631
- uses: actions/checkout@v4
2732
with:
2833
ref: docs
2934
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 缓存用)
3443
- name: Configure Git Credentials
3544
run: |
3645
git config user.name github-actions[bot]
3746
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
3847
48+
# 5️⃣ 安装 Python
3949
- uses: actions/setup-python@v5
4050
with:
4151
python-version: 3.x
4252

53+
# 6️⃣ 设置缓存 Key(按周)
4354
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
4455

56+
# 7️⃣ 缓存 mkdocs-material 依赖缓存
4557
- uses: actions/cache@v4
4658
with:
4759
key: mkdocs-material-${{ env.cache_id }}
48-
path: .cache
60+
path: mkdocs/.cache
4961
restore-keys: |
5062
mkdocs-material-
51-
63+
64+
# 8️⃣ 安装依赖
5265
- name: Install dependencies
66+
working-directory: mkdocs
5367
run: |
5468
python3 -m pip install --upgrade pip
5569
python3 -m pip install -r requirements.txt
5670
python3 -m pip install "mkdocs-material[imaging]"
5771
sudo apt-get install pngquant
58-
72+
73+
# 9️⃣ 设置 API token 环境变量
5974
- name: Set MKDOCS_API_KEYS environment variable
6075
run: echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV
6176

62-
- run: |
77+
# 🔟 执行构建(main.py 中访问的是 main/ 下的内容)
78+
- name: Build site
79+
working-directory: mkdocs
80+
run: |
6381
python3 main.py
6482
mkdocs build -f mkdocs.yml
6583
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
6695
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
69102
103+
# 1️⃣2️⃣ 上传站点构建产物
70104
- name: Upload artifact
71105
uses: actions/upload-pages-artifact@v3
72106
with:
73-
path: ./site
107+
path: mkdocs/site
74108

75109
deploy:
76110
needs: build

0 commit comments

Comments
 (0)