githubcontinuous-integrationgithub-actionsrelease

GitHub Actions on release created workflow trigger not working


I have a GitHub Actions workflow implemented on the main branch of my repository which creates a new release of my package in GitHub. Then I have another workflow implemented which should be triggered on the creation of a release. This trigger, however, is not working.

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

My workflow template is as follows:

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 }}

My on:release:created trigger workflow is as follows:

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 }}

The release and tags are correctly added in GitHub, so everything looks to work fine except that the workflow that should be triggered on the release is not executed.

How do I solve this?


Solution

  • The GitHub Actions documentation on performing tasks in a workflow states the following:

    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.

    This means that you will have to create a personal access token and add this token to you repository secrets.

    To generate a new personal access token go to your personal developer settings and generate a new token. Then go to your repository settings and add a new secret containing the personal access token, name it i.e. PAT.

    In your release workflow template, replace:

    token: ${{ github.token }}
    

    With:

    token: ${{ secrets.PAT }}
    

    Now the on release created event the workflow will be triggered!

    Note: This approach seems is a bit hacky, but is currently the only known workaround for this issue and can be considered a major design flaw of workflow integrations.