|
15 | 15 | - basic/** |
16 | 16 |
|
17 | 17 | concurrency: |
18 | | - group: ${{github.workflow}} - ${{github.ref}} |
| 18 | + group: ${{ github.workflow }} - ${{ github.ref }} |
19 | 19 | cancel-in-progress: true |
20 | 20 |
|
21 | 21 | jobs: |
22 | 22 | build: |
23 | 23 | runs-on: ubuntu-latest |
24 | 24 | steps: |
| 25 | + # 1️⃣ main 分支代码 |
25 | 26 | - uses: actions/checkout@v4 |
| 27 | + |
| 28 | + # 2️⃣ docs 分支代码放到 mkdocs/ 目录 |
26 | 29 | - uses: actions/checkout@v4 |
27 | 30 | with: |
28 | 31 | ref: docs |
29 | 32 | path: mkdocs |
| 33 | + |
| 34 | + # 3️⃣ 整理目录结构 |
30 | 35 | - run: | |
31 | 36 | mv -f mkdocs/* . |
32 | 37 | mv solution/CONTEST_README.md docs/contest.md |
33 | 38 | mv solution/CONTEST_README_EN.md docs-en/contest.md |
| 39 | +
|
| 40 | + # 4️⃣ 配置 Git 身份(供后续提交缓存) |
34 | 41 | - name: Configure Git Credentials |
35 | 42 | run: | |
36 | 43 | git config user.name github-actions[bot] |
37 | 44 | git config user.email 41898282+github-actions[bot]@users.noreply.github.com |
38 | 45 |
|
| 46 | + # 5️⃣ Python 环境 |
39 | 47 | - uses: actions/setup-python@v5 |
40 | 48 | with: |
41 | 49 | python-version: 3.x |
42 | 50 |
|
| 51 | + # 6️⃣ 设置一周一次失效的缓存 key |
43 | 52 | - run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV |
44 | 53 |
|
| 54 | + # 7️⃣ 复用 .cache |
45 | 55 | - uses: actions/cache@v4 |
46 | 56 | with: |
47 | 57 | key: mkdocs-material-${{ env.cache_id }} |
48 | 58 | path: .cache |
49 | 59 | restore-keys: | |
50 | 60 | mkdocs-material- |
51 | | - |
| 61 | +
|
| 62 | + # 8️⃣ 安装依赖 |
52 | 63 | - name: Install dependencies |
53 | 64 | run: | |
54 | 65 | python3 -m pip install --upgrade pip |
55 | 66 | python3 -m pip install -r requirements.txt |
56 | 67 | python3 -m pip install "mkdocs-material[imaging]" |
57 | 68 | sudo apt-get install pngquant |
58 | | - |
| 69 | +
|
| 70 | + # 9️⃣ 传递 GitHub Token 池 |
59 | 71 | - name: Set MKDOCS_API_KEYS environment variable |
60 | 72 | run: echo "MKDOCS_API_KEYS=${{ secrets.MKDOCS_API_KEYS }}" >> $GITHUB_ENV |
61 | 73 |
|
| 74 | + # 🔟 生成导航 & 构建站点 |
62 | 75 | - run: | |
63 | 76 | python3 main.py |
64 | 77 | mkdocs build -f mkdocs.yml |
65 | 78 | mkdocs build -f mkdocs-en.yml |
66 | 79 |
|
| 80 | + # 11️⃣ 生成 CNAME |
67 | 81 | - name: Generate CNAME file |
68 | 82 | run: echo "leetcode.doocs.org" > ./site/CNAME |
69 | 83 |
|
| 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️⃣ 上传构建产物 |
70 | 100 | - name: Upload artifact |
71 | 101 | uses: actions/upload-pages-artifact@v3 |
72 | 102 | with: |
|
0 commit comments