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
persist-credentials: false
- 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
id: version
run: |
npm version "$VERSION_TYPE" --no-git-tag-version
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
env:
VERSION_TYPE: ${{ github.event.inputs.version }}
- name: Get release notes
id: release-notes
run: |
# Get the default branch
DEFAULT_BRANCH=$(gh api "repos/$GITHUB_REPOSITORY" --jq '.default_branch')
# 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$VERSION" \
-f target_commitish="$DEFAULT_BRANCH" \
-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 }}
VERSION: ${{ steps.version.outputs.version }}
GITHUB_REPOSITORY: ${{ github.repository }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 # v5.0.2
with:
branch: release/v${{ steps.version.outputs.version }}
delete-branch: true
title: "Release v${{ steps.version.outputs.version }}"
body-path: release-notes.md
commit-message: "chore: release v${{ steps.version.outputs.version }}"
labels: |
Type: Release
assignees: ${{ github.actor }}