配置github action
-
创建 workflows在github 项目仓库的Actions下, 在项目setting-secrets-actions,新增一个mpmToken
-
在项目actions中,新建一个publish config,并修改;
-
修改npm-publish.yml,并提交保存
name: Node.js Package
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
- run: npm i
// 如果包中没有测试则不需要这一步
- run: npm run test
publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
registry-url: https://registry.npmjs.org/
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npmToken}}
- on push branches master :表示只要往master上提交代码,就执行action操作,发布到npm远程仓库
- jobs build:构建任务,进行执行安装依赖、单元测试
- jobs publish-npm:进行远程推送到npm仓库操作
评论区