Skip to content

Create Release PR

Create Release PR #1

name: Create Release PR
on:
workflow_dispatch:
inputs:
version:
description: 'Version type'
required: true
type: choice
options:
- patch
- minor
- major
jobs:
create-release-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3.9.1
with:
node-version: 22
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Version bump
run: |
npm version ${{ github.event.inputs.version }} --no-git-tag-version
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Get release notes
id: release-notes
run: |
# Get the last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
LAST_TAG=$(git rev-list --max-parents=0 HEAD)
fi
# Generate release notes
NOTES=$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
/repos/${{ github.repository }}/releases/generate-notes \
-f tag_name="v${{ env.VERSION }}" \
-f target_commitish="master" \
-f previous_tag_name="${LAST_TAG}" | jq -r '.body')
# Save to file to handle multiline content
echo "$NOTES" > release-notes.md
env:
GH_TOKEN: ${{ github.token }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 # v5.0.2
with:
branch: release/v${{ env.VERSION }}
delete-branch: true
title: "Release v${{ env.VERSION }}"
body-path: release-notes.md
commit-message: "chore: release v${{ env.VERSION }}"
labels: |
Type: Release
assignees: ${{ github.actor }}