Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scripts-update-release-notes): properly handle git for-each-ref cmd call to not fail release notes update #27757

Merged
Merged
Changes from all commits
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
54 changes: 38 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,48 @@ 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);

let tagsAndDates = execSync(cmd, { cwd: process.cwd() })
.toString()
.split(/\r?\n/g)
.map(tag => tag.split(' -- '))
.filter(arr => arr.length === 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!
`);

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

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) {
if (err.code === 'ENOBUFS') {
throw new Error(`maxBuffer ${TEN_MEGABYTES}MB was reached. Increase its size in the codebase`);
}

throw err;
}
}

/**
Expand Down