# release-it

适用于自己发过包的小伙伴,对流程有了解的,可以简化一些流程的操作,tag、release、publish npm

# 安装

yarn add @release-it/conventional-changelog release-it -D

# 配置

package.json 中添加配置,这一步完就算安装完毕,提前登录npm就可以使用release-it的publish npm 功能,如果要集成 github action 自动打包发布到npm请继续

{
    // name:对应npm发的包名
    "name": "@fruits-chain/react-native-xiaoshu",
    // 在npm网页上显示
    "repository": {
        "type": "git",
        "url": "https://github.com/hjfruit/react-native-xiaoshu"
    },
    // 在npm网页上显示
    "bugs": {
        "url": "https://github.com/hjfruit/react-native-xiaoshu/issues"
    },
    // 发布到哪一个源
    "publishConfig": {
        "registry": "https://registry.npmjs.org/"
    },
    "release-it": {
        // 配置一些格式
        "git": {
            "commitMessage": "chore: release ${version}",
            "tagName": "v${version}"
        },
        // 是否支持release
        "github": {
            "release": true
        },
        // 关闭则可以,本地发布
        "npm": {
            "publish": false
        }
    }
}

# 获取npm发包token

image-20211214111015051

image-20211214111107892

生成好的access token保存好后面在github中添加使用

# 项目设置Actions secrets

在项目中的Setting中设置刚刚获取的token,key为 NPM_TOKEN

image-20211214112045308

# 添加 github action

创建 .github/workflows/tag.yml ,workflows下任何.yml文件都会被视作action,名字自己根据功能取

name: Next release

on:
  push:
    tags:
      - '*'

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@v2
        with:
          node-version: 11
          registry-url: https://registry.npmjs.org

      - name: build
        run: npm install && npm run build

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

# 最后

最后完成的效果 release-it 帮助我们简化流程,github action 帮我们打包发包,省去登录,切换源操作,如果有安全要求可设置tag或者分支权限即可,最后又一个坑:组织下的包第一次发布要加 npm publish --access public ,建议先手动发一次

lastUpdate: 12/14/2021, 3:39:41 AM