Skip to content

feat: allow custom release title and body through workflow inputs #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 74 additions & 9 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,26 @@ name: "Release New Version"

on:
workflow_dispatch:
inputs:
release_title:
description: "Title for the release"
required: true
release_body:
description: "Additional notes (optional)"
required: false
default: ""

permissions:
contents: write

jobs:
publish:
name: "Publish to NPM"
runs-on: ubuntu-latest

steps:
- name: "Checkout source code"
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: "Set up Node.js"
uses: actions/setup-node@v3
Expand All @@ -29,7 +37,63 @@ jobs:

- name: "Get version from package.json"
id: get_version
run: echo "version=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
run: |
VERSION="v$(node -p 'require("./package.json").version')"
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Get previous Git tag
id: get_previous_tag
run: |
VERSION="${{ steps.get_version.outputs.version }}"
PREV_TAG=$(git tag --sort=-creatordate | grep '^v' | grep -v "$VERSION" | head -n 1)
echo "previous_tag=$PREV_TAG" >> $GITHUB_OUTPUT

- name: Fetch and categorize merged PRs
id: fetch_prs
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
PREVIOUS_TAG=${{ steps.get_previous_tag.outputs.previous_tag }}
if [ -z "$PREVIOUS_TAG" ]; then
echo "pr_list=No previous tag found to compare PRs." >> $GITHUB_OUTPUT
exit 0
fi
PREVIOUS_SHA=$(git rev-list -n 1 $PREVIOUS_TAG)
PREVIOUS_DATE=$(git show -s --format=%cI $PREVIOUS_SHA)
CURRENT_DATE=$(git show -s --format=%cI HEAD)
echo "Fetching PRs merged between $PREVIOUS_DATE and $CURRENT_DATE"

RAW_PRS=$(gh pr list --state merged --search "merged:${PREVIOUS_DATE}..${CURRENT_DATE}" \
--json number,title,url \
--jq '.[] | "- [#\(.number)](\(.url)) \(.title)"')

if [ -z "$RAW_PRS" ]; then
echo "pr_list=No pull requests were merged during this release." >> $GITHUB_OUTPUT
exit 0
fi

ADDED=""
FIXED=""
while IFS= read -r pr; do
if echo "$pr" | grep -iq "fix"; then
FIXED+="$pr"$'\n'
else
ADDED+="$pr"$'\n'
fi
done <<< "$RAW_PRS"

BODY=""
if [ -n "$ADDED" ]; then
BODY="$BODY### Added"$'\n'"$ADDED"
fi
if [ -n "$FIXED" ]; then
BODY="$BODY"$'\n'"### Fixed"$'\n'"$FIXED"
fi

echo "pr_list<<EOF" >> $GITHUB_OUTPUT
echo "$BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: "Set Git user name and email"
run: |
Expand All @@ -51,11 +115,12 @@ jobs:
uses: actions/create-release@v1
with:
tag_name: ${{ steps.get_version.outputs.version }}
release_name: Release ${{ steps.get_version.outputs.version }}
release_name: ${{ github.event.inputs.release_title }}
body: |
```
• See CHANGELOG.md for details
• Published by ${{ github.actor }}
```
${{ github.event.inputs.release_body }}

${{ steps.fetch_prs.outputs.pr_list }}

Published by ${{ github.actor }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}