Skip to content

Commit 6c09869

Browse files
committed
chore: 🤖 增加action发布脚本
1 parent 48ec59e commit 6c09869

6 files changed

Lines changed: 491 additions & 0 deletions

File tree

.github/README.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# GitHub Actions 工作流说明
2+
3+
本项目包含完整的 CI/CD 工作流,支持自动化测试、发布和文档部署。
4+
5+
## 🚀 工作流概览
6+
7+
### 1. CI 工作流 (`ci.yml`)
8+
- **触发条件**: 推送到主分支或创建 PR
9+
- **功能**:
10+
- 多 Node.js 版本测试 (16, 18, 20)
11+
- 代码格式检查
12+
- 类型检查
13+
- 单元测试
14+
- 构建验证
15+
- 包检查
16+
- 测试覆盖率报告
17+
18+
### 2. 发布工作流 (`release.yml`)
19+
- **触发条件**:
20+
- 推送版本标签 (如 `v1.0.0`)
21+
- 手动触发 (可指定版本号)
22+
- **功能**:
23+
- 完整的 CI 检查
24+
- 自动生成变更日志
25+
- 发布到 npm
26+
- 创建 GitHub Release
27+
28+
### 3. 文档部署工作流 (`docs.yml`)
29+
- **触发条件**:
30+
- 推送到主分支 (文档相关文件变更)
31+
- 新版本发布
32+
- 手动触发
33+
- **功能**:
34+
- 构建 rspress 文档
35+
- 部署到 GitHub Pages
36+
37+
### 4. 依赖更新 (`dependabot.yml`)
38+
- **功能**: 自动检查并更新依赖
39+
- **频率**: 每周一上午 9 点
40+
- **范围**: npm 依赖和 GitHub Actions
41+
42+
## 📋 使用前准备
43+
44+
### 1. 设置 Secrets
45+
在 GitHub 仓库设置中添加以下 Secrets:
46+
47+
```
48+
NPM_TOKEN # npm 发布令牌
49+
CODECOV_TOKEN # Codecov 令牌 (可选)
50+
```
51+
52+
### 2. 启用 GitHub Pages
53+
1. 进入仓库 Settings → Pages
54+
2. Source 选择 "GitHub Actions"
55+
3. 保存设置
56+
57+
### 3. 配置分支保护 (推荐)
58+
为主分支设置保护规则:
59+
- 要求 PR 审查
60+
- 要求状态检查通过
61+
- 要求分支为最新
62+
63+
## 🎯 发布流程
64+
65+
### 方式一:标签发布 (推荐)
66+
```bash
67+
# 1. 更新版本号
68+
npm version patch # 或 minor, major
69+
70+
# 2. 推送标签
71+
git push origin --tags
72+
73+
# 3. 工作流自动执行发布
74+
```
75+
76+
### 方式二:手动发布
77+
1. 进入 GitHub Actions 页面
78+
2. 选择 "Release" 工作流
79+
3. 点击 "Run workflow"
80+
4. 输入版本号 (如 `1.0.1`)
81+
5. 点击运行
82+
83+
## 📚 文档部署
84+
85+
文档会在以下情况自动部署:
86+
- 推送到主分支且包含文档相关文件变更
87+
- 发布新版本
88+
- 手动触发部署
89+
90+
访问地址:`https://winjs-dev.github.io/cloud-utils/`
91+
92+
## 🔧 本地开发
93+
94+
```bash
95+
# 安装依赖
96+
pnpm install
97+
98+
# 开发模式
99+
pnpm dev
100+
101+
# 运行测试
102+
pnpm test
103+
104+
# 构建项目
105+
pnpm build
106+
107+
# 本地预览文档
108+
pnpm docs:dev
109+
```
110+
111+
## 📊 状态徽章
112+
113+
可以在项目 README 中添加以下徽章:
114+
115+
```markdown
116+
![CI](https://github.com/winjs-dev/cloud-utils/workflows/CI/badge.svg)
117+
![Release](https://github.com/winjs-dev/cloud-utils/workflows/Release/badge.svg)
118+
![Deploy Docs](https://github.com/winjs-dev/cloud-utils/workflows/Deploy%20Docs/badge.svg)
119+
```
120+
121+
## 🐛 故障排除
122+
123+
### 发布失败
124+
1. 检查 `NPM_TOKEN` 是否正确设置
125+
2. 确认包名在 npm 上可用
126+
3. 检查版本号是否符合语义化版本规范
127+
128+
### 文档部署失败
129+
1. 确认 GitHub Pages 已启用
130+
2. 检查 `rspress.config.ts` 配置
131+
3. 确认构建产物路径正确
132+
133+
### CI 测试失败
134+
1. 本地运行测试确认问题
135+
2. 检查 Node.js 版本兼容性
136+
3. 确认依赖安装正常
137+
138+
## 📝 自定义配置
139+
140+
可以根据项目需求调整工作流:
141+
142+
- 修改 Node.js 版本矩阵
143+
- 调整触发条件
144+
- 添加额外的检查步骤
145+
- 自定义部署目标

.github/dependabot.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: 2
2+
updates:
3+
# npm 依赖更新
4+
- package-ecosystem: "npm"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
day: "monday"
9+
time: "09:00"
10+
open-pull-requests-limit: 10
11+
reviewers:
12+
- "winjs-dev"
13+
assignees:
14+
- "winjs-dev"
15+
commit-message:
16+
prefix: "chore"
17+
include: "scope"
18+
19+
# GitHub Actions 更新
20+
- package-ecosystem: "github-actions"
21+
directory: "/"
22+
schedule:
23+
interval: "weekly"
24+
day: "monday"
25+
time: "09:00"
26+
open-pull-requests-limit: 5
27+
reviewers:
28+
- "winjs-dev"
29+
assignees:
30+
- "winjs-dev"
31+
commit-message:
32+
prefix: "ci"
33+
include: "scope"

.github/workflows/ci.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
- develop
9+
pull_request:
10+
branches:
11+
- main
12+
- master
13+
- develop
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
node-version: [16, 18, 20]
21+
22+
steps:
23+
- name: 检出代码
24+
uses: actions/checkout@v4
25+
26+
- name: 设置 Node.js ${{ matrix.node-version }}
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: ${{ matrix.node-version }}
30+
31+
- name: 安装 pnpm
32+
uses: pnpm/action-setup@v4
33+
with:
34+
version: 8
35+
36+
- name: 获取 pnpm store 目录
37+
shell: bash
38+
run: |
39+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
40+
41+
- name: 设置 pnpm 缓存
42+
uses: actions/cache@v4
43+
with:
44+
path: ${{ env.STORE_PATH }}
45+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
46+
restore-keys: |
47+
${{ runner.os }}-pnpm-store-
48+
49+
- name: 安装依赖
50+
run: pnpm install --frozen-lockfile
51+
52+
- name: 代码格式检查
53+
run: pnpm run format:check
54+
55+
- name: 类型检查
56+
run: pnpm run type-check
57+
58+
- name: 运行测试
59+
run: pnpm run test
60+
61+
- name: 构建项目
62+
run: pnpm run build
63+
64+
- name: 包检查
65+
run: pnpm run lint:package
66+
67+
coverage:
68+
runs-on: ubuntu-latest
69+
needs: test
70+
71+
steps:
72+
- name: 检出代码
73+
uses: actions/checkout@v4
74+
75+
- name: 设置 Node.js
76+
uses: actions/setup-node@v4
77+
with:
78+
node-version: '18'
79+
80+
- name: 安装 pnpm
81+
uses: pnpm/action-setup@v4
82+
with:
83+
version: 8
84+
85+
- name: 安装依赖
86+
run: pnpm install --frozen-lockfile
87+
88+
- name: 运行测试覆盖率
89+
run: pnpm run test:coverage
90+
91+
- name: 上传覆盖率报告
92+
uses: codecov/codecov-action@v4
93+
with:
94+
token: ${{ secrets.CODECOV_TOKEN }}
95+
files: ./coverage/lcov.info
96+
fail_ci_if_error: false

.github/workflows/docs.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Deploy Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
paths:
9+
- 'docs/**'
10+
- 'src/**'
11+
- 'rspress.config.ts'
12+
- 'package.json'
13+
workflow_dispatch:
14+
# 当有新的 release 时也触发文档部署
15+
release:
16+
types: [published]
17+
18+
jobs:
19+
deploy-docs:
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
pages: write
24+
id-token: write
25+
26+
# 确保同一时间只有一个部署在运行
27+
concurrency:
28+
group: "pages"
29+
cancel-in-progress: false
30+
31+
steps:
32+
- name: 检出代码
33+
uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
37+
- name: 设置 Node.js
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: '18'
41+
42+
- name: 安装 pnpm
43+
uses: pnpm/action-setup@v4
44+
with:
45+
version: 8
46+
47+
- name: 获取 pnpm store 目录
48+
shell: bash
49+
run: |
50+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
51+
52+
- name: 设置 pnpm 缓存
53+
uses: actions/cache@v4
54+
with:
55+
path: ${{ env.STORE_PATH }}
56+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
57+
restore-keys: |
58+
${{ runner.os }}-pnpm-store-
59+
60+
- name: 安装依赖
61+
run: pnpm install --frozen-lockfile
62+
63+
- name: 构建项目 (生成类型定义)
64+
run: pnpm run build
65+
66+
- name: 构建文档
67+
run: pnpm run docs:build
68+
env:
69+
NODE_ENV: production
70+
71+
- name: 设置 Pages
72+
uses: actions/configure-pages@v4
73+
74+
- name: 上传文档构建产物
75+
uses: actions/upload-pages-artifact@v3
76+
with:
77+
path: ./doc_build
78+
79+
- name: 部署到 GitHub Pages
80+
id: deployment
81+
uses: actions/deploy-pages@v4
82+
83+
- name: 通知部署成功
84+
run: |
85+
echo "📚 文档部署成功!"
86+
echo "🌐 访问地址: https://winjs-dev.github.io/cloud-utils/"
87+
echo "📝 部署 ID: ${{ steps.deployment.outputs.page_url }}"

0 commit comments

Comments
 (0)