-
Notifications
You must be signed in to change notification settings - Fork 662
525 lines (440 loc) · 18.3 KB
/
Copy pathrelease.yml
File metadata and controls
525 lines (440 loc) · 18.3 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
name: Release
# Uses GitHub Models API for AI release notes.
# Requires: Repository secret MODELS_TOKEN (PAT with models:read scope)
on:
workflow_dispatch:
inputs:
release_type:
description: Release type to cut
required: true
default: auto
type: choice
options:
- auto
- patch
- minor
- major
prerelease:
description: Mark the GitHub Release as a prerelease
required: true
default: false
type: boolean
use_ai_notes:
description: Use GitHub Models to draft release notes when MODELS_TOKEN is configured
required: true
default: true
type: boolean
pull_request:
types:
- closed
permissions:
contents: write
pull-requests: write
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false
jobs:
propose_release:
name: Propose release
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
fetch-depth: 0
persist-credentials: true
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Resolve base tag and target version
id: version
shell: bash
env:
REQUESTED_RELEASE_TYPE: ${{ inputs.release_type }}
run: |
set -euo pipefail
git fetch --force --tags
stable_tag="$(git tag --merged HEAD --list 'v*' --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1 || true)"
base_tag="$stable_tag"
if [ -z "$base_tag" ]; then
base_tag="$(git tag --merged HEAD --list 'v*' --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.]+)?$' | head -n 1 || true)"
fi
if [ -z "$base_tag" ]; then
base_tag="v0.0.0"
log_range=""
else
log_range="${base_tag}..HEAD"
fi
if [ -n "$log_range" ] && [ -z "$(git log --oneline "$log_range")" ]; then
echo "No commits found since ${base_tag}; skipping duplicate release."
exit 1
fi
release_type="$REQUESTED_RELEASE_TYPE"
if [ "$release_type" = "auto" ]; then
if [ -n "$log_range" ]; then
subjects="$(git log --format=%s "$log_range")"
bodies="$(git log --format=%B "$log_range")"
else
subjects="$(git log --format=%s)"
bodies="$(git log --format=%B)"
fi
if printf '%s\n' "$bodies" | grep -Eq 'BREAKING CHANGE|^[^[:space:]]+(\([^)]+\))?!:'; then
release_type="major"
elif printf '%s\n' "$subjects" | grep -Eq '^feat(\([^)]+\))?:'; then
release_type="minor"
else
release_type="patch"
fi
fi
next_version="$(python - "$base_tag" "$release_type" <<'PY'
import re
import sys
base_tag, release_type = sys.argv[1], sys.argv[2]
match = re.match(r"^v?(\d+)\.(\d+)\.(\d+)", base_tag)
if not match:
major, minor, patch = 0, 0, 0
else:
major, minor, patch = map(int, match.groups())
if release_type == "major":
major += 1
minor = 0
patch = 0
elif release_type == "minor":
minor += 1
patch = 0
else:
patch += 1
print(f"{major}.{minor}.{patch}")
PY
)"
tag_name="v${next_version}"
if git rev-parse "$tag_name" >/dev/null 2>&1; then
echo "Tag ${tag_name} already exists."
exit 1
fi
{
echo "base_tag=$base_tag"
echo "release_type=$release_type"
echo "version=$next_version"
echo "tag=$tag_name"
echo "log_range=$log_range"
} >> "$GITHUB_OUTPUT"
echo "Base tag: $base_tag"
echo "Release type: $release_type"
echo "Next version: $next_version"
- name: Collect release context
shell: bash
env:
BASE_TAG: ${{ steps.version.outputs.base_tag }}
TARGET_VERSION: ${{ steps.version.outputs.version }}
TARGET_TAG: ${{ steps.version.outputs.tag }}
RELEASE_TYPE: ${{ steps.version.outputs.release_type }}
LOG_RANGE: ${{ steps.version.outputs.log_range }}
SOURCE_REF: ${{ github.ref_name }}
run: |
set -euo pipefail
mkdir -p .github/release-artifacts
if [ -n "$LOG_RANGE" ]; then
git log --no-merges --pretty=format:'- %s (%h)' "$LOG_RANGE" > .github/release-artifacts/commit-bullets.txt
git log --no-merges --pretty=format:'%H%x09%s' "$LOG_RANGE" > .github/release-artifacts/commit-table.tsv
else
git log --no-merges --pretty=format:'- %s (%h)' > .github/release-artifacts/commit-bullets.txt
git log --no-merges --pretty=format:'%H%x09%s' > .github/release-artifacts/commit-table.tsv
fi
python <<'PY'
from pathlib import Path
import os
base_tag = os.environ["BASE_TAG"]
target_version = os.environ["TARGET_VERSION"]
target_tag = os.environ["TARGET_TAG"]
release_type = os.environ["RELEASE_TYPE"]
notes_path = Path("RELEASE_NOTES.md")
existing = notes_path.read_text(encoding="utf-8") if notes_path.exists() else ""
style_excerpt = "\n".join(existing.splitlines()[:120]).strip()
commit_bullets = Path(".github/release-artifacts/commit-bullets.txt").read_text(encoding="utf-8").strip()
# Limit commit bullets to fit within API token limits
lines = commit_bullets.splitlines()
if len(lines) > 100:
lines = lines[:100] + [f"- ... and {len(lines) - 100} more commits"]
commit_summary = "\n".join(lines)
prompt = f"""You are writing Clawith release notes in markdown.
Based on the provided commit history, analyze the changes between the previous version ({base_tag}) and the new target version ({target_tag}), and write comprehensive release notes in Markdown.
Structure of the Release Notes:
1. Title: Start with a top-level heading exactly formatted as: # {target_tag} — <Concise title summarizing the main theme of this release>
2. ## What's New:
- Group related changes into thematic subheadings (e.g., ### Core Features, ### UI/UX Enhancements, ### Optimizations).
- Sort subheadings and items within each group by importance: major features first, then enhancements, then minor tweaks.
- Specifically list all newly added features and optimization items. Explain what value they add.
3. ## Bug Fixes:
- List resolved bugs, issues, or stability improvements.
4. ## Upgrade Guide:
- Provide standard deployment instructions for upgrading to this version (e.g., rebuilding frontend, restart commands for Docker/Source/Kubernetes).
- Do NOT include manual database migration commands (such as `alembic upgrade heads`), as database migrations run automatically on application startup.
- Mimic the exact formatting, sections, and command blocks shown in the Style Reference below (excluding any manual database migration steps).
5. ## Notes:
- Add any deployment warnings, dependency updates, or configuration warnings.
Writing Style Rules:
- Keep the tone concise, professional, and product-focused.
- Prefer grouping related commits and summarizing the feature/improvement instead of listing every commit verbatim.
- Do NOT invent or hallucinate any features or fixes that are not present or strongly implied in the commit list.
- Keep the language clean and consistent with previous release notes.
- IMPORTANT: Within each section (What's New, Bug Fixes, etc.), sort items by impact and importance in descending order. New core features and major enhancements come first, followed by smaller improvements. Bug fixes that affect stability or data integrity come before minor UI tweaks.
Style Reference (Mimic this structure and formatting):
---
{style_excerpt}
---
Context:
- Previous Release Tag: {base_tag}
- Target Release Tag (Target Version): {target_tag}
- Release Type: {release_type}
- Source Branch: {os.environ["SOURCE_REF"]}
Commits included in this release:
{commit_summary or "- No commits collected"}
"""
Path(".github/release-artifacts/release-prompt.txt").write_text(prompt, encoding="utf-8")
PY
- name: Update version files
shell: bash
env:
TARGET_VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
printf '%s\n' "$TARGET_VERSION" > backend/VERSION
printf '%s\n' "$TARGET_VERSION" > frontend/VERSION
- name: Draft release notes with GitHub Models
if: ${{ inputs.use_ai_notes }}
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.MODELS_TOKEN }}
run: |
set -euo pipefail
python <<'PY'
from pathlib import Path
import json
prompt = Path(".github/release-artifacts/release-prompt.txt").read_text(encoding="utf-8")
payload = {
"model": "openai/gpt-4.1",
"messages": [
{
"role": "system",
"content": "You write concise, accurate release notes in markdown."
},
{
"role": "user",
"content": prompt
}
]
}
Path(".github/release-artifacts/openai-payload.json").write_text(
json.dumps(payload, ensure_ascii=False),
encoding="utf-8",
)
PY
status_code=$(
curl -sS -L \
-o .github/release-artifacts/openai-response.json \
-w "%{http_code}" \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2026-03-10" \
-H "Content-Type: application/json" \
https://models.github.ai/inference/chat/completions \
-d @.github/release-artifacts/openai-payload.json
)
echo "HTTP status: $status_code"
cat .github/release-artifacts/openai-response.json
test "$status_code" -lt 400
python <<'PY'
from pathlib import Path
import json
response = json.loads(Path(".github/release-artifacts/openai-response.json").read_text(encoding="utf-8"))
text = response.get("choices", [{}])[0].get("message", {}).get("content", "").strip()
if not text:
raise SystemExit("GitHub Models did not return release note text.")
Path(".github/release-artifacts/release-notes.generated.md").write_text(
text.rstrip() + "\n",
encoding="utf-8",
)
PY
- name: Build fallback release notes
shell: bash
env:
BASE_TAG: ${{ steps.version.outputs.base_tag }}
TARGET_VERSION: ${{ steps.version.outputs.version }}
TARGET_TAG: ${{ steps.version.outputs.tag }}
SOURCE_REF: ${{ github.ref_name }}
run: |
set -euo pipefail
if [ -s .github/release-artifacts/release-notes.generated.md ]; then
exit 0
fi
python <<'PY'
from pathlib import Path
import os
base_tag = os.environ["BASE_TAG"]
target_version = os.environ["TARGET_VERSION"]
target_tag = os.environ["TARGET_TAG"]
source_ref = os.environ["SOURCE_REF"]
entries = []
for line in Path(".github/release-artifacts/commit-table.tsv").read_text(encoding="utf-8").splitlines():
if not line.strip():
continue
_, subject = line.split("\t", 1)
entries.append(subject.strip())
features = []
fixes = []
others = []
for subject in entries:
lowered = subject.lower()
if lowered.startswith("feat"):
features.append(subject)
elif lowered.startswith("fix"):
fixes.append(subject)
else:
others.append(subject)
def bullets(items):
return "\n".join(f"- {item}" for item in items[:8]) or "- No user-facing highlights captured from commit subjects."
sections = [
f"# {target_tag} — Release Highlights",
"",
"## What's New",
bullets(features or others),
]
if fixes:
sections.extend([
"",
"## Bug Fixes",
bullets(fixes),
])
sections.extend([
"",
"## Upgrade Guide",
"",
"### Docker Deployment",
"```bash",
f"git pull origin {source_ref}",
"docker compose down && docker compose up -d --build",
"```",
"",
"### Source Deployment",
"```bash",
f"git pull origin {source_ref}",
"cd frontend && npm install && npm run build",
"cd ..",
"```",
"",
"## Notes",
f"- Release generated from changes since `{base_tag}`.",
f"- Runtime version files were updated to `{target_version}`.",
])
Path(".github/release-artifacts/release-notes.generated.md").write_text(
"\n".join(sections).rstrip() + "\n",
encoding="utf-8",
)
PY
- name: Refresh RELEASE_NOTES.md
shell: bash
run: |
set -euo pipefail
python <<'PY'
from pathlib import Path
notes_file = Path(".github/release-artifacts/release-notes.generated.md")
release_notes_path = Path("RELEASE_NOTES.md")
new_block = notes_file.read_text(encoding="utf-8").strip()
existing = release_notes_path.read_text(encoding="utf-8").strip() if release_notes_path.exists() else ""
if existing:
combined = f"{new_block}\n\n---\n\n{existing}\n"
else:
combined = f"{new_block}\n"
release_notes_path.write_text(combined, encoding="utf-8")
PY
- name: Commit release metadata
shell: bash
env:
TARGET_TAG: ${{ steps.version.outputs.tag }}
run: |
set -euo pipefail
git add backend/VERSION frontend/VERSION RELEASE_NOTES.md
if git diff --cached --quiet; then
echo "No release metadata changes to commit."
exit 0
fi
git checkout -b "release/${TARGET_TAG}"
git commit -m "chore(release): cut ${TARGET_TAG}"
git push origin "release/${TARGET_TAG}"
- name: Create Pull Request
shell: bash
env:
TARGET_TAG: ${{ steps.version.outputs.tag }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
release_notes=""
if [ -s .github/release-artifacts/release-notes.generated.md ]; then
release_notes="$(cat .github/release-artifacts/release-notes.generated.md)"
fi
gh pr create \
--title "chore(release): cut ${TARGET_TAG}" \
--body "$(cat <<EOF
Automated release PR for ${TARGET_TAG}. Merging this PR will automatically tag the release and publish it.
---
${release_notes}
EOF
)" \
--head "release/${TARGET_TAG}" \
--base "${{ github.ref_name }}"
publish_release:
name: Publish release
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' && github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/v')
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
fetch-depth: 0
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Extract Release Info
id: release_info
shell: bash
run: |
set -euo pipefail
branch_name="${{ github.event.pull_request.head.ref }}"
tag_name="${branch_name#release/}"
python - "$tag_name" <<'PY'
from pathlib import Path
import sys
tag_name = sys.argv[1]
notes_path = Path("RELEASE_NOTES.md")
if not notes_path.exists():
Path("release-notes.extracted.md").write_text(f"# {tag_name}\n\nRelease cut via merge.", encoding="utf-8")
sys.exit(0)
content = notes_path.read_text(encoding="utf-8")
parts = content.split("\n\n---\n\n")
latest_notes = parts[0].strip()
Path("release-notes.extracted.md").write_text(latest_notes + "\n", encoding="utf-8")
PY
echo "tag=$tag_name" >> "$GITHUB_OUTPUT"
- name: Create and push tag
shell: bash
env:
TARGET_TAG: ${{ steps.release_info.outputs.tag }}
run: |
set -euo pipefail
git tag -a "$TARGET_TAG" -m "Release $TARGET_TAG"
git push origin "$TARGET_TAG"
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release_info.outputs.tag }}
name: ${{ steps.release_info.outputs.tag }}
body_path: release-notes.extracted.md
prerelease: ${{ github.event.pull_request.draft }}
generate_release_notes: false