Skip to content

Commit d7f1e24

Browse files
Add GitHub Actions workflow for VitePress documentation deployment to GitHub Pages
Co-authored-by: GreenShadeZhang <[email protected]>
1 parent bcb8373 commit d7f1e24

File tree

116 files changed

+127
-15776
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+127
-15776
lines changed

.github/workflows/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# GitHub Actions 工作流说明
2+
3+
本目录包含项目的 GitHub Actions 工作流配置文件。
4+
5+
## 工作流文件
6+
7+
### `build.yml`
8+
构建和测试工作流,支持多平台(Windows、Linux、macOS)和多 .NET 版本。
9+
10+
### `ci.yml`
11+
持续集成工作流,包含代码分析和安全扫描。
12+
13+
### `release.yml`
14+
发布工作流(如果存在)。
15+
16+
### `deploy-docs.yml`
17+
文档部署工作流,自动将 VitePress 文档网站部署到 GitHub Pages。
18+
19+
#### 使用说明
20+
21+
1. **自动触发**:当向 `main` 分支推送包含 `docs-website/` 目录变更的提交时自动触发
22+
2. **手动触发**:可在 GitHub Actions 页面手动运行
23+
3. **自定义域名**:如果配置了自定义域名,请:
24+
- 在工作流文件中取消注释相应的环境变量设置
25+
- 修改 CNAME 文件创建步骤,填入你的域名
26+
-`if: false` 改为 `if: true`
27+
28+
#### 权限要求
29+
30+
工作流需要以下权限:
31+
- `contents: read` - 读取仓库内容
32+
- `pages: write` - 写入 GitHub Pages
33+
- `id-token: write` - 部署到 Pages 环境
34+
35+
#### 环境配置
36+
37+
确保在仓库设置中启用 GitHub Pages:
38+
1. 进入 Settings > Pages
39+
2. 选择 Source 为 "GitHub Actions"
40+
3. 如果使用自定义域名,在 Custom domain 中配置域名
41+
42+
## 故障排除
43+
44+
- 如果部署失败,检查 GitHub Pages 设置
45+
- 确保 `docs-website/package.json` 中的依赖正确
46+
- 检查 VitePress 配置文件中的 base 路径设置

.github/workflows/deploy-docs.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Deploy Documentation to GitHub Pages
2+
3+
on:
4+
# 在main分支推送时触发
5+
push:
6+
branches: [main]
7+
paths:
8+
- 'docs-website/**'
9+
- '.github/workflows/deploy-docs.yml'
10+
11+
# 允许手动触发
12+
workflow_dispatch:
13+
14+
# 设置GITHUB_TOKEN权限以允许部署到GitHub Pages
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
# 只允许一个并发部署,跳过正在运行的部署之间的运行队列
21+
concurrency:
22+
group: pages
23+
cancel-in-progress: false
24+
25+
jobs:
26+
build:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0 # 需要完整历史记录以获取最后修改时间
33+
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: 18
38+
cache: npm
39+
cache-dependency-path: docs-website/package-lock.json
40+
41+
- name: Setup Pages
42+
uses: actions/configure-pages@v4
43+
44+
- name: Install dependencies
45+
run: npm ci
46+
working-directory: docs-website
47+
48+
- name: Build with VitePress
49+
run: npm run build
50+
working-directory: docs-website
51+
env:
52+
# 如果使用自定义域名,取消注释下一行
53+
# CUSTOM_DOMAIN: true
54+
55+
- name: Add CNAME file (if using custom domain)
56+
run: |
57+
# 如果使用自定义域名,取消注释并修改下一行的域名
58+
# echo "your-custom-domain.com" > docs-website-dist/CNAME
59+
if: false # 将此改为 true 如果使用自定义域名
60+
61+
- name: Upload artifact
62+
uses: actions/upload-pages-artifact@v3
63+
with:
64+
path: docs-website-dist
65+
66+
deploy:
67+
environment:
68+
name: github-pages
69+
url: ${{ steps.deployment.outputs.page_url }}
70+
needs: build
71+
runs-on: ubuntu-latest
72+
steps:
73+
- name: Deploy to GitHub Pages
74+
id: deployment
75+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,5 @@ FodyWeavers.xsd
364364

365365
# VitePress build and cache directories
366366
docs-website/.vitepress/dist/
367-
docs-website/.vitepress/cache/
367+
docs-website/.vitepress/cache/
368+
docs-website-dist/

docs-website-dist/404.html

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)