Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions scripts/update-release-notes/changelogsAndTags.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as path from 'path';
import * as fs from 'fs-extra';
import { execSync } from 'child_process';
import * as path from 'path';

import { ChangelogJson } from 'beachball';
import * as fs from 'fs-extra';
import { rollup as lernaAliases } from 'lerna-alias';

import { IChangelogEntry } from './types';

const MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
Expand Down Expand Up @@ -49,28 +51,44 @@ export function getTagToChangelogMap(maxAgeDays?: number): Map<string, IChangelo
* @returns List of tags
*/
export function getTags(maxAgeDays?: number): string[] {
const ONE_MEGABYTE = 1024 * 1000;
const TEN_MEGABYTES = ONE_MEGABYTE * 10;
console.log(`Getting tags${maxAgeDays ? ` up to ${maxAgeDays} days old` : ''}...`);

const cmd = 'git for-each-ref --sort=-creatordate --format="%(refname:short) -- %(creatordate)" refs/tags';
try {
const cmd = 'git for-each-ref --sort=-creatordate --format="%(refname:short) -- %(creatordate)" refs/tags';
const gitForEachRefBuffer = execSync(cmd, {
// execSync buffer is by default 1MB (node 16). Our git refs tog is much bigger than that, thus setting for 10MB
maxBuffer: TEN_MEGABYTES,
});
const currentBufferSize = (gitForEachRefBuffer.byteLength / ONE_MEGABYTE).toFixed(2);

console.warn(`
📣 NOTE: "git for-each-ref" current buffer size is ${currentBufferSize}MB.
If this will be more than maxBuffer ${TEN_MEGABYTES}MB this command will fail and you'll have to increase maxBuffer!
`);

let tagsAndDates = execSync(cmd, { cwd: process.cwd() })
.toString()
.split(/\r?\n/g)
.map(tag => tag.split(' -- '))
.filter(arr => arr.length === 2);
let tagsAndDates = gitForEachRefBuffer
.toString()
.split(/\r?\n/g)
.map(tag => tag.split(' -- '))
.filter(arr => arr.length === 2);

if (maxAgeDays) {
const endIndex = tagsAndDates.findIndex(([, date]) => !_isNewEnough(date, maxAgeDays));
if (endIndex !== -1) {
tagsAndDates = tagsAndDates.slice(0, endIndex);
if (maxAgeDays) {
const endIndex = tagsAndDates.findIndex(([, date]) => !_isNewEnough(date, maxAgeDays));
if (endIndex !== -1) {
tagsAndDates = tagsAndDates.slice(0, endIndex);
}
}
}

const tags = tagsAndDates.map(([tag]) => tag);
const tags = tagsAndDates.map(([tag]) => tag);

console.log(`Found ${tags.length} tag(s).\n`);
console.log(`Found ${tags.length} tag(s).\n`);

return tags;
return tags;
} catch (err) {
Comment thread
Hotell marked this conversation as resolved.
throw new Error(`maxBuffer ${TEN_MEGABYTES}MB was reached. Increase its size in the codebase`);
}
}

/**
Expand Down