Skip to content

Commit 2233c86

Browse files
committed
ci(release): add release ci
1 parent 13362b1 commit 2233c86

File tree

5 files changed

+214
-2
lines changed

5 files changed

+214
-2
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [main, next]
8+
branches: [main, develop, next]
99
pull_request:
10-
branches: [main, next]
10+
branches: [main, develop, next]
1111

1212
jobs:
1313
check:

.github/workflows/npm-publish.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# This workflow will publish the package to npm when a release is created
2+
3+
name: Publish to npm
4+
5+
on:
6+
release:
7+
types: [published]
8+
workflow_dispatch:
9+
inputs:
10+
version_type:
11+
description: 'Version type'
12+
required: true
13+
default: 'patch'
14+
type: choice
15+
options:
16+
- patch
17+
- minor
18+
- major
19+
20+
jobs:
21+
publish:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
# 确保获取完整的 git 历史,用于版本管理
29+
fetch-depth: 0
30+
31+
- name: Install pnpm
32+
uses: pnpm/action-setup@v4.0.0
33+
with:
34+
version: 9.7.0
35+
36+
- name: Setup Node.js
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: '20.x'
40+
cache: 'pnpm'
41+
registry-url: 'https://registry.npmjs.org'
42+
43+
- name: Install dependencies
44+
run: pnpm install --frozen-lockfile
45+
46+
- name: Run type check
47+
run: pnpm check-types
48+
49+
- name: Run tests
50+
run: pnpm test
51+
52+
- name: Build package
53+
run: pnpm build
54+
55+
- name: Update version (if manual dispatch)
56+
if: github.event_name == 'workflow_dispatch'
57+
run: |
58+
git config user.name github-actions
59+
git config user.email github-actions@github.com
60+
npm version ${{ github.event.inputs.version_type }} --no-git-tag-version
61+
git add package.json
62+
git commit -m "chore: bump version to $(node -p "require('./package.json').version")"
63+
git push
64+
65+
- name: Publish to npm
66+
run: pnpm publish --access public --no-git-checks
67+
env:
68+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
69+
70+
- name: Create Git tag (if manual dispatch)
71+
if: github.event_name == 'workflow_dispatch'
72+
run: |
73+
VERSION=$(node -p "require('./package.json').version")
74+
git tag "v$VERSION"
75+
git push origin "v$VERSION"

.npmignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 源码和开发文件
2+
src/
3+
test/
4+
benchmark/
5+
scripts/
6+
docs/
7+
.github/
8+
9+
# 配置文件
10+
.gitignore
11+
.prettierrc*
12+
.eslintrc*
13+
commitlint.config.js
14+
jest.config.js
15+
tsconfig.json
16+
antlr.format.json
17+
pnpm-lock.yaml
18+
19+
# 文档(保留主要文档)
20+
CONTRIBUTING.md
21+
PUBLISH.md
22+
CHANGELOG.md
23+
24+
# 开发相关
25+
node_modules/
26+
.husky/
27+
benchmark_reports/
28+
29+
# 临时文件
30+
*.log
31+
*.tmp
32+
.DS_Store
33+
Thumbs.db

PUBLISH.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# 发布到 npm 指南
2+
3+
本文档说明如何将 `iotdb-sql-parser` 发布到 npm。
4+
5+
## 前置准备
6+
7+
### 1. npm 账户设置
8+
确保您有 npm 账户,并且有权限发布包:
9+
```bash
10+
npm login
11+
npm whoami
12+
```
13+
14+
### 2. GitHub Secrets 配置
15+
在 GitHub 仓库设置中添加以下 Secrets:
16+
- `NPM_TOKEN`: 您的 npm 访问令牌
17+
18+
获取 npm token 的方法:
19+
1. 登录 npmjs.com
20+
2. 进入 Account Settings > Access Tokens
21+
3. 点击 "Generate New Token"
22+
4. 选择 "Automation" 类型
23+
5. 复制生成的 token 并添加到 GitHub Secrets
24+
25+
## 发布方式
26+
27+
### 方式 1: 通过 GitHub Release(推荐)
28+
1. 在 GitHub 上创建新的 Release
29+
2. 标签格式:`v1.0.0`(遵循语义化版本)
30+
3. 发布 Release 后,GitHub Actions 会自动触发 npm 发布
31+
32+
### 方式 2: 手动触发 GitHub Actions
33+
1. 进入 GitHub 仓库的 Actions 页面
34+
2. 选择 "Publish to npm" workflow
35+
3. 点击 "Run workflow"
36+
4. 选择版本类型(patch/minor/major)
37+
5. 点击运行
38+
39+
### 方式 3: 本地发布(不推荐)
40+
```bash
41+
# 确保代码是最新的
42+
git pull origin main
43+
44+
# 安装依赖
45+
pnpm install
46+
47+
# 运行测试
48+
pnpm test
49+
50+
# 构建项目
51+
pnpm build
52+
53+
# 发布版本(patch/minor/major)
54+
pnpm release:patch
55+
#
56+
pnpm release:minor
57+
#
58+
pnpm release:major
59+
```
60+
61+
## 版本管理
62+
63+
我们遵循 [语义化版本](https://semver.org/lang/zh-CN/) 规范:
64+
65+
- **MAJOR**: 当您做了不兼容的 API 修改
66+
- **MINOR**: 当您做了向下兼容的功能性新增
67+
- **PATCH**: 当您做了向下兼容的问题修正
68+
69+
## 发布流程
70+
71+
1. **开发阶段**: 在 `develop` 分支进行开发
72+
2. **测试**: 确保所有测试通过
73+
3. **合并**: 将 `develop` 分支合并到 `main` 分支
74+
4. **发布**: 在 `main` 分支创建 Release 或手动触发发布
75+
76+
## 检查发布结果
77+
78+
发布成功后,您可以:
79+
1.[npmjs.com](https://www.npmjs.com/package/iotdb-sql-parser) 查看包信息
80+
2. 使用 `npm install iotdb-sql-parser` 安装测试
81+
3. 检查 GitHub Actions 的执行日志
82+
83+
## 回滚发布
84+
85+
如果需要回滚发布的版本:
86+
```bash
87+
# 废弃某个版本
88+
npm deprecate iotdb-sql-parser@1.0.0 "This version has critical bugs"
89+
90+
# 撤销发布(仅限发布后24小时内)
91+
npm unpublish iotdb-sql-parser@1.0.0
92+
```
93+
94+
## 注意事项
95+
96+
1. 确保版本号唯一,npm 不允许发布相同版本号的包
97+
2. 发布前务必运行完整的测试套件
98+
3. 确保 `dist` 目录包含所有必要的构建文件
99+
4. 检查 `package.json` 中的 `files` 字段确保包含正确的文件
100+
5. 遵循 Apache 2.0 许可证要求

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
"check-types": "tsc -p ./tsconfig.json && tsc -p ./test/tsconfig.json",
2727
"test": "NODE_OPTIONS=--max_old_space_size=4096 && jest",
2828
"release": "node ./scripts/release.js",
29+
"release:patch": "npm version patch && npm run release:publish",
30+
"release:minor": "npm version minor && npm run release:publish",
31+
"release:major": "npm version major && npm run release:publish",
32+
"release:publish": "git push && git push --tags",
2933
"prettier-check": "prettier --check .",
3034
"format": "prettier --write .",
3135
"format-g4": "antlr-format -c ./antlr.format.json -v ./src/grammar/**/*.g4",

0 commit comments

Comments
 (0)