Skip to content

[pull] main from doocs:main #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,87 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
# 1️⃣ Checkout main 分支代码到 ./main 目录
- uses: actions/checkout@v4
with:
path: main

# 2️⃣ Checkout docs 分支到 ./mkdocs 目录
- uses: actions/checkout@v4
with:
ref: docs
path: mkdocs
- run: |
mv -f mkdocs/* .
mv solution/CONTEST_README.md docs/contest.md
mv solution/CONTEST_README_EN.md docs-en/contest.md
- name: Configure Git Credentials

# 3️⃣ 移动竞赛 README 到 mkdocs/docs 结构中
- name: Move contest files
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
cp main/solution/CONTEST_README.md mkdocs/docs/contest.md
cp main/solution/CONTEST_README_EN.md mkdocs/docs-en/contest.md

# 4️⃣ 安装 Python
- uses: actions/setup-python@v5
with:
python-version: 3.x

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

# 6️⃣ 缓存 mkdocs-material 的编译产物
- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
path: mkdocs/.cache
restore-keys: |
mkdocs-material-


# 7️⃣ 安装依赖
- name: Install dependencies
working-directory: mkdocs
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
python3 -m pip install "mkdocs-material[imaging]"
sudo apt-get install pngquant


# 8️⃣ 设置 API token 环境变量
- name: Set MKDOCS_API_KEYS environment variable
run: echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV

- run: |
# 9️⃣ 执行构建
- name: Build site
working-directory: mkdocs
run: |
python3 main.py
mkdocs build -f mkdocs.yml
mkdocs build -f mkdocs-en.yml
echo "leetcode.doocs.org" > ./site/CNAME

# 🔟 提交缓存到 docs 分支
- name: Commit cache files back to docs branch
working-directory: mkdocs
run: |
if [ -d ".git" ]; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

git add .cache/path-map.json || true
git add .cache/plugin/git-committers/page-authors.json || true

- name: Generate CNAME file
run: echo "leetcode.doocs.org" > ./site/CNAME
if git diff --cached --quiet; then
echo "No changes to commit"
else
git commit -m "chore: update committers and path map [bot]"
git push origin HEAD:docs
fi
else
echo "::error ::Git directory not found in mkdocs/. Are you sure checkout was successful?"
exit 1

# 1️⃣1️⃣ 上传构建产物
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./site
path: mkdocs/site

deploy:
needs: build
Expand Down