Skip to content

Commit 76258fc

Browse files
author
perlinson
committed
Fix NPM_TOKEN environment variable in GitHub Actions
🔧 Fix NPM authentication: - Change NPM_TOKEN to NODE_AUTH_TOKEN for consistency - GitHub Actions setup-node expects NODE_AUTH_TOKEN - This should resolve the EOTP authentication error 📋 Context: - setup-node step already configures registry-url and NODE_AUTH_TOKEN - npm publish uses NODE_AUTH_TOKEN for authentication - This eliminates the need for OTP prompts
1 parent 90f35d2 commit 76258fc

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

docs/NPM_2FA_SETUP.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# NPM 双因素认证 (2FA) 设置指南
2+
3+
## 🚨 当前问题
4+
5+
GitHub Actions 发布时遇到 2FA 错误:
6+
```
7+
npm error code EOTP
8+
npm error This operation requires a one-time password from your authenticator.
9+
```
10+
11+
## 🔧 解决方案
12+
13+
### 方法一:使用 NPM Access Token(推荐)
14+
15+
#### 1. 创建 NPM Access Token
16+
17+
1. 登录 [NPM](https://www.npmjs.com)
18+
2. 点击右上角头像 → **Account Settings**
19+
3. 左侧菜单点击 **Access Tokens**
20+
4. 点击 **Generate New Token**
21+
5. 选择 **Automation** 类型
22+
6. 输入 Token 名称(如:modernx-github-actions)
23+
7. 点击 **Generate Token**
24+
8. **立即复制 Token**(只显示一次)
25+
26+
#### 2. 设置 GitHub Secret
27+
28+
1. 访问你的 GitHub 仓库:https://github.com/perlinson/modernx
29+
2. 点击 **Settings** 标签
30+
3. 左侧菜单点击 **Secrets and variables****Actions**
31+
4. 点击 **New repository secret**
32+
5. **Name**: `NPM_TOKEN`
33+
6. **Value**: 粘贴刚才复制的 NPM Access Token
34+
7. 点击 **Add secret**
35+
36+
#### 3. 验证设置
37+
38+
Token 设置完成后,GitHub Actions 会自动使用这个 Token 进行发布,无需 OTP。
39+
40+
### 方法二:禁用 2FA(不推荐)
41+
42+
如果不想使用 2FA:
43+
44+
1. 登录 [NPM](https://www.npmjs.com)
45+
2. 进入 **Account Settings**
46+
3. 找到 **Two-factor authentication**
47+
4. 选择 **Disable**(不推荐,降低安全性)
48+
49+
### 方法三:使用 OTP 参数(仅适用于手动发布)
50+
51+
```bash
52+
# 手动发布时使用 OTP
53+
npm publish --otp=123456
54+
```
55+
56+
## 🎯 设置完成后
57+
58+
设置 NPM_TOKEN 后:
59+
60+
1. **重新触发发布**:
61+
```bash
62+
git tag v1.0.3-test
63+
git push origin v1.0.3-test
64+
```
65+
66+
2. **监控发布状态**:
67+
- 访问 https://github.com/perlinson/modernx/actions
68+
- 查看 NPM Publish 工作流
69+
- 应该不再出现 OTP 错误
70+
71+
## 📋 检查清单
72+
73+
- [ ] 已创建 NPM Access Token
74+
- [ ] 已设置 GitHub Secret `NPM_TOKEN`
75+
- [ ] Token 有发布权限
76+
- [ ] 重新触发发布工作流
77+
- [ ] 监控发布状态
78+
79+
## 🔍 故障排除
80+
81+
### Token 无效
82+
- 检查 Token 是否过期
83+
- 确认 Token 类型是 Automation
84+
- 重新生成新的 Token
85+
86+
### 权限不足
87+
- 确认 Token 有发布权限
88+
- 检查是否是包的维护者
89+
- 联系包所有者添加权限
90+
91+
### 工作流仍然失败
92+
- 检查 Secret 名称是否正确(必须是 `NPM_TOKEN`
93+
- 查看 Actions 日志中的详细错误信息
94+
- 确认 Token 没有过期
95+
96+
## 🚀 发布成功后
97+
98+
发布成功后,你可以:
99+
100+
1. **验证包**: 访问 https://www.npmjs.com/package/modernx-core
101+
2. **测试安装**: `npm install modernx-core@1.0.2`
102+
3. **正式发布**: 使用 `npm run release:patch`
103+
104+
---
105+
106+
设置完成后,自动发布就会正常工作了!🎉

0 commit comments

Comments
 (0)