Skip to content

Commit 8464239

Browse files
authored
Merge pull request #48 from swlodarski-sumoheavy/2.1.x-changelog
[#47] Push release to Readme.com changelog
2 parents 13da5e0 + 99385cc commit 8464239

1 file changed

Lines changed: 147 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
branch:
7+
description: "Branch to release from"
8+
required: true
9+
default: "master"
10+
type: string
11+
version:
12+
description: "Version number (e.g., 2.1.4)"
13+
required: true
14+
type: string
15+
overview:
16+
description: "Release overview (will be placed at top of notes)"
17+
required: true
18+
type: string
19+
20+
jobs:
21+
release:
22+
name: Create tag and release
23+
runs-on: ubuntu-latest
24+
outputs:
25+
version: ${{ steps.version.outputs.version }}
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v6
30+
with:
31+
ref: ${{ inputs.branch }}
32+
fetch-depth: 0
33+
34+
- name: Validate version format
35+
id: version
36+
env:
37+
VERSION_INPUT: ${{ inputs.version }}
38+
run: |
39+
if [[ ! "$VERSION_INPUT" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
40+
echo "Error: Version must be in format X.Y.Z (e.g., 9.3.3)"
41+
exit 1
42+
fi
43+
echo "version=$VERSION_INPUT" >> $GITHUB_OUTPUT
44+
45+
- name: Configure Git
46+
run: |
47+
git config user.name "github-actions"
48+
git config user.email "github-actions@github.com"
49+
50+
- name: Create and push tag
51+
run: |
52+
git tag "${{ steps.version.outputs.version }}"
53+
git push origin "${{ steps.version.outputs.version }}"
54+
55+
- name: Get merged PR titles and format release notes
56+
id: changelog
57+
env:
58+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
BRANCH_INPUT: ${{ inputs.branch }}
60+
OVERVIEW_INPUT: ${{ inputs.overview }}
61+
REPOSITORY: ${{ github.repository }}
62+
run: |
63+
git fetch --tags
64+
65+
# Get most recent and previous tags
66+
tags=($(git tag --sort=-creatordate))
67+
new_tag="${tags[0]}"
68+
prev_tag="${tags[1]}"
69+
70+
if [ -z "$prev_tag" ]; then
71+
echo "Warning: No previous tag found. Skipping full changelog link."
72+
changelog=""
73+
else
74+
changelog="**Full Changelog**: https://github.com/$REPOSITORY/compare/$prev_tag...$new_tag"
75+
fi
76+
77+
prs=$(gh pr list --state merged --base "$BRANCH_INPUT" --json title,mergedAt --jq '[.[] | select(.mergedAt != null) | .title]')
78+
joined=$(echo "$prs" | jq -r '.[]' | sed 's/^/* /')
79+
80+
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
81+
echo "$OVERVIEW_INPUT" >> $GITHUB_ENV
82+
echo "" >> $GITHUB_ENV
83+
echo "## What's Changed" >> $GITHUB_ENV
84+
echo "$joined" >> $GITHUB_ENV
85+
echo "" >> $GITHUB_ENV
86+
echo "$changelog" >> $GITHUB_ENV
87+
echo "EOF" >> $GITHUB_ENV
88+
89+
- name: Create GitHub Release
90+
env:
91+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
NOTES: ${{ env.RELEASE_NOTES }}
93+
VERSION: ${{ steps.version.outputs.version }}
94+
run: |
95+
gh release create "$VERSION" \
96+
--title "$VERSION" \
97+
--notes "$NOTES"
98+
99+
readme-changelog:
100+
name: Publish changelog to Readme
101+
needs: release
102+
runs-on: ubuntu-latest
103+
104+
steps:
105+
- name: Checkout repo
106+
uses: actions/checkout@v6
107+
108+
- name: Extract release data
109+
id: release_data
110+
env:
111+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
RELEASE_VERSION: ${{ needs.release.outputs.version }}
113+
run: |
114+
echo "title=$RELEASE_VERSION" >> $GITHUB_OUTPUT
115+
body=$(gh release view "$RELEASE_VERSION" --json body --jq .body)
116+
body_escaped=$(echo "$body" \
117+
| sed 's/&/\&#38;/g' \
118+
| sed 's/</\&#60;/g' \
119+
| sed 's/>/\&#62;/g' \
120+
| sed 's/{/\&#123;/g' \
121+
| sed 's/}/\&#125;/g')
122+
{
123+
echo "body<<EOF"
124+
echo "$body_escaped"
125+
echo "EOF"
126+
} >> $GITHUB_OUTPUT
127+
128+
- name: Publish changelog to Readme
129+
env:
130+
README_API_KEY: ${{ secrets.README_API_KEY }}
131+
RELEASE_TITLE: ${{ steps.release_data.outputs.title }}
132+
RELEASE_BODY: ${{ steps.release_data.outputs.body }}
133+
run: |
134+
jq -n --arg title "BitPay Utils cryptography pack v$RELEASE_TITLE" \
135+
--arg body "$RELEASE_BODY" \
136+
'{
137+
title: $title,
138+
content: {
139+
body: $body
140+
},
141+
privacy: { view: "public" }
142+
}' > payload.json
143+
144+
curl --location 'https://api.readme.com/v2/changelogs' \
145+
--header "Authorization: Bearer $README_API_KEY" \
146+
--header 'Content-Type: application/json' \
147+
--data @payload.json

0 commit comments

Comments
 (0)