ops-toolkit 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.release-it.json CHANGED
@@ -19,7 +19,6 @@
19
19
  "hooks": {
20
20
  "before:init": ["bun run lint", "bun run typecheck"],
21
21
  "after:bump": ["bun run build"],
22
- "before:release": "npm config set //registry.npmjs.org/:_authToken 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",
23
22
  "after:release": ["git push origin HEAD"]
24
23
  },
25
24
  "plugins": {
package/AGENTS.md CHANGED
@@ -202,16 +202,17 @@ try {
202
202
 
203
203
  ## Quick Reference
204
204
 
205
- | Task | Command |
206
- | ---------------- | ----------------------- |
207
- | Start dev server | `bun run dev` |
208
- | Build project | `bun run build` |
209
- | Run tests | `bun test` |
210
- | Type check | `bun run typecheck` |
211
- | Lint and fix | `bun run lint:fix` |
212
- | Format code | `bun run format` |
213
- | Publish to npm | `bun run publish:patch` |
214
- | Debug | F5 in VS Code |
205
+ | Task | Command |
206
+ | ---------------- | ------------------------ |
207
+ | Start dev server | `bun run dev` |
208
+ | Build project | `bun run build` |
209
+ | Run tests | `bun test` |
210
+ | Type check | `bun run typecheck` |
211
+ | Lint and fix | `bun run lint:fix` |
212
+ | Format code | `bun run format` |
213
+ | Publish to npm | `bun run publish:patch` |
214
+ | Publish docs | See `docs/PUBLISHING.md` |
215
+ | Debug | F5 in VS Code |
215
216
 
216
217
  ## OpenCode Custom Commands
217
218
 
package/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
 
2
2
 
3
- ## [1.2.2](https://github.com/liangshaojie/ops-toolkit/compare/v1.2.1...v1.2.2) (2026-01-11)
3
+ ## [1.2.3](https://github.com/liangshaojie/ops-toolkit/compare/v1.2.1...v1.2.3) (2026-01-11)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * 更新版本号 ([7e32b53](https://github.com/liangshaojie/ops-toolkit/commit/7e32b53027845b2768706944b4f1f483cf215c13))
4
9
 
5
10
 
6
11
  ### Features
@@ -0,0 +1,321 @@
1
+ # ops-toolkit 发布指南
2
+
3
+ ## 概述
4
+
5
+ 本文档说明如何将 ops-toolkit 发布到 npm registry。
6
+
7
+ ## 重要变更(2025年12月)
8
+
9
+ npm 已永久撤销 classic tokens,现在使用以下认证方式:
10
+
11
+ - **Granular Access Tokens**:最多90天有效期,需要2FA
12
+ - **Session Tokens**:2小时有效期,通过 `npm login` 获取
13
+ - **OIDC Trusted Publishing**:推荐用于CI/CD,无需管理token
14
+
15
+ ## 发布流程
16
+
17
+ ### 1. 准备工作
18
+
19
+ 确保代码已提交并通过检查:
20
+
21
+ ```bash
22
+ # 检查工作目录是否干净
23
+ git status
24
+
25
+ # 运行代码检查
26
+ bun run lint
27
+ bun run typecheck
28
+
29
+ # 构建项目
30
+ bun run build
31
+ ```
32
+
33
+ ### 2. 登录 npm(可选)
34
+
35
+ 如果使用 session token(2小时有效期):
36
+
37
+ ```bash
38
+ npm login
39
+ ```
40
+
41
+ 这会创建一个2小时的 session token,期间可以发布无需 OTP。
42
+
43
+ ### 3. 发布到 npm
44
+
45
+ 使用以下命令发布不同版本:
46
+
47
+ ```bash
48
+ # Patch 版本(bug fixes):1.2.1 → 1.2.2
49
+ bun run publish:patch
50
+
51
+ # Minor 版本(新功能):1.2.1 → 1.3.0
52
+ bun run publish:minor
53
+
54
+ # Major 版本(破坏性变更):1.2.1 → 2.0.0
55
+ bun run publish:major
56
+ ```
57
+
58
+ ## 自动化发布流程
59
+
60
+ `publish:*` 命令自动执行以下步骤:
61
+
62
+ 1. **质量检查**
63
+ - 运行 ESLint
64
+ - 运行 TypeScript 类型检查
65
+
66
+ 2. **版本升级**
67
+ - 升级 package.json 中的版本号
68
+ - 创建 git tag(如 v1.2.2)
69
+ - 生成 changelog
70
+
71
+ 3. **构建**
72
+ - 编译 TypeScript 代码
73
+ - 生成 dist/ 目录
74
+ - 设置可执行权限
75
+
76
+ 4. **发布**
77
+ - 发布到 npm registry
78
+ - 创建 GitHub release(需要 GITHUB_TOKEN)
79
+
80
+ 5. **推送**
81
+ - 推送 git commits 和 tags 到远程仓库
82
+
83
+ ## 版本选择指南
84
+
85
+ ### Patch 版本
86
+
87
+ ```bash
88
+ bun run publish:patch
89
+ ```
90
+
91
+ 使用场景:
92
+
93
+ - Bug 修复
94
+ - 小改进
95
+ - 非破坏性更改
96
+ - 文档更新
97
+
98
+ ### Minor 版本
99
+
100
+ ```bash
101
+ bun run publish:minor
102
+ ```
103
+
104
+ 使用场景:
105
+
106
+ - 新功能
107
+ - 向后兼容的更改
108
+ - 添加功能
109
+
110
+ ### Major 版本
111
+
112
+ ```bash
113
+ bun run publish:major
114
+ ```
115
+
116
+ 使用场景:
117
+
118
+ - 破坏性更改
119
+ - API 更改
120
+ - 移除功能
121
+
122
+ ## 配置说明
123
+
124
+ ### .npmrc 项目配置
125
+
126
+ 项目根目录包含 `.npmrc` 文件,配置:
127
+
128
+ - registry 地址
129
+ - 公开访问权限
130
+
131
+ **重要**:认证 tokens 不应提交到 `.npmrc`,应通过以下方式设置:
132
+
133
+ 1. 全局 `~/.npmrc`(推荐用于开发)
134
+ 2. 环境变量 `NPM_TOKEN`(推荐用于 CI/CD)
135
+ 3. 通过 `npm login` 创建 session token
136
+
137
+ ### .release-it.json 配置
138
+
139
+ 发布自动化配置包含:
140
+
141
+ - Git 操作(commit, tag, push)
142
+ - GitHub releases
143
+ - npm 发布设置
144
+ - 预发布和后发布 hooks
145
+
146
+ ## 故障排除
147
+
148
+ ### 错误:403 Forbidden
149
+
150
+ **原因**:版本已存在或权限问题
151
+
152
+ **解决方案**:
153
+
154
+ - 检查版本是否已发布:`npm view ops-toolkit versions`
155
+ - 确保有发布权限
156
+ - 检查 token 是否有效
157
+
158
+ ### 错误:EOTP / 需要一次性密码
159
+
160
+ **原因**:启用了 2FA
161
+
162
+ **解决方案**:
163
+
164
+ ```bash
165
+ # 方法1:使用 npm login 创建 session token(推荐)
166
+ npm login
167
+ bun run publish:patch
168
+
169
+ # 方法2:手动提供 OTP
170
+ NPM_OTP=123456 bun run publish:patch
171
+ ```
172
+
173
+ ### 错误:Access token expired or revoked
174
+
175
+ **原因**:token 已过期或被撤销
176
+
177
+ **解决方案**:
178
+
179
+ 1. 创建新的 granular token:https://www.npmjs.com/settings/~/tokens
180
+ 2. 选择 "Granular Access Token"
181
+ 3. 勾选 "Publish" 权限
182
+ 4. 勾选 "Bypass 2FA"(用于自动化)
183
+ 5. 设置过期时间(最长90天)
184
+ 6. 更新 token 配置
185
+
186
+ ### 错误:Git push 被阻止(包含密钥)
187
+
188
+ **原因**:GitHub 检测到 commit 中的敏感信息
189
+
190
+ **解决方案**:
191
+
192
+ ```bash
193
+ # 1. 回退到包含密钥之前的 commit
194
+ git log --oneline
195
+ git reset --hard <commit-hash>
196
+
197
+ # 2. 清理历史(如有必要)
198
+ # 注意:这会重写历史,谨慎使用
199
+ git filter-branch --force --tree-filter 'sed -i "" "s/<TOKEN>//g" .release-it.json'
200
+
201
+ # 3. 强制推送
202
+ git push origin master --force
203
+ ```
204
+
205
+ ### 错误:Working dir must be clean
206
+
207
+ **原因**:有未提交的更改
208
+
209
+ **解决方案**:
210
+
211
+ ```bash
212
+ git add .
213
+ git commit -m "your commit message"
214
+ ```
215
+
216
+ ## 手动发布
217
+
218
+ 如果自动化脚本失败,可以手动发布:
219
+
220
+ ```bash
221
+ # 1. 构建项目
222
+ bun run build
223
+
224
+ # 2. 升级版本
225
+ npm version patch # 或 minor, major
226
+
227
+ # 3. 发布
228
+ npm publish --access public
229
+
230
+ # 4. 推送 git tags
231
+ git push origin master --tags
232
+ ```
233
+
234
+ ## 环境变量
235
+
236
+ ### NPM_TOKEN
237
+
238
+ 用于 CI/CD 环境的 granular token:
239
+
240
+ ```bash
241
+ export NPM_TOKEN=npm_xxxxxxxxxxxxxxxxx
242
+ ```
243
+
244
+ ### NPM_OTP
245
+
246
+ 用于提供一次性密码:
247
+
248
+ ```bash
249
+ export NPM_OTP=123456
250
+ ```
251
+
252
+ ### GITHUB_TOKEN
253
+
254
+ 用于自动创建 GitHub releases:
255
+
256
+ ```bash
257
+ export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxx
258
+ ```
259
+
260
+ 获取方式:
261
+
262
+ - 访问 https://github.com/settings/tokens
263
+ - 生成新的 personal access token
264
+ - 勾选 `repo` 权限
265
+
266
+ ## CI/CD 集成
267
+
268
+ ### GitHub Actions 示例
269
+
270
+ ```yaml
271
+ name: Release
272
+
273
+ on:
274
+ push:
275
+ tags:
276
+ - 'v*'
277
+
278
+ jobs:
279
+ publish:
280
+ runs-on: ubuntu-latest
281
+ steps:
282
+ - uses: actions/checkout@v3
283
+
284
+ - uses: actions/setup-node@v3
285
+ with:
286
+ node-version: '18'
287
+ registry-url: 'https://registry.npmjs.org'
288
+
289
+ - run: npm ci
290
+
291
+ - name: Publish to npm
292
+ run: npm publish --access public
293
+ env:
294
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
295
+ ```
296
+
297
+ ## 安全最佳实践
298
+
299
+ 1. **永远不要**将 tokens 提交到 git
300
+ 2. 使用 `.gitignore` 排除 `.npmrc`(如果包含 tokens)
301
+ 3. 定期轮换 tokens(granular tokens 最多90天)
302
+ 4. 使用最小权限原则
303
+ 5. 考虑使用 OIDC trusted publishing(推荐用于 CI/CD)
304
+
305
+ ## 相关链接
306
+
307
+ - npm 发布文档:https://docs.npmjs.com/cli/v9/commands/npm-publish
308
+ - Granular tokens:https://docs.npmjs.com/creating-and-viewing-access-tokens
309
+ - OIDC trusted publishing:https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow
310
+ - release-it 文档:https://github.com/release-it/release-it
311
+
312
+ ## 快速参考
313
+
314
+ | 命令 | 用途 |
315
+ | ------------------------------- | ------------------ |
316
+ | `bun run publish:patch` | 发布 patch 版本 |
317
+ | `bun run publish:minor` | 发布 minor 版本 |
318
+ | `bun run publish:major` | 发布 major 版本 |
319
+ | `npm login` | 创建 session token |
320
+ | `npm view ops-toolkit versions` | 查看已发布版本 |
321
+ | `npm pack --dry-run` | 预览将要发布的内容 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ops-toolkit",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "A comprehensive DevOps CLI toolkit with terminal UI",
5
5
  "main": "dist/index.js",
6
6
  "bin": {