Skip to content

Commit 5574410

Browse files
authored
Merge pull request #224 from bitpay/manual-release-workflow
Manual release workflow
2 parents 40680a4 + 3b6c776 commit 5574410

File tree

1 file changed

+76
-45
lines changed

1 file changed

+76
-45
lines changed

.github/workflows/release.yml

Lines changed: 76 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,86 +6,117 @@ on:
66
bump:
77
description: 'Version bump type'
88
required: true
9-
default: 'patch'
109
type: choice
1110
options:
1211
- patch
1312
- minor
1413
- major
1514
overview:
16-
description: 'Overview for the release notes (optional)'
17-
required: false
18-
type: string
15+
description: 'Release overview (will be placed at top of notes)'
16+
required: true
1917

2018
jobs:
2119
release:
22-
name: Create Release
20+
name: Create tag and release
2321
runs-on: ubuntu-latest
24-
env:
25-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
26-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
outputs:
23+
version: ${{ steps.version.outputs.version }}
2724

2825
steps:
29-
- name: Checkout repo
26+
- name: Checkout target branch
3027
uses: actions/checkout@v4
3128
with:
32-
fetch-depth: 0
29+
ref: ${{ github.ref_name }}
3330

3431
- name: Set up Node.js
3532
uses: actions/setup-node@v4
3633
with:
37-
node-version: 20
34+
node-version: '20'
35+
36+
- name: Install dependencies
37+
run: npm ci
3838

39-
- name: Configure git
39+
- name: Push version bump and tag
40+
id: version
4041
run: |
4142
git config user.name "github-actions"
4243
git config user.email "[email protected]"
44+
npm version ${{ github.event.inputs.bump }} --no-git-tag-version
45+
version=$(jq -r .version package.json)
46+
echo "version=$version" >> $GITHUB_OUTPUT
47+
git add package.json package-lock.json
48+
git commit -m "Bump version to $version"
49+
git tag $version
50+
git push origin ${{ github.ref_name }}
51+
git push origin $version
4352
44-
- name: Fetch tags
45-
run: git fetch --tags
46-
47-
- name: Bump version
53+
- name: Get merged PR titles and format release notes
54+
id: changelog
4855
run: |
49-
NEW_VERSION=$(npm version ${{ github.event.inputs.bump }} --no-git-tag-version)
50-
echo "VERSION=${NEW_VERSION}" >> $GITHUB_ENV
56+
git fetch --tags
5157
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}
58+
# Get most recent and previous tags
59+
tags=($(git tag --sort=-creatordate))
60+
new_tag="${tags[0]}"
61+
prev_tag="${tags[1]}"
5862
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
63+
if [ -z "$prev_tag" ]; then
64+
echo "Warning: No previous tag found. Skipping full changelog link."
65+
changelog=""
66+
else
67+
changelog="**Full Changelog**: https://github.com/${{ github.repository }}/compare/$prev_tag...$new_tag"
68+
fi
69+
70+
prs=$(gh pr list --state merged --base "${{ github.ref_name }}" --json title,mergedAt --jq '[.[] | select(.mergedAt != null) | .title]')
71+
joined=$(echo "$prs" | jq -r '.[]' | sed 's/^/* /')
6572
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
7373
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
74-
cat release-notes.md >> $GITHUB_ENV
74+
echo "${{ github.event.inputs.overview }}" >> $GITHUB_ENV
75+
echo "" >> $GITHUB_ENV
76+
echo "## What's Changed" >> $GITHUB_ENV
77+
echo "$joined" >> $GITHUB_ENV
78+
echo "" >> $GITHUB_ENV
79+
echo "$changelog" >> $GITHUB_ENV
7580
echo "EOF" >> $GITHUB_ENV
81+
env:
82+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7683

77-
- name: Create GitHub Release
84+
- name: Create GitHub release
7885
run: |
79-
gh release create "${VERSION}" \
80-
--title "${VERSION}" \
81-
--notes "$(cat release-notes.md)"
86+
gh release create "${{ steps.version.outputs.version }}" \
87+
--title "${{ steps.version.outputs.version }}" \
88+
--notes "${{ env.RELEASE_NOTES }}"
89+
env:
90+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
92+
readme-changelog:
93+
name: Publish changelog to Readme
94+
needs: release
95+
runs-on: ubuntu-latest
96+
97+
steps:
98+
- name: Checkout repo
99+
uses: actions/checkout@v4
100+
101+
- name: Extract release data
102+
id: release_data
103+
run: |
104+
echo "title=${{ needs.release.outputs.version }}" >> $GITHUB_OUTPUT
105+
body=$(gh release view ${{ needs.release.outputs.version }} --json body --jq .body)
106+
{
107+
echo "body<<EOF"
108+
echo "$body"
109+
echo "EOF"
110+
} >> $GITHUB_OUTPUT
111+
env:
112+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82113

83114
- name: Publish changelog to Readme
84115
env:
85116
README_API_KEY: ${{ secrets.README_API_KEY }}
86117
run: |
87-
jq -n --arg title "Node.js Unified SDK v${VERSION}" \
88-
--arg body "$(<release-notes.md)" \
118+
jq -n --arg title "Node.js Unified SDK v${{ steps.release_data.outputs.title }}" \
119+
--arg body "${{ steps.release_data.outputs.body }}" \
89120
'{
90121
title: $title,
91122
content: {
@@ -97,4 +128,4 @@ jobs:
97128
curl --location 'https://api.readme.com/v2/changelogs' \
98129
--header "Authorization: Bearer $README_API_KEY" \
99130
--header 'Content-Type: application/json' \
100-
--data @payload.json
131+
--data @payload.json

0 commit comments

Comments
 (0)