Skip to content

Commit a3f8bfd

Browse files
committed
chore: update logic for release note
1 parent fbe1c22 commit a3f8bfd

1 file changed

Lines changed: 31 additions & 39 deletions

File tree

.github/workflows/create-release.yml

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -296,49 +296,41 @@ jobs:
296296
const existingBody = fs.readFileSync('existing_body.md', 'utf8');
297297
const newNotes = `${{ steps.release_notes.outputs.notes }}`;
298298
299-
// Extract native dependency section from existing body
300-
const nativeDepRegex = /### 🛠️ Native Dependency Updates\n\n([\s\S]*?)(?=\n###|\n*$)/;
301-
const existingNativeMatch = existingBody.match(nativeDepRegex);
302-
const newNativeMatch = newNotes.match(nativeDepRegex);
299+
// Regex to extract a single SDK update entry (main bullet + sub-bullets)
300+
// Matches: "- Update {SDK} from X to Y\n" followed by any " - " sub-bullets
301+
const extractSDKSection = (text, sdk) => {
302+
const regex = new RegExp(`- Update ${sdk} SDK from [^\\n]+\\n(?: - [^\\n]+\\n)*`, 'g');
303+
const match = text.match(regex);
304+
return match ? match[0] : null;
305+
};
306+
307+
// Extract Android and iOS sections from both existing and new
308+
const existingAndroid = extractSDKSection(existingBody, 'Android');
309+
const existingIos = extractSDKSection(existingBody, 'iOS');
310+
const newAndroid = extractSDKSection(newNotes, 'Android');
311+
const newIos = extractSDKSection(newNotes, 'iOS');
312+
313+
// Determine what to include (prefer new over existing for same platform)
314+
const finalAndroid = newAndroid || existingAndroid;
315+
const finalIos = newIos || existingIos;
316+
317+
// Build combined native deps section
318+
let combinedDeps = '';
319+
if (finalAndroid) combinedDeps += finalAndroid;
320+
if (finalIos) combinedDeps += finalIos;
303321
304322
let mergedNotes = newNotes;
305323
306-
if (existingNativeMatch && newNativeMatch) {
307-
// Both have native deps - merge them
308-
const existingNativeDeps = existingNativeMatch[1].trim();
309-
const newNativeDeps = newNativeMatch[1].trim();
310-
311-
// Check if existing has Android/iOS that new doesn't have
312-
const existingHasAndroid = existingNativeDeps.includes('Update Android SDK');
313-
const existingHasIos = existingNativeDeps.includes('Update iOS SDK');
314-
const newHasAndroid = newNativeDeps.includes('Update Android SDK');
315-
const newHasIos = newNativeDeps.includes('Update iOS SDK');
316-
317-
let combinedDeps = '';
318-
if (existingHasAndroid && !newHasAndroid) {
319-
// Preserve Android from existing
320-
const androidSection = existingNativeDeps.match(/- Update Android SDK[\s\S]*?(?=- Update iOS|$)/);
321-
if (androidSection) combinedDeps += androidSection[0].trim() + '\n';
324+
if (combinedDeps) {
325+
// Check if new notes already have native deps section
326+
const nativeDepHeaderRegex = /\n*### 🛠️ Native Dependency Updates\n\n[\s\S]*$/;
327+
if (nativeDepHeaderRegex.test(newNotes)) {
328+
// Replace existing section in new notes
329+
mergedNotes = newNotes.replace(nativeDepHeaderRegex, `\n\n### 🛠️ Native Dependency Updates\n\n${combinedDeps}`);
330+
} else {
331+
// Append section to new notes
332+
mergedNotes = newNotes.trimEnd() + `\n\n### 🛠️ Native Dependency Updates\n\n${combinedDeps}`;
322333
}
323-
if (newHasAndroid) {
324-
const androidSection = newNativeDeps.match(/- Update Android SDK[\s\S]*?(?=- Update iOS|$)/);
325-
if (androidSection) combinedDeps += androidSection[0].trim() + '\n';
326-
}
327-
if (existingHasIos && !newHasIos) {
328-
// Preserve iOS from existing
329-
const iosSection = existingNativeDeps.match(/- Update iOS SDK[\s\S]*/);
330-
if (iosSection) combinedDeps += iosSection[0].trim() + '\n';
331-
}
332-
if (newHasIos) {
333-
const iosSection = newNativeDeps.match(/- Update iOS SDK[\s\S]*/);
334-
if (iosSection) combinedDeps += iosSection[0].trim() + '\n';
335-
}
336-
337-
// Replace native deps section in new notes with combined
338-
mergedNotes = newNotes.replace(nativeDepRegex, `### 🛠️ Native Dependency Updates\n\n${combinedDeps}\n`);
339-
} else if (existingNativeMatch && !newNativeMatch) {
340-
// Only existing has native deps - append them to new notes
341-
mergedNotes = newNotes.trimEnd() + '\n\n### 🛠️ Native Dependency Updates\n\n' + existingNativeMatch[1];
342334
}
343335
344336
fs.writeFileSync('release_notes.md', mergedNotes);

0 commit comments

Comments
 (0)