How to Trigger a Workflow When a Release Is Published in GitHub Actions
The release event with the published type fires when a draft or new release is published, giving you the release metadata in the payload.
Add on.release with types: [published]. Read the tag and upload URL from github.event.release, which is useful for attaching build artifacts to the release.
Steps
- Add
release:underonwithtypes: [published]. - Read
github.event.release.tag_namefor the version. - Attach assets with the GitHub CLI or an upload action.
Workflow
.github/workflows/release-assets.yml
on:
release:
types: [published]
jobs:
assets:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- run: gh release upload "${{ github.event.release.tag_name }}" dist/*.zip
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}Gotchas
- Creating a draft release fires
created, notpublished; use the type that matches your flow. - If the release is created by another workflow using GITHUB_TOKEN, it will not trigger this one, by design.
Related guides
How to Trigger a Workflow on a Tag Push in GitHub ActionsFire a GitHub Actions workflow when a Git tag is pushed using on.push.tags, the standard trigger for building…
How to Trigger a Workflow on a Milestone Event in GitHub ActionsRun a GitHub Actions workflow when a milestone is created, closed, or edited using the milestone event, for r…