Skip to content

Commit 1f48d45

Browse files
committed
fix: changeset release now catches server-changes
1 parent e57fd9c commit 1f48d45

1 file changed

Lines changed: 75 additions & 21 deletions

File tree

scripts/enhance-release-pr.mjs

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,28 +183,8 @@ async function getPrForCommit(commitSha) {
183183
// --- Parse .server-changes/ files ---
184184

185185
async function parseServerChanges() {
186-
const dir = join(ROOT_DIR, ".server-changes");
187186
const entries = [];
188-
189-
let files;
190-
try {
191-
files = await fs.readdir(dir);
192-
} catch {
193-
return entries;
194-
}
195-
196-
// Collect file info and look up commits in parallel
197-
const fileData = [];
198-
for (const file of files) {
199-
if (!file.endsWith(".md") || file === "README.md") continue;
200-
201-
const filePath = join(".server-changes", file);
202-
const content = await fs.readFile(join(dir, file), "utf-8");
203-
const parsed = parseFrontmatter(content);
204-
if (!parsed.body.trim()) continue;
205-
206-
fileData.push({ filePath, parsed });
207-
}
187+
const fileData = await getServerChangeFileData();
208188

209189
// Look up commits for all files in parallel
210190
const commits = await Promise.all(fileData.map((f) => getCommitForFile(f.filePath)));
@@ -232,6 +212,80 @@ async function parseServerChanges() {
232212
return entries;
233213
}
234214

215+
async function getServerChangeFileData() {
216+
const liveFileData = await getLiveServerChangeFileData();
217+
if (liveFileData.length > 0) return liveFileData;
218+
219+
// The changesets version command deletes .server-changes before this script
220+
// enhances the release PR body. Recover those consumed files from the release
221+
// branch diff so they still make it into the release notes handoff.
222+
return getDeletedServerChangeFileDataFromReleaseBranch();
223+
}
224+
225+
async function getLiveServerChangeFileData() {
226+
const dir = join(ROOT_DIR, ".server-changes");
227+
228+
let files;
229+
try {
230+
files = await fs.readdir(dir);
231+
} catch {
232+
return [];
233+
}
234+
235+
const fileData = [];
236+
for (const file of files.sort()) {
237+
if (!file.endsWith(".md") || file === "README.md") continue;
238+
239+
const filePath = join(".server-changes", file);
240+
const content = await fs.readFile(join(dir, file), "utf-8");
241+
const parsed = parseFrontmatter(content);
242+
if (!parsed.body.trim()) continue;
243+
244+
fileData.push({ filePath, parsed });
245+
}
246+
247+
return fileData;
248+
}
249+
250+
async function getDeletedServerChangeFileDataFromReleaseBranch() {
251+
const baseRef = process.env.SERVER_CHANGES_BASE_REF || "origin/main";
252+
const releaseRef = process.env.SERVER_CHANGES_RELEASE_REF || "origin/changeset-release/main";
253+
254+
let mergeBase;
255+
let deletedFiles;
256+
try {
257+
mergeBase = await gitExec(["merge-base", baseRef, releaseRef]);
258+
deletedFiles = await gitExec([
259+
"diff",
260+
"--name-only",
261+
"--diff-filter=D",
262+
`${mergeBase}..${releaseRef}`,
263+
"--",
264+
".server-changes",
265+
]);
266+
} catch {
267+
return [];
268+
}
269+
270+
const fileData = [];
271+
for (const filePath of deletedFiles.split("\n").filter(Boolean).sort()) {
272+
const file = filePath.split("/").pop();
273+
if (!file?.endsWith(".md") || file === "README.md") continue;
274+
275+
try {
276+
const content = await gitExec(["show", `${mergeBase}:${filePath}`]);
277+
const parsed = parseFrontmatter(content);
278+
if (!parsed.body.trim()) continue;
279+
fileData.push({ filePath, parsed });
280+
} catch {
281+
// If an individual file cannot be recovered, skip it rather than hiding
282+
// all other server changes.
283+
}
284+
}
285+
286+
return fileData;
287+
}
288+
235289
function parseFrontmatter(content) {
236290
const match = content.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
237291
if (!match) return { frontmatter: {}, body: content };

0 commit comments

Comments
 (0)