GitHub Actions Tutorial — Release Events

2 minute read

Release Events

The release trigger fires when a GitHub release is created, published, edited, or deleted. This is the standard way to automate release pipelines — building binaries, publishing packages, and deploying production code.


Release Activity Types

on:
  release:
    types: [published]
Activity Type When It Fires
published Release is published (most common)
created Release is created (draft or published)
edited Release notes or assets are edited
released Release changed from draft to published
prereleased Pre-release is published
deleted Release is deleted

Best practice: Use published for production releases. It fires when a release goes from draft to published, or when a non-draft release is created directly.


Publish to npm on Release


name: Publish to npm

on:
  release:
    types: [published]

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: 20
          registry-url: 'https://registry.npmjs.org'

      - run: npm ci
      - run: npm test
      - run: npm publish --provenance --access public
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}


Build and Upload Release Assets


name: Release Binaries

on:
  release:
    types: [published]

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4

      - name: Build binary
        run: |
          go build -o myapp-linux-amd64
          tar czf myapp-linux-amd64.tar.gz myapp-linux-amd64

      - name: Upload to release
        uses: softprops/action-gh-release@v2
        with:
          files: myapp-linux-amd64.tar.gz


Release Context Variables

When a release triggers the workflow, you get release-specific context:

Variable Value
${{ github.event.release.tag_name }} v2.1.0
${{ github.event.release.name }} Release 2.1.0
${{ github.event.release.body }} Release notes (markdown)
${{ github.event.release.prerelease }} true or false
${{ github.event.release.draft }} true or false

Issue and Issue Comment Events

Beyond releases, you can trigger workflows on issue and comment activity:

Issue Events


on:
  issues:
    types: [opened, labeled]

jobs:
  triage:
    runs-on: ubuntu-latest
    steps:
      - name: Auto-assign
        if: contains(github.event.issue.labels.*.name, 'bug')
        run: echo "Bug issue opened — assigning to on-call team"

Issue Comment Events


on:
  issue_comment:
    types: [created]

jobs:
  slash-command:
    if: startsWith(github.event.comment.body, '/deploy')
    runs-on: ubuntu-latest
    steps:
      - run: echo "Deploy command received from ${{ github.event.comment.user.login }}"


Common Mistakes

Mistake Fix
Workflow runs on draft releases Use types: [published] not types: [created]
Can’t access release tag Use ${{ github.event.release.tag_name }}, not ${{ github.ref }}
Release asset upload fails Add permissions: contents: write to the job

Quick Reference

Trigger Activity Type Use Case
release: published Production release Publish packages, deploy
release: prereleased Pre-release Staging deploy, beta publish
issues: opened New issue Auto-triage, auto-label
issue_comment: created New comment Slash commands, chatops

← Previous: Schedule & Dispatch

Next: Workflow Run Chain →

Updated: