https://github.com/settings/tokens
把 npm 和 github 的token都配置进去,名称随意
TokenName | Key | Value |
---|---|---|
Personal Access Token | ACCESS_TOKEN | ${{ secrets.ACCESS_TOKEN }} (你刚刚配置的github accessToken的名称) |
Npm Access Token | NODE_AUTH_TOKEN | ${{secrets.NPM_TOKEN}} (你刚刚配置的npmToken的名称) |
name: "publish to npm"
on: workflow_dispatch
jobs:
main:
runs-on: ubuntu-latest
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v2
with:
token: ${{ secrets.ACCESS_TOKEN }}
fetch-depth: 0
- name: ⎔ Setup node
# sets up the .npmrc file to publish to npm
uses: actions/setup-node@v2
with:
node-version: '16.13.0'
registry-url: "https://registry.npmjs.org"
- name: 📥 Download deps
uses: bahmutov/npm-install@v1
with:
useLockFile: false
- name: Configure git user
run: |
git config --global user.email ${{ github.actor }}@users.noreply.github.com
git config --global user.name ${{ github.actor }}
- name: ▶️ Run release
run: npm run release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
github上很多优秀的项目都配置了workflow,可以去参考这些项目怎么写。有多action也被封装好了,可以在market中搜到
npm notice
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using `npm adduser`
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-05-16T02_33_55_906Z-debug.log
Error: Process completed with exit code 1.
解决方案:配置npm 2FA,然后配置 自动化 npm token