|
1
|
name: Draft Release |
|
2
|
|
|
3
|
on: |
|
4
|
workflow_dispatch: |
|
5
|
inputs: |
|
6
|
version: |
|
7
|
description: "Release version (e.g. 2.14.0) — omit to auto-detect from latest published tag" |
|
8
|
required: false |
|
9
|
type: string |
|
10
|
additional_instructions: |
|
11
|
description: "Additional instructions for Claude (e.g. 'Make sure to highlight the new Subscriptions module' or 'The cart breaking change is the most important one')" |
|
12
|
required: false |
|
13
|
type: string |
|
14
|
concurrency: |
|
15
|
group: draft-release |
|
16
|
cancel-in-progress: false |
|
17
|
|
|
18
|
jobs: |
|
19
|
draft-release: |
|
20
|
name: Generate draft release with Claude |
|
21
|
runs-on: ubuntu-latest |
|
22
|
permissions: |
|
23
|
contents: write |
|
24
|
id-token: write |
|
25
|
|
|
26
|
steps: |
|
27
|
- name: Checkout repository |
|
28
|
uses: actions/checkout@v4 |
|
29
|
with: |
|
30
|
fetch-depth: 0 |
|
31
|
|
|
32
|
- name: Generate GitHub App token |
|
33
|
id: app-token |
|
34
|
uses: actions/create-github-app-token@v1 |
|
35
|
with: |
|
36
|
app-id: ${{ secrets.MEDUSA_APP_ID }} |
|
37
|
private-key: ${{ secrets.MEDUSA_APP_PRIVATE_KEY }} |
|
38
|
|
|
39
|
- name: Determine release version and tag |
|
40
|
id: version |
|
41
|
run: | |
|
42
|
git fetch --tags |
|
43
|
|
|
44
|
if [ -n "${{ github.event.inputs.version }}" ]; then |
|
45
|
VERSION="${{ github.event.inputs.version }}" |
|
46
|
else |
|
47
|
# Auto-detect: use the latest stable tag |
|
48
|
VERSION=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -1 | sed 's/^v//') |
|
49
|
fi |
|
50
|
|
|
51
|
TAG="v$VERSION" |
|
52
|
|
|
53
|
# If the tag doesn't exist yet (draft created before publishing), use HEAD as range end |
|
54
|
if git rev-parse "$TAG" >/dev/null 2>&1; then |
|
55
|
RANGE_END="$TAG" |
|
56
|
else |
|
57
|
RANGE_END="HEAD" |
|
58
|
echo "Tag $TAG not found — using HEAD as range end" |
|
59
|
fi |
|
60
|
|
|
61
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
|
62
|
echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
|
63
|
echo "range_end=$RANGE_END" >> "$GITHUB_OUTPUT" |
|
64
|
echo "Resolved release tag: $TAG (range end: $RANGE_END)" |
|
65
|
|
|
66
|
- name: Find previous release tag |
|
67
|
id: previous |
|
68
|
run: | |
|
69
|
TAG="${{ steps.version.outputs.tag }}" |
|
70
|
PREVIOUS_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | grep -v "^${TAG}$" | head -1) |
|
71
|
echo "tag=$PREVIOUS_TAG" >> "$GITHUB_OUTPUT" |
|
72
|
echo "Previous release tag: $PREVIOUS_TAG" |
|
73
|
|
|
74
|
- name: Setup Node.js environment |
|
75
|
uses: actions/setup-node@v4 |
|
76
|
with: |
|
77
|
node-version: 22 |
|
78
|
cache: "yarn" |
|
79
|
# Only the docs-util workspace is installed in this job, so key the |
|
80
|
# cache on its lockfile rather than the repository root's. |
|
81
|
cache-dependency-path: www/utils/yarn.lock |
|
82
|
|
|
83
|
- name: Install release-banner dependencies |
|
84
|
run: yarn install |
|
85
|
working-directory: www/utils |
|
86
|
|
|
87
|
- name: Build release-banner |
|
88
|
run: yarn workspace release-banner build |
|
89
|
working-directory: www/utils |
|
90
|
|
|
91
|
# Runs before the Claude step so a misconfigured upload surfaces early. A |
|
92
|
# missing banner is not worth failing the release over, though, so this only |
|
93
|
# warns — the notes are the deliverable and the banner is decoration. |
|
94
|
- name: Render and upload banner to Cloudinary |
|
95
|
id: banner |
|
96
|
continue-on-error: true |
|
97
|
env: |
|
98
|
CLOUDINARY_URL: ${{ secrets.CLOUDINARY_URL }} |
|
99
|
working-directory: www/utils/packages/release-banner |
|
100
|
run: | |
|
101
|
if [ -z "$CLOUDINARY_URL" ]; then |
|
102
|
echo "::warning::CLOUDINARY_URL is not set — skipping the banner" |
|
103
|
exit 1 |
|
104
|
fi |
|
105
|
|
|
106
|
# Called directly rather than through `yarn upload` so that the only |
|
107
|
# thing captured here is the URL the CLI prints. |
|
108
|
BANNER_URL=$(node dist/cli.js upload \ |
|
109
|
--version "${{ steps.version.outputs.version }}") |
|
110
|
|
|
111
|
echo "url=$BANNER_URL" >> "$GITHUB_OUTPUT" |
|
112
|
echo "Uploaded banner: $BANNER_URL" |
|
113
|
|
|
114
|
- name: Gather commit and PR metadata |
|
115
|
id: commits |
|
116
|
env: |
|
117
|
GH_TOKEN: ${{ steps.app-token.outputs.token }} |
|
118
|
RANGE_END: ${{ steps.version.outputs.range_end }} |
|
119
|
PREVIOUS_TAG: ${{ steps.previous.outputs.tag }} |
|
120
|
REPO: ${{ github.repository }} |
|
121
|
run: | |
|
122
|
echo "Collecting commits between $PREVIOUS_TAG and $RANGE_END..." |
|
123
|
|
|
124
|
# Build JSON array of commits with PR metadata |
|
125
|
node --input-type=module << 'EOF' |
|
126
|
import { execSync } from "child_process" |
|
127
|
import { writeFileSync } from "fs" |
|
128
|
|
|
129
|
const tag = process.env.RANGE_END |
|
130
|
const previousTag = process.env.PREVIOUS_TAG |
|
131
|
const repo = process.env.REPO |
|
132
|
|
|
133
|
// Get raw commit log |
|
134
|
const logOutput = execSync( |
|
135
|
`git log "${previousTag}..${tag}" --pretty=format:'%H|||%s|||%an|||%ae'`, |
|
136
|
{ encoding: "utf8", maxBuffer: 10 * 1024 * 1024 } |
|
137
|
).trim() |
|
138
|
|
|
139
|
if (!logOutput) { |
|
140
|
writeFileSync("/tmp/commits.json", JSON.stringify([])) |
|
141
|
process.exit(0) |
|
142
|
} |
|
143
|
|
|
144
|
const commits = logOutput.split("\n").map((line) => { |
|
145
|
const [hash, subject, author, email] = line.split("|||") |
|
146
|
const prMatch = subject.match(/\(#(\d+)\)/) |
|
147
|
return { |
|
148
|
hash: hash?.trim(), |
|
149
|
subject: subject?.trim(), |
|
150
|
author: author?.trim(), |
|
151
|
email: email?.trim(), |
|
152
|
pr_number: prMatch ? prMatch[1] : null, |
|
153
|
pr_title: null, |
|
154
|
pr_author_login: null, |
|
155
|
pr_labels: [], |
|
156
|
} |
|
157
|
}).filter(c => c.hash) |
|
158
|
|
|
159
|
// Enrich with PR metadata for commits that reference a PR |
|
160
|
for (const commit of commits) { |
|
161
|
if (!commit.pr_number) continue |
|
162
|
try { |
|
163
|
const prData = JSON.parse( |
|
164
|
execSync( |
|
165
|
`gh pr view ${commit.pr_number} --repo ${repo} --json number,title,author,labels`, |
|
166
|
{ encoding: "utf8" } |
|
167
|
) |
|
168
|
) |
|
169
|
commit.pr_title = prData.title |
|
170
|
commit.pr_author_login = prData.author?.login ?? null |
|
171
|
commit.pr_labels = (prData.labels ?? []).map((l) => l.name) |
|
172
|
} catch { |
|
173
|
// PR lookup failed — use commit metadata as fallback |
|
174
|
} |
|
175
|
} |
|
176
|
|
|
177
|
writeFileSync("/tmp/commits.json", JSON.stringify(commits, null, 2)) |
|
178
|
console.log(`Collected ${commits.length} commits`) |
|
179
|
EOF |
|
180
|
|
|
181
|
- name: Detect breaking changes |
|
182
|
id: changesets |
|
183
|
run: | |
|
184
|
RANGE_END="${{ steps.version.outputs.range_end }}" |
|
185
|
PREVIOUS_TAG="${{ steps.previous.outputs.tag }}" |
|
186
|
|
|
187
|
# Method 1: changeset files with a minor bump |
|
188
|
# ("@medusajs/package-name": minor) |
|
189
|
MINOR_CHANGESETS=$( |
|
190
|
git log "${PREVIOUS_TAG}..${RANGE_END}" --diff-filter=A --format="%H" -- ".changeset/*.md" \ |
|
191
|
| while read -r hash; do |
|
192
|
git diff-tree --no-commit-id -r --name-only --diff-filter=A "$hash" -- ".changeset/*.md" \ |
|
193
|
| while read -r file; do |
|
194
|
git show "${hash}:${file}" 2>/dev/null |
|
195
|
done |
|
196
|
done \ |
|
197
|
| grep -c '": minor' || true |
|
198
|
) |
|
199
|
|
|
200
|
# Method 2: PRs labelled "breaking-change" in the commit range |
|
201
|
LABEL_BREAKING=$(node --input-type=module << 'EOF' |
|
202
|
import { readFileSync } from "fs" |
|
203
|
const commits = JSON.parse(readFileSync("/tmp/commits.json", "utf8")) |
|
204
|
const count = commits.filter(c => c.pr_labels?.includes("breaking-change")).length |
|
205
|
process.stdout.write(String(count)) |
|
206
|
EOF |
|
207
|
) |
|
208
|
|
|
209
|
BREAKING_CHANGES=$((MINOR_CHANGESETS + LABEL_BREAKING)) |
|
210
|
|
|
211
|
echo "minor_changesets=$BREAKING_CHANGES" >> "$GITHUB_OUTPUT" |
|
212
|
echo "Breaking changes detected — minor changesets: $MINOR_CHANGESETS, breaking-change label: $LABEL_BREAKING, total: $BREAKING_CHANGES" |
|
213
|
|
|
214
|
- name: Build Claude prompt |
|
215
|
id: prompt |
|
216
|
run: | |
|
217
|
TAG="${{ steps.version.outputs.tag }}" |
|
218
|
PREVIOUS_TAG="${{ steps.previous.outputs.tag }}" |
|
219
|
REPO="${{ github.repository }}" |
|
220
|
MINOR_CHANGESETS="${{ steps.changesets.outputs.minor_changesets }}" |
|
221
|
ADDITIONAL_INSTRUCTIONS="${{ github.event.inputs.additional_instructions }}" |
|
222
|
COMMITS=$(cat /tmp/commits.json) |
|
223
|
|
|
224
|
DELIMITER="CLAUDE_PROMPT_EOF" |
|
225
|
{ |
|
226
|
echo "CLAUDE_PROMPT<<${DELIMITER}" |
|
227
|
cat << PROMPT |
|
228
|
IMPORTANT: Before doing anything else, you MUST read all four skill files below using the Read tool. Do not write a single word of release notes until you have read all of them. |
|
229
|
|
|
230
|
Step 1 — You MUST load the /writing-releases skill and read all its files, especially the SKILL.md which defines the rules, format, structure, and constraints for writing release notes. Then read the reference files that it links to. |
|
231
|
|
|
232
|
Step 2 — Write GitHub release notes for Medusa ${TAG} by strictly following every rule in those files. |
|
233
|
|
|
234
|
IMPORTANT: Only create /tmp/release-notes.md using the Write tool. Do not use git commands. Do not create any other files. |
|
235
|
|
|
236
|
Step 3 — The release notes MUST start with a title and subtitle block, before any other content, in exactly this format (an HTML comment that opens with "<!--" and closes with "CMS_BREAK -->"): |
|
237
|
|
|
238
|
<!-- |
|
239
|
|
|
240
|
# ${TAG}: Short Highlight One, Short Highlight Two, Short Highlight Three |
|
241
|
|
|
242
|
One or two sentences summarizing the most important change in this release and what it enables. |
|
243
|
|
|
244
|
CMS_BREAK --> |
|
245
|
|
|
246
|
Rules for the title and subtitle block: |
|
247
|
- The title line is a level-one heading (a single "#") starting with the release tag "${TAG}", followed by ": ", then two to four of the release's most important highlights in title case, separated by commas. |
|
248
|
- The subtitle is plain prose (no markdown headings, lists, or links) of at most two sentences describing the release's main highlight. |
|
249
|
- Keep the blank lines and the "CMS_BREAK -->" closing line exactly as shown. |
|
250
|
- Everything after "CMS_BREAK -->" is the normal release notes body as defined by the /writing-releases skill. |
|
251
|
|
|
252
|
Context: |
|
253
|
- Repository: ${REPO} |
|
254
|
- Previous release: ${PREVIOUS_TAG} |
|
255
|
- Current release: ${TAG} |
|
256
|
- Number of commits with minor changesets (breaking changes): ${MINOR_CHANGESETS} |
|
257
|
|
|
258
|
The commit and PR metadata is provided below as JSON. Each entry has: |
|
259
|
- hash: commit hash |
|
260
|
- subject: commit message subject |
|
261
|
- author: git author name |
|
262
|
- pr_number: PR number (if any) |
|
263
|
- pr_title: PR title from GitHub (if available) |
|
264
|
- pr_author_login: GitHub username of PR author (if available) |
|
265
|
- pr_labels: labels on the PR |
|
266
|
|
|
267
|
Commits JSON: |
|
268
|
${COMMITS} |
|
269
|
PROMPT |
|
270
|
|
|
271
|
if [ -n "$ADDITIONAL_INSTRUCTIONS" ]; then |
|
272
|
cat << EXTRA |
|
273
|
|
|
274
|
Additional instructions from the release author (apply these when writing, but you MUST still read and follow the skill files from Step 1 — they define the format, structure, and constraints that cannot be overridden): |
|
275
|
${ADDITIONAL_INSTRUCTIONS} |
|
276
|
EXTRA |
|
277
|
fi |
|
278
|
|
|
279
|
cat << PROMPT |
|
280
|
|
|
281
|
Write the complete release notes markdown to /tmp/release-notes.md. |
|
282
|
PROMPT |
|
283
|
echo "${DELIMITER}" |
|
284
|
} >> "$GITHUB_OUTPUT" |
|
285
|
|
|
286
|
- name: Generate release notes with Claude |
|
287
|
uses: anthropics/claude-code-base-action@132be24009ca6f292db66a3d1d5a17249cf68a5d # main, installs Claude Code 2.1.282 |
|
288
|
with: |
|
289
|
anthropic_api_key: ${{ secrets.CLAUDE_CODE_API_TOKEN }} |
|
290
|
claude_args: >- |
|
291
|
--model claude-sonnet-4-6 |
|
292
|
--max-turns 25 |
|
293
|
--allowedTools "Skill,Read,Write,Bash(cat /tmp/commits.json),Bash(git show:*)" |
|
294
|
prompt: ${{ steps.prompt.outputs.CLAUDE_PROMPT }} |
|
295
|
|
|
296
|
- name: Insert banner into the release notes |
|
297
|
if: steps.banner.outputs.url != '' |
|
298
|
env: |
|
299
|
BANNER_URL: ${{ steps.banner.outputs.url }} |
|
300
|
TAG: ${{ steps.version.outputs.tag }} |
|
301
|
run: | |
|
302
|
node --input-type=module << 'EOF' |
|
303
|
import { readFileSync, writeFileSync } from "fs" |
|
304
|
|
|
305
|
const path = "/tmp/release-notes.md" |
|
306
|
const url = process.env.BANNER_URL |
|
307
|
const tag = process.env.TAG |
|
308
|
|
|
309
|
const lines = readFileSync(path, "utf8").split("\n") |
|
310
|
|
|
311
|
// The banner belongs inside the CMS block, above the title heading — |
|
312
|
// it is consumed by the CMS and never rendered on the release page. |
|
313
|
const breakAt = lines.findIndex((line) => |
|
314
|
line.includes("CMS_BREAK -->") |
|
315
|
) |
|
316
|
const headingAt = lines.findIndex((line) => line.startsWith("# ")) |
|
317
|
|
|
318
|
if (headingAt === -1 || breakAt === -1 || headingAt > breakAt) { |
|
319
|
console.log( |
|
320
|
"::warning::Could not find the CMS block's title heading — " + |
|
321
|
"leaving the notes unchanged" |
|
322
|
) |
|
323
|
process.exit(0) |
|
324
|
} |
|
325
|
|
|
326
|
lines.splice(headingAt, 0, ``, "") |
|
327
|
writeFileSync(path, lines.join("\n")) |
|
328
|
|
|
329
|
console.log(`Inserted banner above line ${headingAt + 1}`) |
|
330
|
EOF |
|
331
|
|
|
332
|
- name: Create draft GitHub release |
|
333
|
env: |
|
334
|
GH_TOKEN: ${{ steps.app-token.outputs.token }} |
|
335
|
run: | |
|
336
|
TAG="${{ steps.version.outputs.tag }}" |
|
337
|
PREVIOUS_TAG="${{ steps.previous.outputs.tag }}" |
|
338
|
|
|
339
|
if [ ! -f /tmp/release-notes.md ]; then |
|
340
|
echo "ERROR: /tmp/release-notes.md was not created by Claude" |
|
341
|
exit 1 |
|
342
|
fi |
|
343
|
|
|
344
|
# Use the title from the title/subtitle block Claude generated at the top of the |
|
345
|
# release notes (the first level-one heading), falling back to the tag. |
|
346
|
RELEASE_TITLE=$(grep -m1 '^# ' /tmp/release-notes.md | sed 's/^# *//' || true) |
|
347
|
if [ -z "$RELEASE_TITLE" ]; then |
|
348
|
echo "WARNING: no title heading found in release notes — falling back to $TAG" |
|
349
|
RELEASE_TITLE="$TAG" |
|
350
|
fi |
|
351
|
echo "Release title: $RELEASE_TITLE" |
|
352
|
|
|
353
|
ARGS=( |
|
354
|
"$TAG" |
|
355
|
--title "$RELEASE_TITLE" |
|
356
|
--notes-file /tmp/release-notes.md |
|
357
|
--draft |
|
358
|
--target "${{ github.sha }}" |
|
359
|
) |
|
360
|
|
|
361
|
gh release create "${ARGS[@]}" |
|
362
|
echo "Draft release created for $TAG" |