Skip to content

Commit 8c8d9c6

Browse files
committed
chore: update workflow
1 parent dacb2d0 commit 8c8d9c6

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

.github/workflows/deploy.yml

+33-3
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,88 @@ on:
1515
- basic/**
1616

1717
concurrency:
18-
group: ${{github.workflow}} - ${{github.ref}}
18+
group: ${{ github.workflow }} - ${{ github.ref }}
1919
cancel-in-progress: true
2020

2121
jobs:
2222
build:
2323
runs-on: ubuntu-latest
2424
steps:
25+
# 1️⃣ main 分支代码
2526
- uses: actions/checkout@v4
27+
28+
# 2️⃣ docs 分支代码放到 mkdocs/ 目录
2629
- uses: actions/checkout@v4
2730
with:
2831
ref: docs
2932
path: mkdocs
33+
34+
# 3️⃣ 整理目录结构
3035
- run: |
3136
mv -f mkdocs/* .
3237
mv solution/CONTEST_README.md docs/contest.md
3338
mv solution/CONTEST_README_EN.md docs-en/contest.md
39+
40+
# 4️⃣ 配置 Git 身份(供后续提交缓存)
3441
- name: Configure Git Credentials
3542
run: |
3643
git config user.name github-actions[bot]
3744
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
3845
46+
# 5️⃣ Python 环境
3947
- uses: actions/setup-python@v5
4048
with:
4149
python-version: 3.x
4250

51+
# 6️⃣ 设置一周一次失效的缓存 key
4352
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
4453

54+
# 7️⃣ 复用 .cache
4555
- uses: actions/cache@v4
4656
with:
4757
key: mkdocs-material-${{ env.cache_id }}
4858
path: .cache
4959
restore-keys: |
5060
mkdocs-material-
51-
61+
62+
# 8️⃣ 安装依赖
5263
- name: Install dependencies
5364
run: |
5465
python3 -m pip install --upgrade pip
5566
python3 -m pip install -r requirements.txt
5667
python3 -m pip install "mkdocs-material[imaging]"
5768
sudo apt-get install pngquant
58-
69+
70+
# 9️⃣ 传递 GitHub Token 池
5971
- name: Set MKDOCS_API_KEYS environment variable
6072
run: echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV
6173

74+
# 🔟 生成导航 & 构建站点
6275
- run: |
6376
python3 main.py
6477
mkdocs build -f mkdocs.yml
6578
mkdocs build -f mkdocs-en.yml
6679
80+
# 11️⃣ 生成 CNAME
6781
- name: Generate CNAME file
6882
run: echo "leetcode.doocs.org" > ./site/CNAME
6983

84+
# 12️⃣ 👉 提交 committer 缓存回 docs 分支
85+
- name: Commit committer cache
86+
run: |
87+
if [[ -f .cache/plugin/git-committers/page-authors.json ]]; then
88+
git switch docs
89+
mkdir -p .cache/plugin/git-committers
90+
cp ../.cache/plugin/git-committers/page-authors.json .cache/plugin/git-committers/
91+
git add .cache/plugin/git-committers/page-authors.json
92+
git commit -m "chore: update page-authors cache [skip ci]" || echo "No changes to commit"
93+
fi
94+
95+
- name: Push cache back to docs branch
96+
if: github.ref == 'refs/heads/main'
97+
run: git push origin docs
98+
99+
# 13️⃣ 上传构建产物
70100
- name: Upload artifact
71101
uses: actions/upload-pages-artifact@v3
72102
with:

0 commit comments

Comments
 (0)