Prepares a draft GitHub release from a merged release Pull Request (PR): the tag is the version in the title of the merge commit, the target is that commit and the notes are its description.
name: Release
on:
pull_request:
types: [closed]
# NOTE: some repos still use `master`.
branches: [main]
permissions: {}
jobs:
draft-release:
if: |
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'releases/')
runs-on: ubuntu-latest
permissions:
# Required to create the draft release.
contents: write
# Required to comment the draft release on the pull request.
pull-requests: write
steps:
- uses: mozilla/addons/.github/actions/release@43401a931ebc09f2e511deed766171b0105414bc
with:
repo: ${{ github.repository }}
sha: ${{ github.event.pull_request.merge_commit_sha }}
pr: ${{ github.event.pull_request.number }}
github_token: ${{ secrets.GITHUB_TOKEN }}All four inputs are required. Outputs: version and url.
A release starts with a PR from a releases/* branch, with a single commit
that bumps the version, mentions it in its title and has the release notes as
its description. Versions follow semantic versioning.
Here is an example for an npm package:
-
Create the release PR (
npm versiontakesminor,patchormajor, and--no-git-tag-versiononly updatespackage.jsonandpackage-lock.json):version=$(npm version minor --no-git-tag-version) git switch -c "releases/$version" git add package.json package-lock.json # Write the release notes in the description of this commit, also the commit # title might just be "$version" or something more fancy, but it must have # the version number in it. # # `--cleanup=scissors` is used to allow markdown headers in the commit body. git commit --edit --message ":arrow_up: release $version" --cleanup=scissors git push -u origin "releases/$version" -
Open the PR:
gh pr create --fill -
Get it reviewed, then squash and merge it, keeping the release notes in the description of the merge commit (GitHub pre-fills them). The draft release is prepared, but nothing has been released yet!
-
Open the draft release and click Publish release. This creates the tag, which makes CI publish the package to npm. That allows other workflows to be triggered as well.