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