Skip to content

Commit 62a0bed

Browse files
committed
Rebuild variable handling so the data is available to the publish step
1 parent f93deed commit 62a0bed

File tree

1 file changed

+44
-71
lines changed

1 file changed

+44
-71
lines changed

.github/workflows/release.yml

Lines changed: 44 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,113 +6,86 @@ on:
66
bump:
77
description: 'Version bump type'
88
required: true
9+
default: 'patch'
910
type: choice
1011
options:
1112
- patch
1213
- minor
1314
- major
1415
overview:
15-
description: 'Release overview (will be placed at top of notes)'
16-
required: true
16+
description: 'Overview for the release notes (optional)'
17+
required: false
18+
type: string
1719

1820
jobs:
1921
release:
20-
name: Create tag and release
22+
name: Create Release
2123
runs-on: ubuntu-latest
24+
env:
25+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
26+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2227

2328
steps:
24-
- name: Checkout target branch
29+
- name: Checkout repo
2530
uses: actions/checkout@v4
2631
with:
27-
ref: ${{ github.ref_name }}
32+
fetch-depth: 0
2833

2934
- name: Set up Node.js
3035
uses: actions/setup-node@v4
3136
with:
32-
node-version: '20'
33-
34-
- name: Install dependencies
35-
run: npm ci
37+
node-version: 20
3638

37-
- name: Push version bump and tag
39+
- name: Configure git
3840
run: |
3941
git config user.name "github-actions"
4042
git config user.email "[email protected]"
41-
npm version ${{ github.event.inputs.bump }} --no-git-tag-version
42-
version=$(jq -r .version package.json)
43-
git add package.json package-lock.json
44-
git commit -m "Bump version to $version"
45-
git tag $version
46-
git push origin ${{ github.ref_name }}
47-
git push origin $version
4843
49-
- name: Get merged PR titles and format release notes
50-
id: changelog
51-
run: |
52-
git fetch --tags
44+
- name: Fetch tags
45+
run: git fetch --tags
5346

54-
# Get most recent and previous tags
55-
tags=($(git tag --sort=-creatordate))
56-
new_tag="${tags[0]}"
57-
prev_tag="${tags[1]}"
47+
- name: Bump version
48+
run: |
49+
NEW_VERSION=$(npm version ${{ github.event.inputs.bump }} --no-git-tag-version)
50+
echo "VERSION=${NEW_VERSION}" >> $GITHUB_ENV
5851
59-
if [ -z "$prev_tag" ]; then
60-
echo "Warning: No previous tag found. Skipping full changelog link."
61-
changelog=""
62-
else
63-
changelog="**Full Changelog**: https://github.com/${{ github.repository }}/compare/$prev_tag...$new_tag"
64-
fi
52+
- name: Commit and tag version bump
53+
run: |
54+
git commit -am "Bump version to ${VERSION}"
55+
git tag ${VERSION}
56+
git push origin HEAD
57+
git push origin ${VERSION}
6558
66-
prs=$(gh pr list --state merged --base "${{ github.ref_name }}" --json title,mergedAt --jq '[.[] | select(.mergedAt != null) | .title]')
67-
joined=$(echo "$prs" | jq -r '.[]' | sed 's/^/* /')
59+
- name: Get previous tag
60+
id: previous_tag
61+
run: |
62+
PREV_TAG=$(git tag --sort=-creatordate | grep -v ${VERSION} | head -n 1)
63+
echo "PREV_TAG=$PREV_TAG" >> $GITHUB_ENV
64+
echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT
6865
66+
- name: Generate release notes from merged PRs
67+
id: release_notes
68+
run: |
69+
OVERVIEW="${{ github.event.inputs.overview }}"
70+
NOTES=$(git log ${{ env.PREV_TAG }}..HEAD --pretty=format:"* %s" --merges)
71+
echo -e "${OVERVIEW}\n\n## What's Changed\n${NOTES}\n\n**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ env.PREV_TAG }}...${{ env.VERSION }}" > release-notes.md
72+
cat release-notes.md
6973
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
70-
echo "${{ github.event.inputs.overview }}" >> $GITHUB_ENV
71-
echo "" >> $GITHUB_ENV
72-
echo "## What's Changed" >> $GITHUB_ENV
73-
echo "$joined" >> $GITHUB_ENV
74-
echo "" >> $GITHUB_ENV
75-
echo "$changelog" >> $GITHUB_ENV
74+
cat release-notes.md >> $GITHUB_ENV
7675
echo "EOF" >> $GITHUB_ENV
77-
env:
78-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7976
80-
- name: Create GitHub release
77+
- name: Create GitHub Release
8178
run: |
82-
git fetch --tags
83-
tag=$(git describe --tags --abbrev=0)
84-
gh release create "$tag" --title "$tag" --notes "${{ env.RELEASE_NOTES }}"
85-
env:
86-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87-
88-
readme-changelog:
89-
name: Publish changelog to Readme
90-
needs: release
91-
runs-on: ubuntu-latest
92-
93-
steps:
94-
- name: Checkout repo
95-
uses: actions/checkout@v4
96-
97-
- name: Extract release data
98-
id: release
99-
run: |
100-
echo "title=${{ github.ref_name }}" >> $GITHUB_OUTPUT
101-
body=$(gh release view ${{ github.ref_name }} --json body --jq .body)
102-
{
103-
echo "body<<EOF"
104-
echo "$body"
105-
echo "EOF"
106-
} >> $GITHUB_OUTPUT
107-
env:
108-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
gh release create "${VERSION}" \
80+
--title "${VERSION}" \
81+
--notes "$(cat release-notes.md)"
10982
11083
- name: Publish changelog to Readme
11184
env:
11285
README_API_KEY: ${{ secrets.README_API_KEY }}
11386
run: |
114-
jq -n --arg title "Node.js Unified SDK v${{ steps.release.outputs.title }}" \
115-
--arg body "${{ steps.release.outputs.body }}" \
87+
jq -n --arg title "Node.js Unified SDK v${VERSION}" \
88+
--arg body "$(<release-notes.md)" \
11689
'{
11790
title: $title,
11891
content: {

0 commit comments

Comments
 (0)