Github Actions 如何持续部署发布到npm
1. 创建Npm Token
首先进入Npm, 点击头像-> 选择Access Tokens-> Generate New Token, 注册一个 Automation 类型的Token,复制Token串
2. 创建GitHub Action Secret
然后进入github项目-> Setting -> Secrets -> Actions 创建一个secret,Name可以自定义一个如CLEAR_PLUGIN_NPM_TOKEN,Value为刚刚Npm创建的Token串
3. 编写Github Action 部署发布脚本
name: Publish To NPM
on:
push:
tags:
- 'v*'
jobs:
publish:
runs-on: ubuntu-latest
name: 'publish npm'
environment: npm
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- uses: actions/setup-node@v1
with:
node-version: '14'
registry-url: https://registry.npmjs.org/
- name: publish
env:
NODE_AUTH_TOKEN: ${{secrets.CLEAR_PLUGIN_NPM_TOKEN}}
run: npm publish