36

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.

Draculater
  • 2,280
  • 1
  • 24
  • 29
baruchiro
  • 5,088
  • 5
  • 44
  • 66
  • [Github Community Forum](https://github.community/t5/GitHub-Actions/What-is-the-created-type-in-on-release/m-p/41171) – baruchiro Dec 13 '19 at 13:39

3 Answers3

35

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.

Lucia
  • 13,033
  • 6
  • 44
  • 50
11

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}}
Lucio
  • 4,753
  • 3
  • 48
  • 77
  • Why not use: `on: release: types: [ created ]` – IgorGanapolsky May 25 '21 at 17:35
  • 1
    @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. https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow – Mathias Feb 14 '23 at 20:42
2

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.

smac89
  • 39,374
  • 15
  • 132
  • 179
  • 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 Dec 13 '19 at 13:13