Skip to content

Commit 15270fe

Browse files
authored
ci switch npm scope to tommy94 (#3)
1 parent 4abf919 commit 15270fe

5 files changed

Lines changed: 61 additions & 21 deletions

File tree

.github/workflows/publish.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Publish Package
33
on:
44
workflow_dispatch:
55
push:
6+
branches:
7+
- "main"
68
tags:
79
- "v*"
810

@@ -12,7 +14,6 @@ permissions:
1214

1315
jobs:
1416
publish:
15-
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
1617
runs-on: ubuntu-latest
1718

1819
steps:
@@ -34,5 +35,34 @@ jobs:
3435
- name: Check publish tarball
3536
run: npm pack --dry-run
3637

38+
- name: Check npm publish target
39+
id: package
40+
shell: bash
41+
run: |
42+
PACKAGE_NAME=$(node -p "require('./package.json').name")
43+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
44+
PUBLISHED_VERSION=$(npm view "$PACKAGE_NAME" version 2>/dev/null || true)
45+
46+
echo "name=$PACKAGE_NAME" >> "$GITHUB_OUTPUT"
47+
echo "version=$PACKAGE_VERSION" >> "$GITHUB_OUTPUT"
48+
echo "published=$PUBLISHED_VERSION" >> "$GITHUB_OUTPUT"
49+
50+
if [ -n "$PUBLISHED_VERSION" ] && [ "$PACKAGE_VERSION" = "$PUBLISHED_VERSION" ]; then
51+
echo "publish=false" >> "$GITHUB_OUTPUT"
52+
echo "Package $PACKAGE_NAME@$PACKAGE_VERSION is already published. Skipping npm publish."
53+
else
54+
echo "publish=true" >> "$GITHUB_OUTPUT"
55+
echo "Package $PACKAGE_NAME@$PACKAGE_VERSION will be published."
56+
fi
57+
58+
- name: Publish summary
59+
shell: bash
60+
run: |
61+
echo "package: ${{ steps.package.outputs.name }}"
62+
echo "version: ${{ steps.package.outputs.version }}"
63+
echo "published version: ${{ steps.package.outputs.published }}"
64+
echo "publish now: ${{ steps.package.outputs.publish }}"
65+
3766
- name: Publish to npm
67+
if: steps.package.outputs.publish == 'true'
3868
run: npm publish --access public

CONTRIBUTING.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,22 @@ PR 标题建议:
113113

114114
1. 确保默认分支已经包含:
115115
- `.github/workflows/publish.yml`
116-
2. 在 npm 包设置中配置 Trusted Publisher:
116+
2. 在 npm `@tommy94/codex-viewer` 的设置中配置 Trusted Publisher:
117117
- GitHub user/org: `joyang1`
118118
- repository: `codex-viewer`
119119
- workflow filename: `publish.yml`
120-
3.`main` 上创建并推送版本 tag
120+
3.`main` 上提升版本并推送
121121

122122
```bash
123123
git checkout main
124124
git pull
125-
git tag v0.4.0
126-
git push origin main --tags
125+
npm version patch
126+
git push origin main --follow-tags
127127
```
128128

129-
4. 等待 GitHub Actions 完成发布
129+
4. GitHub Actions 会在推到 `main` 后自动运行
130+
5. 如果该版本尚未发布,会自动发布到 npm
131+
6. 如果该版本已经存在,会自动跳过发布
130132

131133
### Local Fallback Release
132134

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
### 全局安装
3939

4040
```bash
41-
npm install -g @joyang1/codex-viewer
41+
npm install -g @tommy94/codex-viewer
4242
```
4343

4444
安装完成后可直接运行:
@@ -50,7 +50,7 @@ codex-viewer --port 3789
5050
### 免安装快速运行
5151

5252
```bash
53-
npx @joyang1/codex-viewer --port 3789
53+
npx @tommy94/codex-viewer --port 3789
5454
```
5555

5656
## 前置条件
@@ -190,34 +190,42 @@ npm run pack:check
190190

191191
工作流会在以下场景触发:
192192

193+
- 推送到 `main`
193194
- 手动触发 `workflow_dispatch`
194195
- 推送 `v*` tag,例如 `v0.4.0`
195196

196197
发布前需要先在 npm 包设置里配置 Trusted Publisher:
197198

198199
1. 打开 npm 上的包设置页面
199-
2. 进入 `Trusted Publisher`
200-
3. 选择 `GitHub Actions`
201-
4. 填入:
200+
2. 打开包 `@tommy94/codex-viewer`
201+
3. 进入 `Trusted Publisher`
202+
4. 选择 `GitHub Actions`
203+
5. 填入:
202204
- GitHub user/org: `joyang1`
203205
- repository: `codex-viewer`
204206
- workflow filename: `publish.yml`
205207

206-
之后推荐这样发布
208+
配置完成后,推荐的发布方式是
207209

208210
```bash
209211
git checkout main
210212
git pull
211-
git tag v0.4.0
212-
git push origin main --tags
213+
npm version patch
214+
git push origin main --follow-tags
213215
```
214216

215-
工作流会自动执行:
217+
合并或推送到 `main` 后,工作流会自动执行:
216218

217219
- `npm ci`
218220
- `npm test --silent`
219221
- `npm pack --dry-run`
220-
- `npm publish --access public`
222+
- 检查当前版本是否已发布
223+
- 若该版本尚未发布,则自动执行 `npm publish --access public`
224+
225+
这意味着:
226+
227+
- 只要 `main` 上的 `package.json` 版本号是一个新版本,Actions 就会自动发布
228+
- 如果你只是提交普通代码、但版本号没变,工作流会自动跳过发布,不会重复报错
221229

222230
### 本地发布方式
223231

@@ -233,13 +241,13 @@ npm publish --access public --otp=<6-digit-code>
233241
当前仓库默认使用作用域包名:
234242

235243
```bash
236-
@joyang1/codex-viewer
244+
@tommy94/codex-viewer
237245
```
238246

239247
对应安装命令会变成:
240248

241249
```bash
242-
npm install -g @joyang1/codex-viewer
250+
npm install -g @tommy94/codex-viewer
243251
```
244252

245253
## 建议在发布前再补一项

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@joyang1/codex-viewer",
2+
"name": "@tommy94/codex-viewer",
33
"version": "0.4.0",
44
"description": "Web UI and realtime protocol inspector for Codex CLI with direct proxy capture.",
55
"type": "module",

0 commit comments

Comments
 (0)