Skip to content

Release

Release #5

Workflow file for this run

name: Release
on:
# Manual trigger from the Actions tab: pick patch/minor/major and run.
workflow_dispatch:
inputs:
bump:
description: 'Version bump'
required: true
type: choice
default: patch
options:
- patch
- minor
- major
permissions:
# Push the version bump commit + tag and create the GitHub release.
contents: write
# Dispatch the publish workflow on the new tag.
actions: write
# Never run two releases at the same time.
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
name: Release (${{ inputs.bump }})
runs-on: ubuntu-latest
steps:
- name: Ensure release runs from the default branch
if: github.ref_name != github.event.repository.default_branch
run: |
echo "::error::Releases must be run from ${{ github.event.repository.default_branch }}, not ${{ github.ref_name }}"
exit 1
# Full history and tags are required: conventional-changelog reads the
# commits since the previous vX.Y.Z tag. With the default shallow
# checkout it sees a single untagged commit and generates an empty
# changelog section without even a compare link.
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
- run: npm ci
# Never tag a broken build.
- run: npm run lint
- run: npm run prettier-check
- run: npm run check-types
- run: npm run coverage
- name: Bump version, update changelog, commit and tag
env:
BUMP: ${{ inputs.bump }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
npm version "$BUMP" --no-git-tag-version
VERSION="$(node -p "require('./package.json').version")"
# Prepend this release's section (conventional commits since the
# last tag) to CHANGELOG.md. Must run before the tag is created:
# once HEAD is tagged there are no "unreleased" commits left.
npm run changelog
git add package.json package-lock.json CHANGELOG.md
git commit -m "chore(release): v$VERSION"
git tag -a "v$VERSION" -m "v$VERSION"
git push --follow-tags origin HEAD
- name: Create GitHub release with changelog notes
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="$(node -p "require('./package.json').version")"
# The release body is this version's section of CHANGELOG.md
# (everything from the first "## " heading to the next one).
awk '/^## /{n++} n==1' CHANGELOG.md > "$RUNNER_TEMP/release-notes.md"
gh release create "v$VERSION" --title "v$VERSION" --notes-file "$RUNNER_TEMP/release-notes.md" --verify-tag
# A tag pushed with GITHUB_TOKEN does not fire the publish workflow's
# tag-push trigger (GitHub blocks workflow-to-workflow push events), so
# dispatch it explicitly on the new tag.
- name: Trigger npm publish
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="v$(node -p "require('./package.json').version")"
gh workflow run publish.yml --ref "$TAG"