Skip to content

Commit 28992b7

Browse files
committed
ci(book): add GitHub Pages deployment workflow
Adds .github/workflows/book.yml using actions/deploy-pages@v4 (modern artifact-upload model, no gh-pages branch needed). Triggers on push to main; mdbook build runs in ~10s, full pipeline ~1 minute. Owner needs to enable Pages once in repo Settings (Source: GitHub Actions). DEPLOY.md documents the one-time setup, custom domain (CNAME) flow, and troubleshooting.
1 parent 58aae59 commit 28992b7

3 files changed

Lines changed: 131 additions & 27 deletions

File tree

.github/workflows/book.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build and deploy book
2+
3+
on:
4+
push:
5+
branches: [main]
6+
# 触发条件刻意保持宽松:mdbook build 只需 ~10 秒,
7+
# 比维护一份精确路径白名单更省心。
8+
workflow_dispatch: # 允许在 Actions 页面手动重跑
9+
10+
permissions:
11+
contents: read
12+
pages: write
13+
id-token: write
14+
15+
# 同时只允许一个 deploy 在跑
16+
concurrency:
17+
group: pages
18+
cancel-in-progress: false
19+
20+
jobs:
21+
build:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v5
26+
27+
- name: Install mdBook
28+
env:
29+
MDBOOK_VERSION: 0.4.49
30+
run: |
31+
curl -sSL "https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz" \
32+
| tar -xz -C /tmp
33+
sudo mv /tmp/mdbook /usr/local/bin/mdbook
34+
mdbook --version
35+
36+
- name: Setup Pages
37+
uses: actions/configure-pages@v5
38+
39+
- name: Build book
40+
working-directory: ./book
41+
run: mdbook build
42+
43+
- name: Upload artifact
44+
uses: actions/upload-pages-artifact@v3
45+
with:
46+
path: ./book/book
47+
48+
deploy:
49+
needs: build
50+
runs-on: ubuntu-latest
51+
environment:
52+
name: github-pages
53+
url: ${{ steps.deployment.outputs.page_url }}
54+
steps:
55+
- name: Deploy to GitHub Pages
56+
id: deployment
57+
uses: actions/deploy-pages@v4

book/DEPLOY.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# 部署到 GitHub Pages
2+
3+
## 一次性配置(5 分钟)
4+
5+
CI workflow 已经在 [`.github/workflows/book.yml`](../.github/workflows/book.yml),每次 push 到 main 自动 build + deploy。但 GitHub Pages 必须**先在仓库设置里开一下**
6+
7+
### 步骤
8+
9+
1. 打开仓库 Settings:[github.com/jnMetaCode/ai-coding-guide/settings/pages](https://github.com/jnMetaCode/ai-coding-guide/settings/pages)
10+
2. **Source****GitHub Actions**(不要选 "Deploy from a branch"——我们用的是新的 Actions 直接发布模式)
11+
3. 保存。下次 push 会自动跑 workflow,跑完几分钟内 Pages 上线
12+
4. 默认 URL 是:**`https://jnmetacode.github.io/ai-coding-guide/`**
13+
14+
---
15+
16+
## 绑自定义域名(可选,推荐)
17+
18+
公开 URL 更专业,公众号文章能直接点进去。
19+
20+
### 步骤
21+
22+
1. **买域名**(推荐)
23+
- 国内:阿里云国际 / 腾讯云海外 / namesilo(境外,约 ¥50-80/年)
24+
- 推荐域名风格:`book.aibukezhi.com` / `aicodeguide.dev` / `huozaibian.ai`
25+
- 跟你公众号「AI不止语」呼应的话:`aibukezhi.com` / `aibuzhiyu.com`
26+
27+
2. **配置 DNS**(域名注册商管理面板里加)
28+
- 类型:`CNAME`
29+
- 主机记录(前缀):`book`(或 `@` 表示根域名)
30+
- 记录值:`jnmetacode.github.io`
31+
- TTL:`600` 或默认
32+
33+
3. **告诉 mdbook 这个域名是你的**——在 `book/src/` 下建一个文件 `CNAME`**注意大写、无后缀**):
34+
```
35+
book.aibukezhi.com
36+
```
37+
只一行,写你的完整域名即可。mdbook 会把这文件原样复制到输出目录,GitHub Pages 看到就认。
38+
39+
4. **GitHub Pages 验证**
40+
- DNS 生效后(一般 5-30 分钟),回到 Settings → Pages
41+
- **Custom domain** 那里填你的域名,点 **Save**
42+
- 等 GitHub 自动签 HTTPS 证书(约几分钟到 1 小时)
43+
- 勾选 **Enforce HTTPS**
44+
45+
完成后访问 `https://book.aibukezhi.com` 就能看到书了。
46+
47+
---
48+
49+
## 后续维护
50+
51+
- 改任意 markdown → push → 几分钟内自动上线
52+
- 想强制重 build:在 Actions 页面手动跑 `Build and deploy book` workflow
53+
- Build 慢/失败:去 [Actions 页面](https://github.com/jnMetaCode/ai-coding-guide/actions/workflows/book.yml) 看日志
54+
55+
## 常见问题
56+
57+
**Q:能不能两个域名同时指向(比如裸根域 + book 子域)?**
58+
A:能,但 GitHub Pages 只接受 `CNAME` 文件里写一个域名。其他域名要在 DNS 层做 301 重定向。
59+
60+
**Q:要不要开自定义 404 页?**
61+
A:mdbook 已自动生成 `404.html`,GitHub Pages 自动 fallback 到它。不用额外配置。
62+
63+
**Q:内容更新后多久上线?**
64+
A:push 后 → workflow 跑(~30 秒)→ Pages CDN 刷新(~1-2 分钟)= **2-3 分钟内可见**
65+
66+
**Q:workflow 跑失败怎么办?**
67+
A:最常见是 mdbook 二进制下载链接挂了。看 [book.yml](../.github/workflows/book.yml),调一下 `MDBOOK_VERSION`(去 [mdBook releases](https://github.com/rust-lang/mdBook/releases) 查最新版)即可。

book/README.md

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,13 @@ mdbook build
5050

5151
## 怎么发布
5252

53-
### 选项 1:GitHub Pages(最简单)
54-
55-
加一个 `.github/workflows/book.yml`,push 到 main 时自动 build + 推到 `gh-pages` 分支。
56-
57-
```yaml
58-
name: Build book
59-
on:
60-
push:
61-
branches: [main]
62-
paths: ['book/**', 'common/**', 'workflows/**', 'pitfalls/**',
63-
'*.md', 'cheatsheet.md', 'CHANGELOG.md',
64-
'claude-code/**', 'codex/**', 'cursor/**', 'copilot/**',
65-
'windsurf/**', 'trae/**', 'aider/**', 'gemini-cli/**',
66-
'kiro/**', 'openclaw/**']
67-
68-
jobs:
69-
build:
70-
runs-on: ubuntu-latest
71-
steps:
72-
- uses: actions/checkout@v5
73-
- run: cargo install mdbook
74-
- run: cd book && mdbook build
75-
- uses: peaceiris/actions-gh-pages@v4
76-
with:
77-
github_token: ${{ secrets.GITHUB_TOKEN }}
78-
publish_dir: ./book/book
79-
```
53+
### 选项 1:GitHub Pages ⭐ 已配置
54+
55+
CI 已经接好——`.github/workflows/book.yml` 在每次 push 到 main 时自动 build 并 deploy。
56+
57+
**只需在仓库 Settings 里开 Pages 一次**。完整步骤 + 自定义域名教程见 [`DEPLOY.md`](./DEPLOY.md)
58+
59+
默认 URL:**`https://jnmetacode.github.io/ai-coding-guide/`**
8060

8161
### 选项 2:Netlify / Vercel(PR preview 友好)
8262

0 commit comments

Comments
 (0)