Skip to content

Release

Release #1

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version bump type'
required: true
type: choice
options:
- patch
- minor
- major
jobs:
create-release-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
# Ensure this workflow only runs from the main branch
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Get current version
id: current_version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
- name: Bump version
id: bump_version
run: |
yarn version --${{ github.event.inputs.version }} --no-git-tag-version
NEW_VERSION=$(node -p "require('./package.json').version")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Bumped version from ${{ steps.current_version.outputs.version }} to $NEW_VERSION"
- name: Generate changelog
id: changelog
run: |
# Get the latest tag
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LATEST_TAG" ]; then
echo "No previous tag found, generating changelog from first commit"
COMMIT_RANGE=$(git rev-list --max-parents=0 HEAD)..HEAD
else
echo "Latest tag: $LATEST_TAG"
COMMIT_RANGE=$LATEST_TAG..HEAD
fi
# Generate changelog
CHANGELOG=$(git log $COMMIT_RANGE --pretty=format:"- %s (%h)" --no-merges)
# Save to file for PR body
cat > /tmp/changelog.md <<EOF
## Changes in v${{ steps.bump_version.outputs.new_version }}
$CHANGELOG
EOF
# Output for use in PR
echo "changelog<<EOF" >> $GITHUB_OUTPUT
cat /tmp/changelog.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Update CHANGELOG.md
run: |
# Create or update CHANGELOG.md
if [ ! -f CHANGELOG.md ]; then
echo "# Changelog" > CHANGELOG.md
echo "" >> CHANGELOG.md
echo "All notable changes to this project will be documented in this file." >> CHANGELOG.md
echo "" >> CHANGELOG.md
fi
# Prepare new entry
cat > /tmp/new_entry.md <<EOF
## [v${{ steps.bump_version.outputs.new_version }}] - $(date +%Y-%m-%d)
EOF
cat /tmp/changelog.md | tail -n +3 >> /tmp/new_entry.md
echo "" >> /tmp/new_entry.md
# Insert after the header
sed -i '1,/^All notable/r /tmp/new_entry.md' CHANGELOG.md || {
# If sed fails (no header found), just prepend
cat /tmp/new_entry.md CHANGELOG.md > /tmp/new_changelog.md
mv /tmp/new_changelog.md CHANGELOG.md
}
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: release/v${{ steps.bump_version.outputs.new_version }}
commit-message: "chore: bump version to v${{ steps.bump_version.outputs.new_version }}"
title: "Release v${{ steps.bump_version.outputs.new_version }}"
body: |
## Release v${{ steps.bump_version.outputs.new_version }}
This PR bumps the version from **v${{ steps.current_version.outputs.version }}** to **v${{ steps.bump_version.outputs.new_version }}**.
${{ steps.changelog.outputs.changelog }}
---
### Release Checklist
- [ ] Review changelog and version bump
- [ ] Merge this PR to main
- [ ] Create a GitHub release from main with tag `v${{ steps.bump_version.outputs.new_version }}`
- [ ] Run `yarn build` locally
- [ ] Run `npm publish` to publish to npm registry
---
*This PR was automatically generated by the release workflow*
labels: |
release
automated