首页 > 解决方案 > Github Actions:使用提交摘要确定 npm 版本

问题描述

我想知道,如何在 GitHub 操作中检测提交摘要(或描述)的前缀以确定要指定哪个 <update_type> 运行:

npm version <update_type> 

我希望在我的提交描述中添加这样的内容:

[RELEASE/type:"patch"] Lorem ipsum dolor sit amet...
[RELEASE/type:"minor"] Lorem ipsum dolor sit amet...
[RELEASE/type:"major"] Lorem ipsum dolor sit amet...

我也在想我可能只想在没有发布的情况下提交(也许?):

Lorem ipsum dolor sit amet...

本质上,如果存在则提取 RELEASE/type,然后运行:

jobs:
  ci:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [ubuntu-latest]
        node: [14]

    steps:
      - name: Update the published package version number
        run: npm version ${{ EXTRACTED_RELEASE_TYPE }}

但是,我想知道如何从摘要/描述中提取 - 并将其吐出到 env 变量中以增加......

也可能有一个警告,我希望对 repo 的这种更改也被提交?这可能吗?看起来更像是提交后的操作,如果我提交会导致无限循环的麻烦?

如果这是可能的,我认为动作中的 if 语句需要类似于:

if: true === startsWith(github.event.head_commit.message, [RELEASE/type:"minor"])
run: npm version minor

然后确保以某种方式提交对 package.json 的更改?

任何有关如何实现这一目标的专业提示将不胜感激。

标签: github-actions

解决方案


推荐阅读