File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Publish Package
2+
3+ on :
4+ workflow_dispatch :
5+ push :
6+ tags :
7+ - " v*"
8+
9+ permissions :
10+ contents : read
11+ id-token : write
12+
13+ jobs :
14+ publish :
15+ if : github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
16+ runs-on : ubuntu-latest
17+
18+ steps :
19+ - name : Checkout
20+ uses : actions/checkout@v4
21+
22+ - name : Setup Node.js
23+ uses : actions/setup-node@v4
24+ with :
25+ node-version : " 24"
26+ registry-url : " https://registry.npmjs.org"
27+
28+ - name : Install dependencies
29+ run : npm ci
30+
31+ - name : Run tests
32+ run : npm test --silent
33+
34+ - name : Check publish tarball
35+ run : npm pack --dry-run
36+
37+ - name : Publish to npm
38+ run : npm publish --access public
Original file line number Diff line number Diff line change @@ -107,13 +107,36 @@ PR 标题建议:
107107
108108## Release Flow
109109
110- 发布前建议按顺序执行:
110+ 默认推荐用 GitHub Actions 发布,而不是本地发布。
111+
112+ ### GitHub Actions Release
113+
114+ 1 . 确保默认分支已经包含:
115+ - ` .github/workflows/publish.yml `
116+ 2 . 在 npm 包设置中配置 Trusted Publisher:
117+ - GitHub user/org: ` joyang1 `
118+ - repository: ` codex-viewer `
119+ - workflow filename: ` publish.yml `
120+ 3 . 在 ` main ` 上创建并推送版本 tag:
121+
122+ ``` bash
123+ git checkout main
124+ git pull
125+ git tag v0.4.0
126+ git push origin main --tags
127+ ```
128+
129+ 4 . 等待 GitHub Actions 完成发布
130+
131+ ### Local Fallback Release
132+
133+ 如果必须本地发布,再执行:
111134
112135``` bash
113136npm whoami
114137npm test
115138npm run pack:check
116- npm publish --access public
139+ npm publish --access public --otp= < 6-digit-code >
117140```
118141
119- 如果账号启用了 2FA,发布时需要补 ` --otp=<code> ` 。
142+ 如果账号启用了 2FA,本地发布必须补 ` --otp=<code> ` 。
Original file line number Diff line number Diff line change @@ -180,13 +180,54 @@ npm run pack:check
180180
181181## 发布到 npm
182182
183- 项目已经准备成可直接发布的 npm CLI 包。正式发布前,建议按下面顺序执行:
183+ 项目已经准备成可直接发布的 npm CLI 包。推荐使用 GitHub Actions + npm Trusted Publishing 来发布,而不是在本地执行 ` npm publish ` 。
184+
185+ ### 推荐发布方式:GitHub Actions
186+
187+ 仓库已包含工作流:
188+
189+ - [ ` publish.yml ` ] ( ./.github/workflows/publish.yml )
190+
191+ 工作流会在以下场景触发:
192+
193+ - 手动触发 ` workflow_dispatch `
194+ - 推送 ` v* ` tag,例如 ` v0.4.0 `
195+
196+ 发布前需要先在 npm 包设置里配置 Trusted Publisher:
197+
198+ 1 . 打开 npm 上的包设置页面
199+ 2 . 进入 ` Trusted Publisher `
200+ 3 . 选择 ` GitHub Actions `
201+ 4 . 填入:
202+ - GitHub user/org: ` joyang1 `
203+ - repository: ` codex-viewer `
204+ - workflow filename: ` publish.yml `
205+
206+ 之后推荐这样发布:
207+
208+ ``` bash
209+ git checkout main
210+ git pull
211+ git tag v0.4.0
212+ git push origin main --tags
213+ ```
214+
215+ 工作流会自动执行:
216+
217+ - ` npm ci `
218+ - ` npm test --silent `
219+ - ` npm pack --dry-run `
220+ - ` npm publish --access public `
221+
222+ ### 本地发布方式
223+
224+ 如果你临时仍要从本地发布,建议按下面顺序执行:
184225
185226``` bash
186227npm login
187228npm whoami
188229npm run pack:check
189- npm publish --access public
230+ npm publish --access public --otp= < 6-digit-code >
190231```
191232
192233当前仓库默认使用作用域包名:
You can’t perform that action at this time.
0 commit comments