From 498055f4a56626896215413ba2411f8df8e8ea77 Mon Sep 17 00:00:00 2001 From: acbin <44314231+acbin@users.noreply.github.com> Date: Fri, 25 Apr 2025 06:18:24 +0000 Subject: [PATCH 1/2] chore: update workflow --- .github/workflows/deploy.yml | 56 +++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c9d1ff08444c5..1fe91a6504e7a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -22,55 +22,89 @@ 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 + + # 3️⃣ 移动竞赛专属 README 到 docs 结构中 + - name: Move contest files + run: | + cp main/solution/CONTEST_README.md mkdocs/docs/contest.md + cp main/solution/CONTEST_README_EN.md mkdocs/docs-en/contest.md + + # 4️⃣ 配置 Git 用户信息(后续 commit 缓存用) - name: Configure Git Credentials run: | git config user.name github-actions[bot] git config user.email 41898282+github-actions[bot]@users.noreply.github.com + # 5️⃣ 安装 Python - uses: actions/setup-python@v5 with: python-version: 3.x + # 6️⃣ 设置缓存 Key(按周) - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV + # 7️⃣ 缓存 mkdocs-material 依赖缓存 - uses: actions/cache@v4 with: key: mkdocs-material-${{ env.cache_id }} - path: .cache + path: mkdocs/.cache restore-keys: | mkdocs-material- - + + # 8️⃣ 安装依赖 - 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 - + + # 9️⃣ 设置 API token 环境变量 - name: Set MKDOCS_API_KEYS environment variable run: echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV - - run: | + # 🔟 执行构建(main.py 中访问的是 main/ 下的内容) + - 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 + + # 1️⃣1️⃣ 提交缓存(包括 path-map.json 和 page-authors.json)回 docs 分支 + - name: Commit cache files back to docs branch + working-directory: mkdocs + run: | + 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 + git add .cache/plugin/git-committers/page-authors.json - - 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 + # 1️⃣2️⃣ 上传站点构建产物 - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: ./site + path: mkdocs/site deploy: needs: build From 2b3951dde620b686153148040c8ef2e4966f85ad Mon Sep 17 00:00:00 2001 From: acbin <44314231+acbin@users.noreply.github.com> Date: Fri, 25 Apr 2025 06:29:21 +0000 Subject: [PATCH 2/2] chore: update workflow --- .github/workflows/deploy.yml | 50 +++++++++++++++++------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1fe91a6504e7a..b7027973c2ae0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -33,27 +33,21 @@ jobs: ref: docs path: mkdocs - # 3️⃣ 移动竞赛专属 README 到 docs 结构中 + # 3️⃣ 移动竞赛 README 到 mkdocs/docs 结构中 - name: Move contest files run: | cp main/solution/CONTEST_README.md mkdocs/docs/contest.md cp main/solution/CONTEST_README_EN.md mkdocs/docs-en/contest.md - # 4️⃣ 配置 Git 用户信息(后续 commit 缓存用) - - name: Configure Git Credentials - run: | - git config user.name github-actions[bot] - git config user.email 41898282+github-actions[bot]@users.noreply.github.com - - # 5️⃣ 安装 Python + # 4️⃣ 安装 Python - uses: actions/setup-python@v5 with: python-version: 3.x - # 6️⃣ 设置缓存 Key(按周) + # 5️⃣ 设置缓存 Key(按周) - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV - # 7️⃣ 缓存 mkdocs-material 依赖缓存 + # 6️⃣ 缓存 mkdocs-material 的编译产物 - uses: actions/cache@v4 with: key: mkdocs-material-${{ env.cache_id }} @@ -61,7 +55,7 @@ jobs: restore-keys: | mkdocs-material- - # 8️⃣ 安装依赖 + # 7️⃣ 安装依赖 - name: Install dependencies working-directory: mkdocs run: | @@ -70,11 +64,11 @@ jobs: python3 -m pip install "mkdocs-material[imaging]" sudo apt-get install pngquant - # 9️⃣ 设置 API token 环境变量 + # 8️⃣ 设置 API token 环境变量 - name: Set MKDOCS_API_KEYS environment variable run: echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV - # 🔟 执行构建(main.py 中访问的是 main/ 下的内容) + # 9️⃣ 执行构建 - name: Build site working-directory: mkdocs run: | @@ -83,24 +77,28 @@ jobs: mkdocs build -f mkdocs-en.yml echo "leetcode.doocs.org" > ./site/CNAME - # 1️⃣1️⃣ 提交缓存(包括 path-map.json 和 page-authors.json)回 docs 分支 + # 🔟 提交缓存到 docs 分支 - name: Commit cache files back to docs branch working-directory: mkdocs run: | - 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 - git add .cache/plugin/git-committers/page-authors.json - - if git diff --cached --quiet; then - echo "No changes to commit" + 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 + + 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 - git commit -m "chore: update committers and path map [bot]" - git push origin HEAD:docs - fi + echo "::error ::Git directory not found in mkdocs/. Are you sure checkout was successful?" + exit 1 - # 1️⃣2️⃣ 上传站点构建产物 + # 1️⃣1️⃣ 上传构建产物 - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: