在自定义的 release.yml 文件中根据版本号获取 git 更改

Mub*_*rak 7 javascript release github autorelease github-actions

我的目标是创建一个 GitHub 操作,当 release.yml 文件更改时,它将更新现有版本或在检查该版本是否为新版本后创建新版本,并根据先前的提交进行检查。最终想将此添加到我想添加操作和 release.yml 的其他项目中。

我目前遇到的问题是很难围绕如何去检测 release.yml 文件中的版本更改。

对于添加新版本的非常基本的用例,创建 action.yml 并添加的简单方法

version_1_0: # id of input
description: '1.0'
required: true
default: 'The most important changes are downgrading the artifact to java7 (from 8) and switching to gmavenplus plugin to compile groovy.
      Besides that, there is a lot of restructuring inside of the pom.xml file

      # Misc

      * Polishing (f2ec0bb, 9e2ae89 and 8654493)

      _Reviewed by_: @user' 
Run Code Online (Sandbox Code Playgroud)

稍后在 index.js 文件中

const version = core.getInput('version_1_0');
core.setOutput("ver", version);
Run Code Online (Sandbox Code Playgroud)

给出稍后可以在 GitHub 操作文件中获取和清理的输出,然后转发到发布步骤以用于创建发布

  push:
    paths:
      - release.yml
    branches:
      - file_change_trigger
jobs:
  hello_world_job:
    runs-on: ubuntu-latest
    name: release notes
    outputs:
      output1: ${{ steps.step1.outputs.test }}
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - run: 
            description=${{ steps.hello.outputs.ver }}
            echo $description
            description="${description//'%'/'%25'}" 
            description="${description//$'\n'/'%0A'}"
            description="${description//$'\r'/'%0D'}" 
            echo $description
            echo "::set-output name=test::$description"
  
  release_note:
        name: Create Release
        runs-on: ubuntu-latest
        needs: hello_world_job
        steps:
          - name: Checkout code
            uses: actions/checkout@v2
             # Use the output from the `hello` step
          - name: Get the output time
            run: echo "${{needs.hello_world_job.outputs.output1}}"
          - name: Create Release
            id: create_release
            uses: actions/create-release@v1
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
            with:
              tag_name: ${{ github.ref }}
              release_name: Release ${{ github.ref }}
              body: |
                ${{needs.hello_world_job.outputs.output1}}
              draft: false
              prerelease: false  
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我尝试基于差异的基于文件的触发器时,这种方法被证明是不够的。

示例发布.yml

    v1.0:
     body:
          'The most important changes are downgrading the artifact to java7 (from 8) and switching to gmavenplus plugin to compile groovy.
          Besides that, there is a lot of restructuring inside of the pom.xml file

          # Misc

          * Polishing (f2ec0bb, 9e2ae89 and 8654493)

          _Reviewed by_: @user'
    v2.0:
     body:
          'The most important changes are downgrading the artifact to java7 (from 8) and switching to gmavenplus plugin to compile groovy.
          

          # Misc

          * Polishing (f2ec0bb, 9e2ae89 and 8654493)

          _Reviewed by_: @user'           
Run Code Online (Sandbox Code Playgroud)

小智 1

为什么不使用 Github 版本来跟踪和触发 Github 操作,而不是跟踪 release.yml 文件中的更改。 https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release

on:
  release:
    types: [published]
Run Code Online (Sandbox Code Playgroud)

在这里,您可以选择正确维护版本和更改日志,如果需要,也可以在操作中访问它们。