Skip to content

Commit 0743ab7

Browse files
feat: 添加 GitHub Actions 工作流配置,包括 CI/CD、文档部署和 NPM 发布
1 parent 11dcf1c commit 0743ab7

File tree

6 files changed

+459
-0
lines changed

6 files changed

+459
-0
lines changed

.github/release-drafter.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name-template: 'v$RESOLVED_VERSION 🎉'
2+
tag-template: 'v$RESOLVED_VERSION'
3+
4+
categories:
5+
- title: '🚀 Features'
6+
labels:
7+
- 'feature'
8+
- 'enhancement'
9+
- title: '🐛 Bug Fixes'
10+
labels:
11+
- 'fix'
12+
- 'bugfix'
13+
- 'bug'
14+
- title: '🧰 Maintenance'
15+
labels:
16+
- 'chore'
17+
- 'dependencies'
18+
- title: '📚 Documentation'
19+
labels:
20+
- 'documentation'
21+
- 'docs'
22+
- title: '🎨 Styling'
23+
labels:
24+
- 'style'
25+
- title: '⚡ Performance'
26+
labels:
27+
- 'performance'
28+
- title: '🔒 Security'
29+
labels:
30+
- 'security'
31+
32+
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
33+
change-title-escapes: '\<*_&'
34+
35+
version-resolver:
36+
major:
37+
labels:
38+
- 'major'
39+
- 'breaking'
40+
minor:
41+
labels:
42+
- 'minor'
43+
- 'feature'
44+
patch:
45+
labels:
46+
- 'patch'
47+
- 'fix'
48+
- 'bugfix'
49+
default: patch
50+
51+
template: |
52+
## 📋 Changes
53+
54+
$CHANGES
55+
56+
## 📦 Installation
57+
58+
```bash
59+
npm install tml-ui@$RESOLVED_VERSION
60+
```
61+
62+
## 👥 Contributors
63+
64+
$CONTRIBUTORS

.github/workflows/README.md

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# GitHub Actions Workflows 配置说明
2+
3+
本项目包含以下 GitHub Actions 工作流配置,用于自动化构建、测试、发布和部署流程。
4+
5+
## 📋 工作流列表
6+
7+
### 1. CI/CD 持续集成 (`.github/workflows/ci.yml`)
8+
9+
**触发条件:**
10+
- `main``develop` 分支的 push
11+
- 针对 `main``develop` 分支的 Pull Request
12+
13+
**功能:**
14+
- ✅ 多 Node.js 版本测试(18.x, 20.x)
15+
- ✅ TypeScript 类型检查
16+
- ✅ 代码格式检查(Prettier)
17+
- ✅ 代码规范检查(ESLint)
18+
- ✅ 单元测试(Vitest)
19+
- ✅ 构建验证
20+
- ✅ 上传构建产物
21+
22+
**无需配置 Secrets**
23+
24+
---
25+
26+
### 2. NPM 自动发布 (`.github/workflows/publish.yml`)
27+
28+
**触发条件:**
29+
- 推送带有 `v*` 前缀的标签(如 `v1.0.0`
30+
31+
**功能:**
32+
- 📦 运行完整测试
33+
- 📦 构建生产包
34+
- 📦 发布到 NPM(支持私有仓库)
35+
- 📝 自动创建 GitHub Release
36+
37+
**需要配置的 Secrets:**
38+
39+
| Secret 名称 | 是否必需 | 说明 | 示例值 |
40+
|------------|---------|------|--------|
41+
| `NPM_TOKEN` | ✅ 必需 | NPM 认证 Token | `npm_xxxxxxxxxxxx` |
42+
| `NPM_REGISTRY_URL` | ⚠️ 可选 | NPM 仓库地址(默认:`https://registry.npmjs.org/`| `https://npm.company.com/` |
43+
| `NPM_REGISTRY_HOST` | ⚠️ 可选 | NPM 仓库主机(默认:`registry.npmjs.org`| `npm.company.com` |
44+
45+
**使用示例:**
46+
```bash
47+
# 发布新版本
48+
git tag v1.0.0
49+
git push origin v1.0.0
50+
```
51+
52+
---
53+
54+
### 3. 文档自动部署 (`.github/workflows/deploy-docs.yml`)
55+
56+
**触发条件:**
57+
- `main` 分支的 push
58+
- 手动触发(workflow_dispatch)
59+
60+
**功能:**
61+
- 📚 构建 VitePress 文档
62+
- 🚀 部署到 GitHub Pages
63+
64+
**需要配置:**
65+
1. 在仓库设置中启用 GitHub Pages
66+
2. 设置 Pages 源为 "GitHub Actions"
67+
68+
**无需配置 Secrets**(使用自动生成的 `GITHUB_TOKEN`
69+
70+
---
71+
72+
### 4. 自动化发布流程 (`.github/workflows/release-drafter.yml`)
73+
74+
**触发条件:**
75+
- `main` 分支的 push
76+
- Pull Request 的打开、重新打开或同步
77+
78+
**功能:**
79+
- 📋 自动生成 Release Notes
80+
- 🏷️ 根据 PR 标签自动分类变更
81+
- 🔖 自动计算语义化版本号
82+
83+
**配置文件:** `.github/release-drafter.yml`
84+
85+
**支持的 PR 标签:**
86+
- `feature`, `enhancement` → 🚀 Features
87+
- `fix`, `bugfix`, `bug` → 🐛 Bug Fixes
88+
- `chore`, `dependencies` → 🧰 Maintenance
89+
- `documentation`, `docs` → 📚 Documentation
90+
- `style` → 🎨 Styling
91+
- `performance` → ⚡ Performance
92+
- `security` → 🔒 Security
93+
94+
**版本号规则:**
95+
- `major`, `breaking` 标签 → 主版本号 +1
96+
- `minor`, `feature` 标签 → 次版本号 +1
97+
- `patch`, `fix`, `bugfix` 标签 → 修订号 +1
98+
99+
**无需配置 Secrets**(使用自动生成的 `GITHUB_TOKEN`
100+
101+
---
102+
103+
## 🔧 配置步骤
104+
105+
### 1. 配置 NPM 发布(支持私有仓库)
106+
107+
#### 公共 NPM 仓库
108+
在仓库的 **Settings → Secrets and variables → Actions** 中添加:
109+
110+
```
111+
NPM_TOKEN = npm_xxxxxxxxxxxxxxxxxxxx
112+
```
113+
114+
获取 NPM Token:
115+
```bash
116+
npm login
117+
npm token create
118+
```
119+
120+
#### 私有 NPM 仓库
121+
除了 `NPM_TOKEN`,还需添加:
122+
123+
```
124+
NPM_REGISTRY_URL = https://npm.company.com/
125+
NPM_REGISTRY_HOST = npm.company.com
126+
```
127+
128+
### 2. 配置 GitHub Pages
129+
130+
1. 进入仓库 **Settings → Pages**
131+
2. Source 选择 **GitHub Actions**
132+
3. 保存后,推送到 `main` 分支即可自动部署
133+
134+
### 3. 使用 Release Drafter
135+
136+
1. 创建 PR 时添加合适的标签(如 `feature``fix`
137+
2. 合并 PR 后,Release Draft 会自动更新
138+
3. 在 Releases 页面编辑 Draft 并发布
139+
4. 或者直接推送 tag 触发自动发布
140+
141+
---
142+
143+
## 🚀 发布流程示例
144+
145+
### 完整发布流程
146+
147+
```bash
148+
# 1. 开发完成后,创建 PR 并添加标签(如 feature)
149+
git checkout -b feat/new-feature
150+
# ... 开发 ...
151+
git push origin feat/new-feature
152+
# 在 GitHub 创建 PR,添加 "feature" 标签
153+
154+
# 2. PR 合并到 main 后,Release Drafter 自动更新草稿
155+
156+
# 3. 本地拉取最新代码
157+
git checkout main
158+
git pull origin main
159+
160+
# 4. 创建并推送 tag
161+
git tag v1.0.0
162+
git push origin v1.0.0
163+
164+
# 5. 自动触发:
165+
# - NPM 发布
166+
# - GitHub Release 创建
167+
# - 文档部署
168+
```
169+
170+
---
171+
172+
## 📝 注意事项
173+
174+
1. **首次使用前**,确保所有必需的 Secrets 已配置
175+
2. **私有 NPM 仓库**需要同时配置 `NPM_REGISTRY_URL``NPM_REGISTRY_HOST`
176+
3. **GitHub Pages** 需要在仓库设置中手动启用
177+
4. **标签格式**必须为 `v*`(如 `v1.0.0``v2.1.0-beta.1`
178+
5. **PR 标签**影响版本号计算和 Release Notes 分类
179+
180+
---
181+
182+
## 🔍 故障排查
183+
184+
### NPM 发布失败
185+
- 检查 `NPM_TOKEN` 是否有效
186+
- 确认私有仓库地址配置正确
187+
- 查看 Actions 日志中的详细错误信息
188+
189+
### 文档部署失败
190+
- 确认 GitHub Pages 已启用
191+
- 检查 VitePress 构建是否成功
192+
- 查看 `docs:build` 命令是否正常
193+
194+
### Release Drafter 未更新
195+
- 确认 PR 已合并到 `main` 分支
196+
- 检查工作流权限是否正确
197+
198+
---
199+
200+
## 📚 相关链接
201+
202+
- [GitHub Actions 文档](https://docs.github.com/en/actions)
203+
- [Release Drafter](https://github.com/release-drafter/release-drafter)
204+
- [NPM Publishing](https://docs.npmjs.com/packages-and-modules/contributing-packages-to-the-registry)
205+
- [GitHub Pages](https://docs.github.com/en/pages)

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [18.x, 20.x]
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
cache: 'npm'
26+
27+
- name: Install dependencies
28+
run: npm ci
29+
30+
- name: Type check
31+
run: npm run type-check
32+
33+
- name: Format check
34+
run: npx prettier --check src/
35+
36+
- name: Lint check
37+
run: npx eslint src/
38+
39+
- name: Run tests
40+
run: npm run test -- --run
41+
42+
- name: Build
43+
run: npm run build
44+
45+
- name: Upload build artifacts
46+
if: matrix.node-version == '20.x'
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: dist
50+
path: dist/
51+
retention-days: 7

.github/workflows/deploy-docs.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Deploy Docs
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: pages
15+
cancel-in-progress: false
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Setup Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '20.x'
31+
cache: 'npm'
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- name: Build VitePress docs
37+
run: npm run docs:build
38+
env:
39+
NODE_OPTIONS: --max_old_space_size=4096
40+
41+
- name: Upload artifact
42+
uses: actions/upload-pages-artifact@v3
43+
with:
44+
path: docs/.vitepress/dist
45+
46+
deploy:
47+
environment:
48+
name: github-pages
49+
url: ${{ steps.deployment.outputs.page_url }}
50+
needs: build
51+
runs-on: ubuntu-latest
52+
53+
steps:
54+
- name: Deploy to GitHub Pages
55+
id: deployment
56+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)