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

5.8 KiB
Raw Blame History

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 publish 进行包的发布

访问测试环境

如果需要访问 https://npm-testing.nie.netease.com/

将上述步骤中的设置 scope 和登陆 npm 时的 registry 替换为相应的 https://npm-testing.nie.netease.com/ 即:

发布系统模块

手动发布

系统模块的发布在 neo-module 目录下进行

登陆 npm

注意:首次发布需要在终端界面登陆 npm 并设置 @neo 域(不需要通过 web 端登陆):

$ 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

执行发布命令

$ npm run upload

首先会进行版本号和更新日志的设置,根据提示完成即可

请在这里输入图片描述

模块的版本默认会根据当前的版本计算出下一个发布的版本,以当前为 1.0.2 为例

测试环境,在版本号后面加上 beta 版本号,即 1.0.2-beta.1,后续会在最后的数字上进行叠加

正式环境在版本号第三位叠加1即 1.0.3,如果需要进行第二位第一位的递增,手动修改即可

请在这里输入图片描述

看到上述提示则表示发布成功

配置 CI 自动发布

可以使用 gitlab ci添加 CI 自动发布流程

若原系统未配置 gitlab-ci请参考文档进行配置 https://docs.gitlab.com/ee/ci/README.html

设置 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。

添加.gitabl.ci.yaml文件

目前neo-script已经支持命令行式执行发布。只需要在项目根目录添加 .gitlab-ci.yml 文件,执行对应的发布操作即可。

CI流程主要分为两个阶段

  1. build 阶段,业务系统模块资源打包,根据实际情况进行配置,打包后会输出项目静态资源

  2. upload 阶段neo 模块打包与发布,通过 neo-scripts 进行资源处理和上传

# 测试环境自动上传静态文件到 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://npm.nie.netease.com 并搜索系统模块名查看 version 可以确定模块版本是否正确发布