Skip to content

Commit ea5ea01

Browse files
authored
feat: allow custom release title and body through workflow inputs (#50)
* feat: allow custom release title and body through workflow inputs * remove bullet point from published message * refactor: update npm-publish workflow to improve release notes generation and input handling * chore: remove debug output from npm-publish workflow
1 parent 37bdd22 commit ea5ea01

File tree

1 file changed

+74
-9
lines changed

1 file changed

+74
-9
lines changed

.github/workflows/npm-publish.yml

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@ name: "Release New Version"
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
release_title:
7+
description: "Title for the release"
8+
required: true
9+
release_body:
10+
description: "Additional notes (optional)"
11+
required: false
12+
default: ""
513

614
permissions:
715
contents: write
816

917
jobs:
1018
publish:
11-
name: "Publish to NPM"
1219
runs-on: ubuntu-latest
13-
1420
steps:
1521
- name: "Checkout source code"
1622
uses: actions/checkout@v2
23+
with:
24+
fetch-depth: 0
1725

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

3038
- name: "Get version from package.json"
3139
id: get_version
32-
run: echo "version=v$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
40+
run: |
41+
VERSION="v$(node -p 'require("./package.json").version')"
42+
echo "version=$VERSION" >> $GITHUB_OUTPUT
43+
44+
- name: Get previous Git tag
45+
id: get_previous_tag
46+
run: |
47+
VERSION="${{ steps.get_version.outputs.version }}"
48+
PREV_TAG=$(git tag --sort=-creatordate | grep '^v' | grep -v "$VERSION" | head -n 1)
49+
echo "previous_tag=$PREV_TAG" >> $GITHUB_OUTPUT
50+
51+
- name: Fetch and categorize merged PRs
52+
id: fetch_prs
53+
env:
54+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
run: |
56+
set -e
57+
PREVIOUS_TAG=${{ steps.get_previous_tag.outputs.previous_tag }}
58+
if [ -z "$PREVIOUS_TAG" ]; then
59+
echo "pr_list=No previous tag found to compare PRs." >> $GITHUB_OUTPUT
60+
exit 0
61+
fi
62+
PREVIOUS_SHA=$(git rev-list -n 1 $PREVIOUS_TAG)
63+
PREVIOUS_DATE=$(git show -s --format=%cI $PREVIOUS_SHA)
64+
CURRENT_DATE=$(git show -s --format=%cI HEAD)
65+
echo "Fetching PRs merged between $PREVIOUS_DATE and $CURRENT_DATE"
66+
67+
RAW_PRS=$(gh pr list --state merged --search "merged:${PREVIOUS_DATE}..${CURRENT_DATE}" \
68+
--json number,title,url \
69+
--jq '.[] | "- [#\(.number)](\(.url)) \(.title)"')
70+
71+
if [ -z "$RAW_PRS" ]; then
72+
echo "pr_list=No pull requests were merged during this release." >> $GITHUB_OUTPUT
73+
exit 0
74+
fi
75+
76+
ADDED=""
77+
FIXED=""
78+
while IFS= read -r pr; do
79+
if echo "$pr" | grep -iq "fix"; then
80+
FIXED+="$pr"$'\n'
81+
else
82+
ADDED+="$pr"$'\n'
83+
fi
84+
done <<< "$RAW_PRS"
85+
86+
BODY=""
87+
if [ -n "$ADDED" ]; then
88+
BODY="$BODY### Added"$'\n'"$ADDED"
89+
fi
90+
if [ -n "$FIXED" ]; then
91+
BODY="$BODY"$'\n'"### Fixed"$'\n'"$FIXED"
92+
fi
93+
94+
echo "pr_list<<EOF" >> $GITHUB_OUTPUT
95+
echo "$BODY" >> $GITHUB_OUTPUT
96+
echo "EOF" >> $GITHUB_OUTPUT
3397

3498
- name: "Set Git user name and email"
3599
run: |
@@ -51,11 +115,12 @@ jobs:
51115
uses: actions/create-release@v1
52116
with:
53117
tag_name: ${{ steps.get_version.outputs.version }}
54-
release_name: Release ${{ steps.get_version.outputs.version }}
118+
release_name: ${{ github.event.inputs.release_title }}
55119
body: |
56-
```
57-
• See CHANGELOG.md for details
58-
• Published by ${{ github.actor }}
59-
```
120+
${{ github.event.inputs.release_body }}
121+
122+
${{ steps.fetch_prs.outputs.pr_list }}
123+
124+
Published by ${{ github.actor }}
60125
env:
61-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)