Github Action different between release created and published

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.


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