首页 > 其他分享 >Github-Actions使用release-please实现自动发版

Github-Actions使用release-please实现自动发版

时间:2023-03-06 22:04:15浏览次数:44  
标签:major Github outputs please Actions git steps release tag

release please​ 是一个来自于 Google​ 的自动发版工具,基于 Github Actions 可实现全自动发版。

官网:https://github.com/googleapis/release-please

上手

在项目根目录的 .github​ 的 workflows​ 里面新建一个 release-please.yml​ 文件,下面是一个标准的 node 项目的标准配置:

on:
  push:
    branches:
      - main

name: release-please
jobs:
  release-please:
    runs-on: ubuntu-latest
    steps:
      # create release pr
      - uses: google-github-actions/release-please-action@v3
        with:
          release-type: node
          package-name: release-please-action
          changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
      - run: echo "A release was created."
        if: ${{ steps.release.outputs.releases_created }}
      - run: echo "Release ${{ steps.release.outputs['packages/package-a--tag_name'] }} created for package-a."
        if: ${{ steps.release.outputs['packages/package-a--release_created'] }}

      # create tag
      - uses: actions/checkout@v3
      - name: tag major and minor versions
        if: ${{ steps.release.outputs.release_created }}
        run: |
          git config user.name github-actions[bot]
          git config user.email 41898282+github-actions[bot]@users.noreply.github.com
          git tag -d v${{ steps.release.outputs.major }} || true
          git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
          git push origin :v${{ steps.release.outputs.major }} || true
          git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
          git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}"
          git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}"
          git push origin v${{ steps.release.outputs.major }}
          git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}

      # publish to npm
      - uses: actions/setup-node@v1
        with:
          node-version: '16.x'
          registry-url: 'https://registry.npmjs.org'
      - name: Publish to npm
        if: ${{ steps.release.outputs.release_created }}
        run: |
          pnpm install
          pnpm build
          npm publish --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

提交之后,正常情况就会在 main​ 分支的 push​ 事件触发之时,启动自动发版,包括发布到 npm​ 仓库。

如果不需要发布到 npm​ ,可以使用下面的配置:

on:
  push:
    branches:
      - main

name: release-please
jobs:
  release-please:
    runs-on: ubuntu-latest
    steps:
      # create release pr
      - uses: google-github-actions/release-please-action@v3
        with:
          release-type: node
          package-name: release-please-action
          changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false}]'
      - run: echo "A release was created."
        if: ${{ steps.release.outputs.releases_created }}
      - run: echo "Release ${{ steps.release.outputs['packages/package-a--tag_name'] }} created for package-a."
        if: ${{ steps.release.outputs['packages/package-a--release_created'] }}

      # create tag
      - uses: actions/checkout@v3
      - name: tag major and minor versions
        if: ${{ steps.release.outputs.release_created }}
        run: |
          git config user.name github-actions[bot]
          git config user.email 41898282+github-actions[bot]@users.noreply.github.com
          git tag -d v${{ steps.release.outputs.major }} || true
          git tag -d v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
          git push origin :v${{ steps.release.outputs.major }} || true
          git push origin :v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} || true
          git tag -a v${{ steps.release.outputs.major }} -m "Release v${{ steps.release.outputs.major }}"
          git tag -a v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }} -m "Release v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}"
          git push origin v${{ steps.release.outputs.major }}
          git push origin v${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}

注意事项

  • 配置 npm token

    https://www.npmjs.com/settings/terwer/tokens 申请一个 token​ ,然后再项目里面设置:

    Settings -> Secrets and variables -> Actions -> New repository secret​ ,新建一个即可。

  • Github 仓库权限设置

    注意:默认的 Github 仓库不允许拉取,需要开启权限才行。方法如下:

    转到 https://github.com/OWNER/REPO/settings/actions​ 页面向下划到 Workflow Permissions 然后切换到 s Read and Write permissions 。

文章更新历史
2023-03-06 feat:初稿

标签:major,Github,outputs,please,Actions,git,steps,release,tag
From: https://www.cnblogs.com/tangyouwei/p/githubactions-uses-reaseplease-to-implement-automatic

相关文章

  • 开箱即用,你不可错过的好东西「GitHub 热点速览」
    近两周ChatGPT的应用雨后春笋般冒出来,占据了GitHub热榜半个版面,像是本周推荐能搞定一本电子书翻译的bilingual_book_maker,有ChatGPTbuff加成的小爱同学。除了开箱......
  • Github学习
    1.常用词含义watch:会持续收到该项目的动态fork:复制某个仓库到自己的Github仓库中star:可以理解为点赞clone:将项目下载至本地follow:关注你感兴趣的作者,会收到他们的动......
  • git clone的时候出现出现 fatal: unable to access 'https://github.com/...':OpenSSL
    一般发生这种事故因为代理在git种配置的,既然它是https代理(而不是http)gitconfighttp.proxy和gitconfig--globalhttp.proxy也无济于事。解决方案一 1、先看看......
  • git推送项目到GitHub
    记录一下leetcode上的算法练习,将代码记录下来作为记录,如有错误缺漏请多指点一、GitHub上创建项目仓库登录GitHub->newrepository创建库创建完成后可在yourreposito......
  • git push遇到的问题“Please make sure you have the correct access rights and the
    问题:今天在用idea往github推送代码的时候,出现了下面的报错原因:是sshkey有问题,连接不上服务器解决:1.得重新在git设置一下身份的名字和邮箱gitconfig--globaluser.......
  • Github 太卡、连不上、图裂 等等新解决方案
    Github太卡、连不上、图裂等等新解决方案!!之前分享过关于Github浏览太卡、连不上的问题的解决方案,当时确实感觉良好。但后来一看,还是一个坑爹方案,不过由于我常用的是gitee......
  • Github太卡、连不上、图裂 等等新解决方案2.0!!
    Github太卡、连不上、图裂等等新解决方案2.0!!之前给大家推荐SwitchHosts这个软件,效果其实很不错,然每次启动总是需要点步骤。不过我在浏览信息的时候,又发现了新的一种方......
  • Git和Github
    Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。Git与常用的版本控制工具CVS,Subversion等不同,它采用了分布式版本库的方式,不必服务器端......
  • AI 能多强「GitHub 热点速览」
    不知道AI在你那边是什么样的具象,在我这就是各种搞图:从给线稿图上色,到直接给你生成一张小色图,AI最近是真出风头,本周热点速览也收录了2个AI项目,也和图像有关。还有一......
  • 在Github的fork项目中切换分支来提交PR
    在Github的fork项目中切换分支来提交PR查看远程所有分支gitbranch不带参数,列出本地已经存在的分支,并且在当前分支的前面用*标记,加上-a参数可以查看所有分支列表,包括本......