GitHub 对发布创建的工作流触发器的操作不起作用

GitHub Actions on release created workflow trigger not working

我在 GitHub 中有一个 GitHub Actions workflow implemented on the main branch of my repository which creates a new release 我的包裹。然后我实施了另一个工作流,该工作流应在创建发布时触发。但是,此触发器不起作用。

Please note that GitHub abandoned their own actions/create-release@v1 project and advises to use the softprops release action.

我的工作流程模板如下:

name: Main release

on:
  push:
    branches:
      - main

jobs:
  release:
    name: 'Release main'
    runs-on: ubuntu-latest
    steps:
      - name: 'Checkout source code'
        uses: 'actions/checkout@v2'
        with:
          ref: ${{ github.ref }
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          draft: false
          body_path: CHANGELOG.md
          name: ${{ steps.version.outputs.version }}
          tag_name: ${{ github.ref }}
          token: ${{ github.token }}

我的on:release:created触发器工作流程如下:

name: Act on release created

on:
  release:
    types: [created]

jobs:
  build:
    name: Build
    environment: dev_environment
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set env
        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
      - name: Test
        run: |
          echo $RELEASE_VERSION
          echo ${{ env.RELEASE_VERSION }}

在 GitHub 中正确添加了版本和标签,所以除了应该在版本上触发的工作流没有执行之外,一切看起来都工作正常。

我该如何解决这个问题?

GitHub 操作 documentation on performing tasks in a workflow 声明如下:

When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs.

这意味着您必须创建一个个人访问令牌并将此令牌添加到您的存储库机密中。

要生成新的个人访问令牌,请转到您的个人 developer settings 并生成一个新令牌。然后转到您的存储库设置并添加一个包含个人访问令牌的新秘密,将其命名为 PAT.

在您的发布工作流程模板中,替换:

token: ${{ github.token }}

有:

token: ${{ secrets.PAT }}

现在将触发工作流的发布创建事件!

注意:这种做法好像有点hacky,但是目前唯一此问题的已知解决方法,可被视为工作流集成的主要设计缺陷。