Skip to content

Release step 1 - Bump version, create PR and draft release #17

Release step 1 - Bump version, create PR and draft release

Release step 1 - Bump version, create PR and draft release #17

name: Release step 1 - Bump version and create PR
on:
workflow_dispatch:
inputs:
bump:
description: "Version bump type"
required: true
default: "minor"
type: choice
options:
- patch
- minor
- major
jobs:
create-release-pr:
name: "πŸš€ Create Release PR (${{ github.event.inputs.bump }})"
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🧰 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: πŸ”’ Get current version
id: get_version
run: echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
- name: βž• Calculate new version
id: bump
run: |
current="${{ steps.get_version.outputs.version }}"
bump="${{ github.event.inputs.bump }}"
new=$(npx semver "$current" -i "$bump")
echo "new_version=$new" >> "$GITHUB_OUTPUT"
- name: πŸ“ List commits since last tag
id: commit_list
run: |
git fetch --tags
last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$last_tag" ]; then
echo "No previous tags found"
echo "last_tag=" >> "$GITHUB_OUTPUT"
git log --pretty=format:"- %s %H" | head -n 20 | tee commits.txt
else
echo "last_tag=$last_tag" >> "$GITHUB_OUTPUT"
git log "$last_tag"..HEAD --pretty=format:"- %s %H" | tee commits.txt
fi
- name: πŸ“’ Show summary in notices
run: |
echo "::notice title=Version::${{ steps.get_version.outputs.version }} ➑️ ${{ steps.bump.outputs.new_version }}"
if [ -s commits.txt ]; then
commits=$(head -n 10 commits.txt | tr '\n' '\r')
echo "::notice title=Commits since ${{ steps.commit_list.outputs.last_tag }}::${commits}"
fi
- name: 🧾 Write Markdown summary
run: |
{
echo "## πŸ”’ Version"
echo "**${{ steps.get_version.outputs.version }} ➑️ ${{ steps.bump.outputs.new_version }}**"
echo ""
echo "## πŸ“ New commits"
echo ""
if [ -s commits.txt ]; then
head -n 20 commits.txt
else
echo "No new commits"
fi
echo ""
echo "## πŸ“Š Additional Information"
echo "- Triggered by: ${{ github.actor }}"
echo "- Branch: ${{ github.ref_name }}"
} >> "$GITHUB_STEP_SUMMARY"
- name: πŸ“‹ Prepare PR Body
id: pr_body
run: |
{
echo "## πŸš€ Release v${{ steps.bump.outputs.new_version }}"
echo ""
echo "### Version Bump"
echo "**${{ steps.get_version.outputs.version }} ➑️ ${{ steps.bump.outputs.new_version }}**"
echo ""
echo "### Commits included in this release"
echo ""
if [ -s commits.txt ]; then
cat commits.txt
else
echo "No new commits"
fi
echo ""
echo "### Additional Information"
echo "- Triggered by: ${{ github.actor }}"
echo "- Source branch: ${{ github.ref_name }}"
echo ""
echo "---"
echo ""
echo "**Note:** After merging this PR, run 'Release step 2' workflow to create a GitHub release."
} > pr_body.txt
body=$(cat pr_body.txt)
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$body" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: πŸš€ Bump version
run: npm version ${{ github.event.inputs.bump }} --no-git-tag-version
- name: 🧹 Clean up temporary files
run: rm -f commits.txt pr_body.txt
- name: πŸ”„ Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: bump version to ${{ steps.bump.outputs.new_version }}"
branch: release/v${{ steps.bump.outputs.new_version }}
delete-branch: true
title: "chore: release v${{ steps.bump.outputs.new_version }}"
body: ${{ steps.pr_body.outputs.body }}
base: main