Creating releases with GitHub Actions
In October 2021, GitHub introduced a feature that allows maintainers to generate release notes for a release automatically. Like ergebnis/github-changelog
, GitHub creates the release notes based on pull requests merged into the default branch since the previous release.
When you use the UI of GitHub to create a release, you can quickly generate these release notes with the click of a button.
Even better, GitHub can automatically generate a changelog for you when you create a release via their API!
In combination with actions/github-script
you can easily create a GitHub Actions workflow that automatically creates a release with changelog when you push a tag.
Here is an example of the release workflow I maintain in ergebnis/php-package-template
, and eventually propagate to and use in all of my open-source repositories in the @ergebnis
organization:
# https://docs.github.com/en/actions
name: "Release"
on: # yamllint disable-line rule:truthy
push:
tags:
- "**"
jobs:
release:
name: "Release"
runs-on: "ubuntu-latest"
steps:
- name: "Determine tag"
run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV"
- name: "Create release"
uses: "actions/github-script@v5"
with:
github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}"
script: |
try {
await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: process.env.RELEASE_TAG,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: process.env.RELEASE_TAG,
});
} catch (error) {
core.setFailed(error.message);
}
You can see an example of a release with release notes created by this workflow in ergebnis/data-provider:1.1.0
.
Feel free to copy, and enjoy!
Project on GitHub
ergebnis/php-package-template
📒 Provides a GitHub repository template for a PHP library, using GitHub actions.
Find out more at ergebnis/php-package-template
.