npmnpm

用 GitHub Actions 实现自动发布 NPM 包

2020-05-03  本文已影响0人  Kenny锅

一、前置条件

1.1 生成 NPM TOKEN

生成好了大概长这个样子 1c14ee16-xxxx-4ae3-b09f-faca87axxxx (注:已做脱敏处理)

1.2 加入 GitHub 项目的 secrets 里

二、编写 GitHub Actions 脚本

在你项目里创建 .github/workflows/main.yml 文件,内容如下:

name: Next release

on:
  push:
    branches: [ release ]
  pull_request:
    branches: [ release ]

jobs:
  publish-to-npm:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout release branch code
        uses: actions/checkout@v2

      - name: Use Node.js
        uses: actions/setup-node@v1.4.2
        with:
          node-version: 12
          registry-url: https://registry.npmjs.org

      - name: Publish to NPM
        run: npm publish || true
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

#  publish-to-gpr:
#    runs-on: ubuntu-latest
#    steps:
#      - name: Checkout release branch code
#        uses: actions/checkout@v2
#
#      - name: Use Node.js
#        uses: actions/setup-node@v1.4.2
#        with:
#          node-version: 12
#          registry-url: https://npm.pkg.github.com/
#
#      - name: Publish to GitHub Package
#        run: npm publish
#        env:
#          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

完整内容:https://github.com/Kennytian/tradex/blob/release/.github/workflows/main.yml

脚本解释:

三、额外知识点

最近在学习 Linux,发现一个很好的视频教程,现分享给大家:https://www.bilibili.com/video/BV1mW411i7Qf?p=68

文中运用到的||,详解如下:

全文完!

上一篇下一篇

猜你喜欢

热点阅读