Skip to content

Commit 4b3e22f

Browse files
author
Robert Brodie
authored
Merge pull request #412 from swlodarski-sumoheavy/9.3.x-changelog
#406 Add GitHub Actions workflow for automated release process
2 parents 713a729 + ada0310 commit 4b3e22f

1 file changed

Lines changed: 174 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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., 9.3.3)"
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: Update Env.php version
51+
env:
52+
VERSION: ${{ steps.version.outputs.version }}
53+
run: |
54+
sed -i "s/public const BITPAY_PLUGIN_INFO = \"BitPay_PHP_Client_v[0-9.]*\";/public const BITPAY_PLUGIN_INFO = \"BitPay_PHP_Client_v${VERSION}\";/" src/BitPaySDK/Env.php
55+
echo "Updated Env.php with version ${VERSION}"
56+
cat src/BitPaySDK/Env.php | grep BITPAY_PLUGIN_INFO
57+
58+
- name: Update phpdoc.dist.xml version
59+
env:
60+
VERSION: ${{ steps.version.outputs.version }}
61+
run: |
62+
sed -i "s/<version number=\"[0-9.]*\">/<version number=\"${VERSION}\">/" phpdoc.dist.xml
63+
echo "Updated phpdoc.dist.xml with version ${VERSION}"
64+
cat phpdoc.dist.xml | grep -A 1 "<version number"
65+
66+
- name: Commit version updates
67+
env:
68+
BRANCH: ${{ inputs.branch }}
69+
VERSION: ${{ steps.version.outputs.version }}
70+
run: |
71+
git add src/BitPaySDK/Env.php phpdoc.dist.xml
72+
git commit -m "Bump version to $VERSION"
73+
git push origin "$BRANCH"
74+
75+
- name: Create and push tag
76+
env:
77+
VERSION: ${{ steps.version.outputs.version }}
78+
run: |
79+
git tag "$VERSION"
80+
git push origin "$VERSION"
81+
82+
- name: Get merged PR titles and format release notes
83+
id: changelog
84+
env:
85+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86+
OVERVIEW: ${{ inputs.overview }}
87+
BRANCH: ${{ inputs.branch }}
88+
REPOSITORY: ${{ github.repository }}
89+
run: |
90+
git fetch --tags
91+
92+
# Get most recent and previous tags
93+
tags=($(git tag --sort=-creatordate))
94+
new_tag="${tags[0]}"
95+
prev_tag="${tags[1]}"
96+
97+
if [ -z "$prev_tag" ]; then
98+
echo "Warning: No previous tag found. Skipping full changelog link."
99+
changelog=""
100+
else
101+
changelog="**Full Changelog**: https://github.com/$REPOSITORY/compare/$prev_tag...$new_tag"
102+
fi
103+
104+
prs=$(gh pr list --state merged --base "$BRANCH" --json title,mergedAt --jq '[.[] | select(.mergedAt != null) | .title]')
105+
joined=$(echo "$prs" | jq -r '.[]' | sed 's/^/* /')
106+
107+
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
108+
echo "$OVERVIEW" >> $GITHUB_ENV
109+
echo "" >> $GITHUB_ENV
110+
echo "## What's Changed" >> $GITHUB_ENV
111+
echo "$joined" >> $GITHUB_ENV
112+
echo "" >> $GITHUB_ENV
113+
echo "$changelog" >> $GITHUB_ENV
114+
echo "EOF" >> $GITHUB_ENV
115+
116+
- name: Create GitHub Release
117+
env:
118+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119+
NOTES: ${{ env.RELEASE_NOTES }}
120+
VERSION: ${{ steps.version.outputs.version }}
121+
run: |
122+
gh release create "$VERSION" \
123+
--title "$VERSION" \
124+
--notes "$NOTES"
125+
126+
readme-changelog:
127+
name: Publish changelog to Readme
128+
needs: release
129+
runs-on: ubuntu-latest
130+
131+
steps:
132+
- name: Checkout repo
133+
uses: actions/checkout@v6
134+
135+
- name: Extract release data
136+
id: release_data
137+
env:
138+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139+
VERSION: ${{ needs.release.outputs.version }}
140+
run: |
141+
echo "title=$VERSION" >> $GITHUB_OUTPUT
142+
body=$(gh release view "$VERSION" --json body --jq .body)
143+
body_escaped=$(echo "$body" \
144+
| sed 's/&/\&#38;/g' \
145+
| sed 's/</\&#60;/g' \
146+
| sed 's/>/\&#62;/g' \
147+
| sed 's/{/\&#123;/g' \
148+
| sed 's/}/\&#125;/g')
149+
{
150+
echo "body<<EOF"
151+
echo "$body_escaped"
152+
echo "EOF"
153+
} >> $GITHUB_OUTPUT
154+
155+
- name: Publish changelog to Readme
156+
env:
157+
README_API_KEY: ${{ secrets.README_API_KEY }}
158+
RELEASE_TITLE: ${{ steps.release_data.outputs.title }}
159+
RELEASE_BODY: ${{ steps.release_data.outputs.body }}
160+
run: |
161+
jq -n --arg title "BitPay PHP SDK v$RELEASE_TITLE" \
162+
--arg body "$RELEASE_BODY" \
163+
'{
164+
title: $title,
165+
content: {
166+
body: $body
167+
},
168+
privacy: { view: "public" }
169+
}' > payload.json
170+
171+
curl --location 'https://api.readme.com/v2/changelogs' \
172+
--header "Authorization: Bearer $README_API_KEY" \
173+
--header 'Content-Type: application/json' \
174+
--data @payload.json

0 commit comments

Comments
 (0)