-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathgenerate-github-release.mjs
More file actions
executable file
·266 lines (232 loc) · 6.99 KB
/
generate-github-release.mjs
File metadata and controls
executable file
·266 lines (232 loc) · 6.99 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
#!/usr/bin/env node
/**
* Generates a unified GitHub release body for a trigger.dev version release.
*
* Usage:
* node scripts/generate-github-release.mjs <version>
*
* Reads:
* - The enhanced changeset release PR body (via RELEASE_PR_BODY env var or stdin).
* By the time this runs, the PR body has already been enhanced by enhance-release-pr.mjs
* to include server changes, deduplication, and categorization. The .server-changes/ files
* themselves are already deleted (consumed on the release branch, same as .changeset/ files).
* - Git log for contributor info
*
* Outputs the formatted GitHub release body to stdout.
*/
import { execSync } from "child_process";
import { readdirSync, readFileSync } from "fs";
import { join } from "path";
const version = process.argv[2];
if (!version) {
console.error("Usage: node scripts/generate-github-release.mjs <version>");
process.exit(1);
}
const ROOT_DIR = join(import.meta.dirname, "..");
// --- Parse the enhanced PR body ---
// The PR body from enhance-release-pr.mjs has sections like:
// ## Highlights
// ## Improvements
// ## Bug fixes
// ## Server changes
// ## Breaking changes
// <details>...</details>
// We extract the content between the first heading and the <details> block.
function extractChangesFromPrBody(body) {
if (!body) return "";
const lines = body.split("\n");
const outputLines = [];
let inDetails = false;
let inSummary = false;
let foundContent = false;
for (const line of lines) {
// Skip the title line (# trigger.dev vX.Y.Z)
if (line.startsWith("# trigger.dev v")) continue;
// Skip the entire Summary section (heading + content until next heading)
if (line.startsWith("## Summary")) {
inSummary = true;
continue;
}
if (inSummary) {
if (line.startsWith("## ")) {
inSummary = false;
} else {
continue;
}
}
// Stop before raw changeset output
if (line.trim() === "<details>") {
inDetails = true;
continue;
}
if (inDetails) continue;
// Collect everything from the first ## heading onward
if (line.startsWith("## ") && !foundContent) {
foundContent = true;
}
if (foundContent) {
outputLines.push(line);
}
}
return outputLines.join("\n").trim();
}
// --- Get contributors from git log ---
function getContributors(previousVersion) {
try {
const range = previousVersion
? `v${previousVersion}...HEAD`
: "HEAD~50..HEAD";
const log = execSync(`git log ${range} --format="%aN|%aE" --no-merges`, {
cwd: ROOT_DIR,
encoding: "utf-8",
});
const contributors = new Map();
for (const line of log.split("\n").filter(Boolean)) {
const [name, email] = line.split("|");
if (!name || email?.endsWith("@users.noreply.github.com")) {
// Try to extract username from noreply email
const match = email?.match(/(\d+\+)?(.+)@users\.noreply\.github\.com/);
if (match) {
const username = match[2];
contributors.set(username, (contributors.get(username) || 0) + 1);
}
continue;
}
contributors.set(name, (contributors.get(name) || 0) + 1);
}
return [...contributors.entries()]
.sort((a, b) => b[1] - a[1])
.map(([name]) => name);
} catch {
return [];
}
}
// --- Get published packages ---
function getPublishedPackages() {
try {
const packagesDir = join(ROOT_DIR, "packages");
const names = [];
for (const dir of readdirSync(packagesDir, { withFileTypes: true })) {
if (!dir.isDirectory()) continue;
try {
const pkg = JSON.parse(
readFileSync(join(packagesDir, dir.name, "package.json"), "utf-8")
);
if (pkg.name && !pkg.private) {
names.push(pkg.name);
}
} catch {
// skip directories without package.json
}
}
return names.sort();
} catch {
return [
"@trigger.dev/build",
"@trigger.dev/core",
"@trigger.dev/react-hooks",
"@trigger.dev/sdk",
"trigger.dev",
];
}
}
function getPreviousVersion(version) {
const parts = version.split(".").map(Number);
if (parts[2] > 0) {
parts[2]--;
} else if (parts[1] > 0) {
parts[1]--;
parts[2] = 0;
} else if (parts[0] > 0) {
parts[0]--;
parts[1] = 0;
parts[2] = 0;
} else {
return null;
}
return parts.join(".");
}
// --- Format the release body ---
function formatRelease({ version, changesContent, contributors, packages }) {
const lines = [];
lines.push(`# trigger.dev v${version}`);
lines.push("");
lines.push("## Upgrade");
lines.push("");
lines.push("```sh");
lines.push("npx trigger.dev@latest update # npm");
lines.push("pnpm dlx trigger.dev@latest update # pnpm");
lines.push("yarn dlx trigger.dev@latest update # yarn");
lines.push("bunx trigger.dev@latest update # bun");
lines.push("```");
lines.push("");
// The Docker image link initially points to the container page without a tag filter.
// After Docker images are built, the update-release job patches this with the exact tag URL.
lines.push(
`Self-hosted Docker image: [\`ghcr.io/triggerdotdev/trigger.dev:v${version}\`](https://github.com/triggerdotdev/trigger.dev/pkgs/container/trigger.dev)`
);
lines.push("");
lines.push("## Release notes");
lines.push("");
lines.push(
`Read the full release notes: https://trigger.dev/changelog/v${version.replace(/\./g, "-")}`
);
lines.push("");
// What's changed — extracted from the enhanced PR body
if (changesContent) {
lines.push("## What's changed");
lines.push("");
lines.push(changesContent);
lines.push("");
}
// Packages
if (packages.length > 0) {
lines.push(`## All packages: v${version}`);
lines.push("");
lines.push(packages.join(", "));
lines.push("");
}
// Contributors
if (contributors.length > 0) {
lines.push("## Contributors");
lines.push("");
lines.push(
contributors
.map((c) => (/^[A-Za-z0-9][-A-Za-z0-9]*$/.test(c) ? `@${c}` : c))
.join(", ")
);
lines.push("");
}
// Comparison link
const prevVersion = getPreviousVersion(version);
if (prevVersion) {
lines.push(
`**Full changelog**: https://github.com/triggerdotdev/trigger.dev/compare/v${prevVersion}...v${version}`
);
}
return lines.join("\n");
}
// --- Main ---
async function main() {
// Read PR body from env or stdin
let prBody = process.env.RELEASE_PR_BODY || "";
if (!prBody && !process.stdin.isTTY) {
const chunks = [];
for await (const chunk of process.stdin) chunks.push(chunk);
prBody = Buffer.concat(chunks).toString("utf-8");
}
const changesContent = extractChangesFromPrBody(prBody);
const contributors = getContributors(getPreviousVersion(version));
const packages = getPublishedPackages();
const body = formatRelease({
version,
changesContent,
contributors,
packages,
});
process.stdout.write(body);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});