-
-
Notifications
You must be signed in to change notification settings - Fork 6
247 lines (214 loc) · 11.2 KB
/
release-notes.yml
File metadata and controls
247 lines (214 loc) · 11.2 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name: Generate Release Notes
on:
release:
types: [created, published]
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name for the release'
required: true
type: string
target_commitish:
description: 'Target branch or commit (default: main)'
required: false
default: 'main'
type: string
permissions:
contents: read
jobs:
generate-release-notes:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: '20'
- name: Get release information
id: release_info
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG_NAME="${{ github.event.inputs.tag_name }}"
TARGET_COMMITISH="${{ github.event.inputs.target_commitish }}"
else
TAG_NAME="${{ github.event.release.tag_name }}"
TARGET_COMMITISH="${{ github.event.release.target_commitish }}"
fi
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
echo "target_commitish=$TARGET_COMMITISH" >> $GITHUB_OUTPUT
# Get previous tag
PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -v "$TAG_NAME" | head -n 1)
if [ -z "$PREVIOUS_TAG" ]; then
# If no previous tag, use first commit
PREVIOUS_TAG=$(git rev-list --max-parents=0 HEAD)
fi
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
# Get version without 'v' prefix
VERSION=${TAG_NAME#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Generate categorized commit list
id: categorize_commits
run: |
# Create arrays for different categories
declare -a features=()
declare -a bugfixes=()
declare -a breaking=()
declare -a documentation=()
declare -a internal=()
declare -a dependencies=()
declare -a other=()
# Get commits since last release
COMMITS=$(git log ${{ steps.release_info.outputs.previous_tag }}..${{ steps.release_info.outputs.tag_name }} --pretty=format:"%h|%s|%an" --no-merges)
# Categorize commits
while IFS='|' read -r hash subject author; do
if [[ -z "$hash" ]]; then continue; fi
# Convert to lowercase for matching
lower_subject=$(echo "$subject" | tr '[:upper:]' '[:lower:]')
if [[ $lower_subject =~ ^feat(\(.*\))?!: ]] || [[ $lower_subject =~ breaking ]]; then
breaking+=("- $subject ([${hash}](https://github.com/${{ github.repository }}/commit/${hash})) by @${author}")
elif [[ $lower_subject =~ ^feat(\(.*\))?: ]] || [[ $lower_subject =~ ^add ]] || [[ $lower_subject =~ ^implement ]]; then
features+=("- $subject ([${hash}](https://github.com/${{ github.repository }}/commit/${hash})) by @${author}")
elif [[ $lower_subject =~ ^fix(\(.*\))?: ]] || [[ $lower_subject =~ ^bug ]] || [[ $lower_subject =~ ^patch ]]; then
bugfixes+=("- $subject ([${hash}](https://github.com/${{ github.repository }}/commit/${hash})) by @${author}")
elif [[ $lower_subject =~ ^docs(\(.*\))?: ]] || [[ $lower_subject =~ documentation ]] || [[ $lower_subject =~ readme ]]; then
documentation+=("- $subject ([${hash}](https://github.com/${{ github.repository }}/commit/${hash})) by @${author}")
elif [[ $lower_subject =~ ^chore(\(.*\))?: ]] || [[ $lower_subject =~ ^ci(\(.*\))?: ]] || [[ $lower_subject =~ ^test(\(.*\))?: ]] || [[ $lower_subject =~ ^refactor(\(.*\))?: ]]; then
internal+=("- $subject ([${hash}](https://github.com/${{ github.repository }}/commit/${hash})) by @${author}")
elif [[ $lower_subject =~ ^deps(\(.*\))?: ]] || [[ $lower_subject =~ dependencies ]] || [[ $lower_subject =~ package ]] || [[ $lower_subject =~ bump ]]; then
dependencies+=("- $subject ([${hash}](https://github.com/${{ github.repository }}/commit/${hash})) by @${author}")
else
other+=("- $subject ([${hash}](https://github.com/${{ github.repository }}/commit/${hash})) by @${author}")
fi
done <<< "$COMMITS"
# Export arrays as multiline strings
printf '%s\n' "${features[@]}" > features.txt
printf '%s\n' "${bugfixes[@]}" > bugfixes.txt
printf '%s\n' "${breaking[@]}" > breaking.txt
printf '%s\n' "${documentation[@]}" > documentation.txt
printf '%s\n' "${internal[@]}" > internal.txt
printf '%s\n' "${dependencies[@]}" > dependencies.txt
printf '%s\n' "${other[@]}" > other.txt
- name: Get contributors
id: contributors
run: |
# Get unique contributors for this release
CONTRIBUTORS=$(git log ${{ steps.release_info.outputs.previous_tag }}..${{ steps.release_info.outputs.tag_name }} --pretty=format:"%an" --no-merges | sort -u | sed 's/^/- @/' | tr '\n' '\n')
echo "contributors<<EOF" >> $GITHUB_OUTPUT
echo "$CONTRIBUTORS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Generate release notes
id: generate_notes
run: |
# Read template
TEMPLATE=$(cat .github/release-notes-template.md)
# Read categorized sections
FEATURES=$(cat features.txt || echo "No new features in this release.")
BUGFIXES=$(cat bugfixes.txt || echo "No bug fixes in this release.")
BREAKING=$(cat breaking.txt || echo "No breaking changes in this release.")
DOCUMENTATION=$(cat documentation.txt || echo "No documentation changes in this release.")
INTERNAL=$(cat internal.txt || echo "No internal changes in this release.")
DEPENDENCIES=$(cat dependencies.txt || echo "No dependency updates in this release.")
OTHER=$(cat other.txt || echo "No other changes in this release.")
# Replace placeholders
NOTES="$TEMPLATE"
NOTES="${NOTES//\{version\}/${{ steps.release_info.outputs.version }}}"
NOTES="${NOTES//\{features\}/$FEATURES}"
NOTES="${NOTES//\{bugfixes\}/$BUGFIXES}"
NOTES="${NOTES//\{breaking\}/$BREAKING}"
NOTES="${NOTES//\{documentation\}/$DOCUMENTATION}"
NOTES="${NOTES//\{internal\}/$INTERNAL}"
NOTES="${NOTES//\{dependencies\}/$DEPENDENCIES}"
NOTES="${NOTES//\{other\}/$OTHER}"
NOTES="${NOTES//\{refactoring\}/No refactoring changes in this release.}"
NOTES="${NOTES//\{compare_url\}/https://github.com/${{ github.repository }}/compare/${{ steps.release_info.outputs.previous_tag }}...${{ steps.release_info.outputs.tag_name }}}"
NOTES="${NOTES//\{contributors\}/${{ steps.contributors.outputs.contributors }}}"
NOTES="${NOTES//\{commits\}/[View all commits](https://github.com/${{ github.repository }}/compare/${{ steps.release_info.outputs.previous_tag }}...${{ steps.release_info.outputs.tag_name }})}"
# Add placeholder sections for manual editing
NOTES="${NOTES//\{upgrade_notes\}/<!-- Add any upgrade notes or migration steps here -->}"
NOTES="${NOTES//\{known_issues\}/<!-- Add any known issues or caveats here -->}"
# Save to file
echo "$NOTES" > release-notes.md
# Also set as output for updating release
echo "notes<<EOF" >> $GITHUB_OUTPUT
echo "$NOTES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Update release with generated notes
if: github.event_name == 'release'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const releaseNotes = fs.readFileSync('release-notes.md', 'utf8');
// Get the current release
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: '${{ steps.release_info.outputs.tag_name }}'
});
// Update the release with generated notes
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
body: releaseNotes
});
console.log('Release notes updated successfully!');
- name: Create draft release (for manual dispatch)
if: github.event_name == 'workflow_dispatch'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const releaseNotes = fs.readFileSync('release-notes.md', 'utf8');
try {
// Try to get existing release
const existingRelease = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: '${{ steps.release_info.outputs.tag_name }}'
});
// Update existing release
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: existingRelease.data.id,
body: releaseNotes
});
console.log('Existing release updated with generated notes!');
} catch (error) {
if (error.status === 404) {
// Create new draft release
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ steps.release_info.outputs.tag_name }}',
target_commitish: '${{ steps.release_info.outputs.target_commitish }}',
name: `Release ${{ steps.release_info.outputs.version }}`,
body: releaseNotes,
draft: true,
prerelease: false
});
console.log(`Draft release created: ${release.data.html_url}`);
} else {
throw error;
}
}
- name: Upload release notes as artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: release-notes-${{ steps.release_info.outputs.version }}
path: release-notes.md
retention-days: 30