-
Notifications
You must be signed in to change notification settings - Fork 32
295 lines (255 loc) · 10.7 KB
/
prepare-release.yml
File metadata and controls
295 lines (255 loc) · 10.7 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
name: Prepare GPULlama3 Release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., 0.2.3)'
required: true
type: string
previous_version:
description: 'Previous version for changelog (e.g., 0.2.2)'
required: true
type: string
dry_run:
description: 'Dry run - show changes without creating PR'
required: false
type: boolean
default: false
env:
VERSION: ${{ inputs.version }}
PREV_VERSION: ${{ inputs.previous_version }}
jobs:
prepare-release:
if: github.repository == 'beehive-lab/GPULlama3.java'
runs-on: [self-hosted, Linux, x64]
permissions:
contents: write
pull-requests: write
timeout-minutes: 15
env:
JAVA_HOME: /opt/jenkins/jdks/graal-23.1.0/jdk-21.0.3
steps:
- name: Validate version format
run: |
if [[ ! "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Invalid version format. Expected: X.Y.Z (e.g., 0.2.3)"
exit 1
fi
echo "✅ Version format valid: ${{ inputs.version }}"
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup environment
run: |
echo "$JAVA_HOME/bin" >> $GITHUB_PATH
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create release branch
run: |
git checkout -b release/${{ env.VERSION }}
echo "✅ Created branch: release/${{ env.VERSION }}"
# ============================================
# VERSION UPDATES
# ============================================
- name: Update Maven version
run: |
# Update <revision> property directly; versions:set would overwrite
# the CI-friendly ${revision}${jdk.version.suffix} expression.
sed -i 's|<revision>.*</revision>|<revision>${{ env.VERSION }}</revision>|' pom.xml
echo "✅ Maven version updated to ${{ env.VERSION }}"
- name: Update README.md
run: |
if [ -f "README.md" ]; then
# Update version in Maven dependency examples (handles plain X.Y.Z and X.Y.Z-jdkNN suffixes)
sed -i 's|<version>[0-9]\+\.[0-9]\+\.[0-9]\+</version>|<version>${{ env.VERSION }}</version>|g' README.md
sed -i 's|<version>[0-9]\+\.[0-9]\+\.[0-9]\+-jdk[0-9]\+</version>|<version>${{ env.VERSION }}-jdk25</version>|g' README.md
echo "✅ Updated README.md"
fi
- name: Update CITATION.cff
run: |
if [ -f "CITATION.cff" ]; then
sed -i "s/^version: .*/version: ${{ env.VERSION }}/" CITATION.cff
RELEASE_DATE=$(date +"%Y-%m-%d")
sed -i "s/^date-released: .*/date-released: $RELEASE_DATE/" CITATION.cff
echo "✅ Updated CITATION.cff"
fi
# ============================================
# CHANGELOG GENERATION
# ============================================
- name: Fetch merged PRs for changelog
id: fetch_prs
uses: actions/github-script@v7
with:
script: |
const prevVersion = '${{ env.PREV_VERSION }}';
const newVersion = '${{ env.VERSION }}';
let sinceDate;
try {
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 10
});
const prevRelease = releases.find(r =>
r.tag_name === `v${prevVersion}` || r.tag_name === prevVersion
);
if (prevRelease) {
sinceDate = prevRelease.published_at;
console.log(`Found previous release ${prevVersion} from ${sinceDate}`);
}
} catch (e) {
console.log('Could not fetch releases:', e.message);
}
if (!sinceDate) {
const date = new Date();
date.setDate(date.getDate() - 90);
sinceDate = date.toISOString();
console.log(`Using fallback date: ${sinceDate}`);
}
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
sort: 'updated',
direction: 'desc',
per_page: 100
});
const mergedPRs = prs.filter(pr =>
pr.merged_at && new Date(pr.merged_at) > new Date(sinceDate)
);
console.log(`Found ${mergedPRs.length} merged PRs since ${sinceDate}`);
const features = [];
const bugfixes = [];
const models = [];
const performance = [];
const other = [];
for (const pr of mergedPRs) {
const labels = pr.labels.map(l => l.name.toLowerCase());
const title = pr.title;
const entry = `- ${title} ([#${pr.number}](${pr.html_url}))`;
if (labels.some(l => l.includes('bug') || l.includes('fix'))) {
bugfixes.push(entry);
} else if (labels.some(l => l.includes('model')) || title.toLowerCase().includes('model')) {
models.push(entry);
} else if (labels.some(l => l.includes('perf') || l.includes('optim'))) {
performance.push(entry);
} else if (labels.some(l => l.includes('feature') || l.includes('enhancement'))) {
features.push(entry);
} else {
other.push(entry);
}
}
const today = new Date().toISOString().split('T')[0];
let changelog = `## [${newVersion}] - ${today}\n\n`;
if (features.length > 0) {
changelog += '### Features\n\n' + features.join('\n') + '\n\n';
}
if (models.length > 0) {
changelog += '### Model Support\n\n' + models.join('\n') + '\n\n';
}
if (performance.length > 0) {
changelog += '### Performance\n\n' + performance.join('\n') + '\n\n';
}
if (bugfixes.length > 0) {
changelog += '### Bug Fixes\n\n' + bugfixes.join('\n') + '\n\n';
}
if (other.length > 0) {
changelog += '### Other Changes\n\n' + other.join('\n') + '\n\n';
}
if (mergedPRs.length === 0) {
changelog += '<!-- TODO: Add changes manually -->\n\n';
}
const fs = require('fs');
fs.writeFileSync('${{ runner.temp }}/changelog_entry.txt', changelog);
core.setOutput('pr_count', mergedPRs.length);
- name: Update CHANGELOG.md
run: |
CHANGELOG_FILE="CHANGELOG.md"
CHANGELOG_ENTRY="${{ runner.temp }}/changelog_entry.txt"
if [ ! -f "$CHANGELOG_FILE" ]; then
echo "# Changelog" > "$CHANGELOG_FILE"
echo "" >> "$CHANGELOG_FILE"
echo "All notable changes to GPULlama3.java will be documented in this file." >> "$CHANGELOG_FILE"
echo "" >> "$CHANGELOG_FILE"
fi
if grep -q "^## \[" "$CHANGELOG_FILE"; then
FIRST_VERSION_LINE=$(grep -n "^## \[" "$CHANGELOG_FILE" | head -1 | cut -d: -f1)
{
head -n $((FIRST_VERSION_LINE - 1)) "$CHANGELOG_FILE"
cat "$CHANGELOG_ENTRY"
tail -n +$FIRST_VERSION_LINE "$CHANGELOG_FILE"
} > "${{ runner.temp }}/changelog_new.md"
mv "${{ runner.temp }}/changelog_new.md" "$CHANGELOG_FILE"
else
cat "$CHANGELOG_ENTRY" >> "$CHANGELOG_FILE"
fi
echo "✅ Updated CHANGELOG.md"
- name: Show changes summary
run: |
echo "## 📋 Release ${{ env.VERSION }} Preparation" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Files Modified:" >> $GITHUB_STEP_SUMMARY
git diff --name-only | while read file; do
echo "- \`$file\`" >> $GITHUB_STEP_SUMMARY
done
echo "" >> $GITHUB_STEP_SUMMARY
echo "### PRs included: ${{ steps.fetch_prs.outputs.pr_count }}" >> $GITHUB_STEP_SUMMARY
- name: Commit and push
if: ${{ inputs.dry_run == false }}
run: |
git add -A
git commit -m "Prepare release ${{ env.VERSION }}"
git push origin release/${{ env.VERSION }}
- name: Create Pull Request
if: ${{ inputs.dry_run == false }}
uses: actions/github-script@v7
with:
script: |
const version = process.env.VERSION;
const prCount = '${{ steps.fetch_prs.outputs.pr_count }}';
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Release ${version}`,
head: `release/${version}`,
base: 'main',
body: `## 🚀 Release ${version}
### 📝 Changes
- ${prCount} PRs included in changelog
- Version bumped to ${version}
### ✅ Review Checklist
- [ ] Version number correct in pom.xml
- [ ] CHANGELOG.md reviewed
- [ ] CI passes
### 🔄 After Merge
1. **Finalize Release** → tag \`v${version}\` + GitHub release
2. **Deploy to Maven Central** → publish artifacts
`
});
console.log(`✅ Created PR #${pr.number}: ${pr.html_url}`);
const reviewers = ['mikepapadim', 'stratika', 'orionpapadakis'];
try {
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
reviewers: reviewers
});
} catch (e) {
console.log('Could not request reviewers:', e.message);
}
- name: Dry run output
if: ${{ inputs.dry_run == true }}
run: |
echo "🏃 DRY RUN MODE"
echo ""
echo "=== Files changed ==="
git diff --stat
echo ""
echo "=== Changelog entry ==="
cat "${{ runner.temp }}/changelog_entry.txt"