44

since Github Releases are actually a Git Tags, I want to auto-upgrade my package.json version when there is a new Release (and tag), with Github Action.

I know I need to trigger a job on: release, but according to Github Actions docs I don't know if I need to trigger when created, published, both or all?

Github says:

Note: The release event is not triggered for draft releases.

And I created two pipelines: one on: release, type: created and one on: release, type: published.

Then I created a draft release, and then I published it.

Only the published pipeline triggered, and it was when I published the release.

1

4 Answers 4

41

My experience has been the opposite of what was described here on the forum. When tested:

  • If the release is created from "Draft a new release" button on the /releases page, both events will trigger, as the release goes from state "draft" to "published".
  • If the release is created by scripts like release-it, bypassing "draft" stage and becoming "published" directly, only release:published will trigger

So apparently a release can be published without being created. Weird indeed. I'd go with published.

16
+100

In case you are trying to capture the creation and publishing of a release triggered from a Github Action into another workflow, then it is not gonna work.

The solution is to unify both workflows into a single one so that after the release is created the next workflow continues.

Source: https://twitter.com/ethomson/status/1183838077166477316

Example:

name: Create Release and Publish

# Trigger the create release workflow
on:
  push:
    tags:
      - 'v*'

jobs:
  release:
    name: Create Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Create Release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          draft: false
          prerelease: false

  publish-gpr:
    needs: release # After release is created then run the second workflow
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 10
          registry-url: https://npm.pkg.github.com/
      - run: npm ci
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
2
  • Why not use: on: release: types: [ created ] Commented May 25, 2021 at 17:35
  • 2
    @IgorGanapolsky When you use the repository's GITHUB_TOKEN to perform tasks, events triggered by the GITHUB_TOKEN, with the exception of workflow_dispatch and repository_dispatch, will not create a new workflow run. docs.github.com/en/actions/using-workflows/…
    – Mathias
    Commented Feb 14, 2023 at 20:42
3

A release can be created but not published. This is the case for draft releases.

I would suggest going with the published type of release.

1
  • 2
    See the link in my question. Github says "Note: The release event is not triggered for draft releases". But I'm going to check this.
    – baruchiro
    Commented Dec 13, 2019 at 13:13
1

After I checked out the differences between them here:

https://docs.github.com/en/webhooks/webhook-events-and-payloads#release

enter image description here

And a note from here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#release.

enter image description here

Although the documentation doesn't explicitly say so, I'm guessing that created should only take effect when creating a pre-release/release on the GitHub browser UI.

This also matches the conclusion of the top-vote answer. The created must go through the draft phase to be triggered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.