Skip to content

Create release PR

Create release PR #3

name: Create release PR
permissions:
contents: read
on:
workflow_dispatch:
inputs:
version:
description: 'The version number to release (has priority over release_type)'
type: string
release_type:
description: Type of release
type: choice
default: patch
options:
- patch
- minor
- major
jobs:
create-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
version: ${{ steps.bump.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Git Config
run: |
git config --global user.email "github-actions@github.com"
git config --global user.name "github-actions"
- name: Change version number and push
id: bump
run: |
npm version ${{ inputs.version || inputs.release_type }} --git-tag-version=false
VERSION=`jq -r ".version" package.json`
RELEASE_BRANCH="release/v$VERSION"
git add -u
git commit -m "Bumped v$VERSION"
git push origin "HEAD:$RELEASE_BRANCH"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create PR
uses: actions/github-script@v7
with:
script: |
const defaultBranch = "${{ github.event.repository.default_branch }}"
const { owner, repo } = context.repo
const version = "v${{ steps.bump.outputs.version }}"
const { data: releases } = await github.rest.repos.listReleases({
owner,
repo
})
const { data: { body } } = await github.rest.repos.generateReleaseNotes({
owner,
repo,
tag_name: version,
target_commitish: defaultBranch,
previous_tag_name: releases[0]?.tag_name
});
await github.rest.pulls.create({
owner,
repo,
head: `release/${version}`,
base: defaultBranch,
title: `Create release ${version}`,
body
})