Files
BlueRoseNote/07-Other/AI/AI Agent/WY/NPM.md

137 lines
5.8 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
npm 登录发布流程
- 安装 node/npm 开发环境
- 使用个人帐号和 auth tokenV1 登录 npm
- 访问 https://console-auth.nie.netease.com/ ,获取 v1 token
- 执行 `npm login --registry https://npm.nie.netease.com`
- 输入 Username : 个人 auth 帐号姓名
- 输入 Password : V1 token
- 输入 Email : 个人 auth 帐号邮箱
- 设置相应 npm 包的 scope例如 @test
- npm set @test:registry https://npm-testing.nie.netease.com
- 进入对应的包文件目录
- 执行 `npm publish` 进行包的发布
### [](https://km.netease.com/wiki/25/page/93834#%E8%AE%BF%E9%97%AE%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83)访问测试环境
如果需要访问 https://npm-testing.nie.netease.com/
将上述步骤中的设置 scope 和登陆 npm 时的 registry 替换为相应的 https://npm-testing.nie.netease.com/ 即:
- npm set @test:registry https://npm-testing.nie.netease.com
- npm login --registry https://npm-testing.nie.netease.com
## 发布系统模块
### [](https://km.netease.com/wiki/25/page/97243#%E6%89%8B%E5%8A%A8%E5%8F%91%E5%B8%83)手动发布
系统模块的发布在 neo-module 目录下进行
#### [](https://km.netease.com/wiki/25/page/97243#%E7%99%BB%E9%99%86-npm)登陆 npm
**注意**:首次发布需要在终端界面登陆 npm 并设置 @neo 域(不需要通过 web 端登陆):
```bash
$ npm login --registry https://npm.nie.netease.com
# 用户名和密码为你的 AUTH_USER 和 AUTH_TOKEN
# AUTH_TOKEN 可以在 https://console-auth.nie.netease.com/mymessage/mymessage 的 v1 Token 复制出来
$ npm set @neo:registry https://npm.nie.netease.com
```
#### [](https://km.netease.com/wiki/25/page/97243#%E6%89%A7%E8%A1%8C%E5%8F%91%E5%B8%83%E5%91%BD%E4%BB%A4)执行发布命令
```bash
$ npm run upload
```
首先会进行版本号和更新日志的设置,根据提示完成即可
![请在这里输入图片描述](https://sawiki2.nie.netease.com/media/image/linyifan/20200525145924.png)
```gams
模块的版本默认会根据当前的版本计算出下一个发布的版本,以当前为 1.0.2 为例
测试环境,在版本号后面加上 beta 版本号,即 1.0.2-beta.1,后续会在最后的数字上进行叠加
正式环境在版本号第三位叠加1即 1.0.3,如果需要进行第二位第一位的递增,手动修改即可
```
![请在这里输入图片描述](https://sawiki2.nie.netease.com/media/image/linyifan/20200525145940.png)
看到上述提示则表示发布成功
### [](https://km.netease.com/wiki/25/page/97243#%E9%85%8D%E7%BD%AE-ci-%E8%87%AA%E5%8A%A8%E5%8F%91%E5%B8%83)配置 CI 自动发布
可以使用 gitlab ci添加 CI 自动发布流程
若原系统未配置 gitlab-ci请参考文档进行配置 https://docs.gitlab.com/ee/ci/README.html
#### [](https://km.netease.com/wiki/25/page/97243#%E8%AE%BE%E7%BD%AE-ci-%E5%8F%98%E9%87%8F)设置 CI 变量
首先需要模块管理员设置用于发布 package 的 npm token。
1. 登录 npm参考手动发布中的登录说明
2. 获取个人的 npm token `~/.npmrc` 中 `//npm.nie.netease.com/:_authToken` 配置项的值(不含引号)
3. 在 Gitlab 上设置 CI/CD Variable。
在 package 的 repo 中,点击 [Settings] - [CI / CD],在 Variables 中,添加 `NPM_TOKEN` 变量,值为上一步获取的 npm token。
#### [](https://km.netease.com/wiki/25/page/97243#%E6%B7%BB%E5%8A%A0gitablciyaml%E6%96%87%E4%BB%B6)添加.gitabl.ci.yaml文件
目前neo-script已经支持命令行式执行发布。只需要在项目根目录添加 `.gitlab-ci.yml` 文件,执行对应的发布操作即可。
CI流程主要分为两个阶段
1. `build` 阶段,业务系统模块资源打包,根据实际情况进行配置,打包后会输出项目静态资源
2. `upload` 阶段neo 模块打包与发布,通过 neo-scripts 进行资源处理和上传
```yaml
# 测试环境自动上传静态文件到 neo
upload-test-neo:
tags:
- docker # runner 根据实际情况配置
stage: upload
dependencies:
- build_image # 填入构建 job 的名称
script:
- cd ./neo-module
- npm config set @neo:registry https://npm.nie.netease.com
- npm config set @nie:registry https://npm.nie.netease.com
- npm config set //npm.nie.netease.com/:_authToken $NPM_TOKEN
- npm install
- npx neo-scripts publish --env test && npx neo-scripts build && npm publish
except: # 除了 master develop 和 tags 构建,均上传到 neo 测试环境
- master
- develop
- tags
artifacts: # 配置 artifacts 可以在同个 pipeline 里面共享不同 job 的文件(构建 job 也需要这个配置)
paths:
- ./build # 这里填写构建后静态资源的输出目录
expire_in: 1 day
# 正式环境自动上传静态文件到 neo
upload-prod-neo:
tags:
- docker # runner 根据实际情况配置
stage: upload
dependencies:
- build_image # 填入构建 job 的名称
script:
- cd ./neo-module
- npm config set @neo:registry https://npm.nie.netease.com
- npm config set @nie:registry https://npm.nie.netease.com
- npm config set //npm.nie.netease.com/:_authToken $NPM_TOKEN
- npm install
- npx neo-scripts publish --env prod && npx neo-scripts build && npm publish
only:
- tags # 仅 tag 构建时上传到 neo 正式环境
artifacts: # 配置 artifacts 可以在同个 pipeline 里面共享不同 job 的文件(构建 job 也需要这个配置)
paths:
- ./build # 这里填写构建后静态资源的输出目录
expire_in: 1 day
```
### [](https://km.netease.com/wiki/25/page/97243#%E7%A1%AE%E8%AE%A4%E5%8F%91%E5%B8%83%E7%BB%93%E6%9E%9C)确认发布结果
登陆 https://npm.nie.netease.com 并搜索系统模块名查看 version 可以确定模块版本是否正确发布