Skip to content

Commit 013d85c

Browse files
committed
ci: fallback release changelog generation
1 parent 889e267 commit 013d85c

1 file changed

Lines changed: 45 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,46 @@ jobs:
188188
const baseUrl = process.env.CHANGELOG_API_URL;
189189
const token = process.env.CHANGELOG_API_TOKEN;
190190
191+
function collectChanges() {
192+
const changes = [];
193+
for (const changefile of changefiles) {
194+
const items = Array.isArray(changefile.changes) ? changefile.changes : [];
195+
for (const item of items) {
196+
if (item && item.comment) {
197+
changes.push({
198+
packageName: item.packageName || changefile.packageName || 'VGraph',
199+
comment: String(item.comment).trim(),
200+
type: item.type || 'none',
201+
});
202+
}
203+
}
204+
}
205+
return changes;
206+
}
207+
208+
function formatFallbackBlock(lang) {
209+
const changes = collectChanges();
210+
const heading = `# v${version}`;
211+
const section = lang === 'zh' ? '## 更新内容' : '## Updates';
212+
const emptyMessage =
213+
lang === 'zh'
214+
? '- 发布 VGraph packages。'
215+
: '- Release VGraph packages.';
216+
const lines = changes.length > 0
217+
? changes.map(change => `- ${change.comment}`)
218+
: [emptyMessage];
219+
return `${heading}\n\n${section}\n\n${lines.join('\n')}\n`;
220+
}
221+
222+
function writeFallbackChangelog(reason) {
223+
console.warn(`Use fallback changelog generation: ${reason}`);
224+
fs.mkdirSync('.changelog', { recursive: true });
225+
fs.writeFileSync('.changelog/en.md', formatFallbackBlock('en'), 'utf8');
226+
fs.writeFileSync('.changelog/zh.md', formatFallbackBlock('zh'), 'utf8');
227+
}
228+
191229
function failChangelog(message) {
192-
console.error(message);
193-
process.exit(1);
230+
writeFallbackChangelog(message);
194231
}
195232
196233
function validateBlock(block, lang) {
@@ -201,6 +238,7 @@ jobs:
201238
202239
if (!baseUrl || !token) {
203240
failChangelog('CHANGELOG_API_URL or CHANGELOG_API_TOKEN not configured.');
241+
process.exit(0);
204242
}
205243
206244
const url = new URL('/api/changelog/vgraph/generate', baseUrl);
@@ -249,6 +287,11 @@ jobs:
249287
250288
req.on('error', err => {
251289
failChangelog(`Changelog API request failed: ${err.message || err}`);
290+
process.exit(0);
291+
});
292+
293+
req.setTimeout(15000, () => {
294+
req.destroy(new Error('Changelog API request timed out.'));
252295
});
253296
254297
req.write(body);

0 commit comments

Comments
 (0)