Skip to content

Commit 433be36

Browse files
authored
Merge pull request #5 from xorbitsai/doc/add_doc
ci: 优化文档部署工作流并更新 GitHub Actions 版本
2 parents ce529cc + dbc7771 commit 433be36

File tree

9 files changed

+124
-15
lines changed

9 files changed

+124
-15
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy Documentation to GitHub Pages
1+
name: Build and Deploy Documentation
22

33
on:
44
push:
@@ -25,9 +25,17 @@ jobs:
2525
uses: actions/checkout@v4
2626

2727
- name: Set up Python
28-
uses: actions/setup-python@v4
28+
uses: actions/setup-python@v5
2929
with:
30-
python-version: '3.9'
30+
python-version: '3.11'
31+
32+
- name: Cache pip dependencies
33+
uses: actions/cache@v4
34+
with:
35+
path: ~/.cache/pip
36+
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}
37+
restore-keys: |
38+
${{ runner.os }}-pip-
3139
3240
- name: Install dependencies
3341
run: |
@@ -39,23 +47,34 @@ jobs:
3947
cd docs
4048
python build_multilang.py
4149
50+
- name: Upload build artifacts (for PR preview)
51+
uses: actions/upload-artifact@v4
52+
if: github.event_name == 'pull_request'
53+
with:
54+
name: documentation-preview
55+
path: docs/build/html
56+
retention-days: 7
57+
4258
- name: Setup Pages
43-
uses: actions/configure-pages@v3
59+
uses: actions/configure-pages@v4
60+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
4461

45-
- name: Upload artifact
46-
uses: actions/upload-pages-artifact@v2
62+
- name: Upload Pages artifact
63+
uses: actions/upload-pages-artifact@v3
64+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
4765
with:
4866
path: docs/build/html
49-
67+
5068
deploy:
69+
needs: build
70+
runs-on: ubuntu-latest
71+
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
72+
5173
environment:
5274
name: github-pages
5375
url: ${{ steps.deployment.outputs.page_url }}
54-
runs-on: ubuntu-latest
55-
needs: build
56-
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
5776

5877
steps:
5978
- name: Deploy to GitHub Pages
6079
id: deployment
61-
uses: actions/deploy-pages@v2
80+
uses: actions/deploy-pages@v4

.github/workflows/pr-preview.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: PR Preview Comment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build and Deploy Documentation"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
pull-requests: write
11+
contents: read
12+
13+
jobs:
14+
comment:
15+
runs-on: ubuntu-latest
16+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
17+
18+
steps:
19+
- name: Comment on PR
20+
uses: actions/github-script@v7
21+
with:
22+
script: |
23+
// Get PR number from the workflow run
24+
const pullRequests = context.payload.workflow_run.pull_requests;
25+
if (!pullRequests || pullRequests.length === 0) {
26+
console.log('No pull requests found for this workflow run');
27+
return;
28+
}
29+
30+
const prNumber = pullRequests[0].number;
31+
const runId = context.payload.workflow_run.id;
32+
const repoOwner = context.repo.owner;
33+
const repoName = context.repo.repo;
34+
35+
const comment = `## 📚 Documentation Preview
36+
37+
✅ **Build Status**: Success
38+
🔗 **Artifacts**: [Download documentation preview](https://github.com/${repoOwner}/${repoName}/actions/runs/${runId})
39+
40+
### 📋 Build Summary
41+
- **Multi-language build**: Completed
42+
- **Chinese docs**: Generated
43+
- **English docs**: Generated
44+
- **Build artifacts**: Available for 7 days
45+
46+
### 🚀 Next Steps
47+
After merging this PR, the documentation will be automatically deployed to:
48+
- **Chinese**: https://${repoOwner}.github.io/${repoName}/
49+
- **English**: https://${repoOwner}.github.io/${repoName}/en/
50+
51+
---
52+
*This comment was automatically generated by GitHub Actions*`;
53+
54+
await github.rest.issues.createComment({
55+
issue_number: prNumber,
56+
owner: context.repo.owner,
57+
repo: context.repo.repo,
58+
body: comment
59+
});

DEPLOYMENT.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,20 @@
1717

1818
### 部署流程
1919

20-
当你推送代码到 `main``master` 分支时,GitHub Actions 会自动:
20+
#### PR 构建验证
21+
当你创建或更新 Pull Request 时,GitHub Actions 会自动:
2122

2223
1. **安装依赖**: 安装 Python 和 Sphinx 相关包
2324
2. **构建文档**: 运行 `build_multilang.py` 生成多语言文档
24-
3. **部署到 Pages**: 将构建结果发布到 GitHub Pages
25+
3. **上传预览**: 将构建结果作为 artifacts 上传(保留7天)
26+
4. **状态检查**: 在PR中显示构建状态和预览链接
27+
28+
#### 生产部署
29+
当你推送代码到 `main``master` 分支时,GitHub Actions 会自动:
30+
31+
1. **构建文档**: 执行完整的多语言构建
32+
2. **部署到 Pages**: 将构建结果发布到 GitHub Pages
33+
3. **更新网站**: 实时更新在线文档
2534

2635
### 访问地址
2736

@@ -86,6 +95,7 @@ enterprise-docs/
8695
1. **构建失败**
8796
- 检查 `requirements.txt` 中的依赖版本
8897
- 查看 GitHub Actions 日志中的错误信息
98+
- 确认使用的是最新版本的 GitHub Actions
8999

90100
2. **页面显示异常**
91101
- 确保 `.nojekyll` 文件存在于输出目录
@@ -95,6 +105,13 @@ enterprise-docs/
95105
- 确认 `switcher.json` 文件已正确生成
96106
- 检查语言切换器配置
97107

108+
4. **GitHub Actions 版本错误**
109+
- 如果遇到 "deprecated version" 错误,确保使用最新版本:
110+
- `actions/setup-python@v5`
111+
- `actions/configure-pages@v4`
112+
- `actions/upload-pages-artifact@v3`
113+
- `actions/deploy-pages@v4`
114+
98115
### 调试步骤
99116

100117
1. **本地测试**
0 Bytes
Binary file not shown.
149 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

docs/requirements.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
sphinx>=7.0.0
2-
sphinx-rtd-theme>=1.3.0
1+
sphinx>=7.0.0,<8.0.0
2+
sphinx-rtd-theme>=2.0.0
33
sphinx-intl>=2.1.0
44
sphinx-autosummary-accessors>=2023.4.0
5+
sphinx-tabs>=3.4.0
6+
sphinx-design>=0.5.0
7+
ipython>=8.0.0
8+
pydata-sphinx-theme>=0.15.0

docs/source/_static/favicon.svg

Lines changed: 10 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)