Skip to content

Commit f5f9114

Browse files
committed
fix(ci): prevent parallel git diff when detecting new issues in monorepo
1 parent c0e0176 commit f5f9114

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

packages/ci/src/lib/run-monorepo.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
type RunEnv,
3636
checkPrintConfig,
3737
configFromPatterns,
38+
findNewIssues,
3839
hasDefaultPersistFormats,
3940
loadCachedBaseReport,
4041
prepareReportFilesToCompare,
@@ -251,11 +252,20 @@ async function compareManyProjects(
251252
hasFormats: allProjectsHaveDefaultPersistFormats(projectsToCompare),
252253
});
253254

255+
const projectsNewIssues = env.settings.detectNewIssues
256+
? Object.fromEntries(
257+
await asyncSequential(projectsToCompare, async args => [
258+
args.project.name,
259+
await findNewIssues(args),
260+
]),
261+
)
262+
: {};
263+
254264
return Object.fromEntries(
255265
await Promise.all(
256266
projectsToCompare.map(async args => [
257267
args.project.name,
258-
await saveDiffFiles(args),
268+
await saveDiffFiles(args, projectsNewIssues[args.project.name]),
259269
]),
260270
),
261271
);

packages/ci/src/lib/run-utils.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import type {
3636
GitRefs,
3737
Logger,
3838
Options,
39-
OutputFiles,
4039
ProjectRunResult,
4140
ProviderAPIClient,
4241
Settings,
@@ -201,14 +200,19 @@ export async function compareReports(
201200
args: CompareReportsArgs,
202201
): Promise<ProjectRunResult> {
203202
const { ctx, env, config } = args;
204-
const { logger } = env.settings;
203+
const { settings } = env;
204+
const { logger } = settings;
205205

206206
await prepareReportFilesToCompare(args);
207207
await runCompare(ctx, { hasFormats: hasDefaultPersistFormats(config) });
208208

209209
logger.info('Compared reports and generated diff files');
210210

211-
return saveDiffFiles(args);
211+
const newIssues = settings.detectNewIssues
212+
? await findNewIssues(args)
213+
: undefined;
214+
215+
return saveDiffFiles(args, newIssues);
212216
}
213217

214218
export async function prepareReportFilesToCompare(
@@ -264,7 +268,10 @@ export async function prepareReportFilesToCompare(
264268
);
265269
}
266270

267-
export async function saveDiffFiles(args: CompareReportsArgs) {
271+
export async function saveDiffFiles(
272+
args: CompareReportsArgs,
273+
newIssues: SourceFileIssue[] | undefined,
274+
) {
268275
const {
269276
project,
270277
ctx,
@@ -291,10 +298,8 @@ export async function saveDiffFiles(args: CompareReportsArgs) {
291298
settings,
292299
}),
293300
},
294-
...(settings.detectNewIssues && {
295-
newIssues: await findNewIssues({ ...args, diffFiles }),
296-
}),
297-
};
301+
...(newIssues && { newIssues }),
302+
} satisfies ProjectRunResult;
298303
}
299304

300305
export async function saveReportFiles<T extends 'current' | 'previous'>(args: {
@@ -536,25 +541,32 @@ export function configFromPatterns(
536541
}
537542

538543
export async function findNewIssues(
539-
args: CompareReportsArgs & { diffFiles: OutputFiles },
544+
args: CompareReportsArgs,
540545
): Promise<SourceFileIssue[]> {
541546
const {
542547
base,
543548
currReport,
544549
prevReport,
545-
diffFiles,
550+
config,
551+
ctx,
546552
env: {
547553
git,
548554
settings: { logger },
549555
},
550556
} = args;
551557

558+
const diffFiles = persistedFilesFromConfig(config, {
559+
directory: ctx.directory,
560+
isDiff: true,
561+
});
562+
552563
await git.fetch('origin', base.ref, ['--depth=1']);
553564
const reportsDiff = await readFile(diffFiles.json, 'utf8');
554565
const changedFiles = await listChangedFiles(
555566
{ base: 'FETCH_HEAD', head: 'HEAD' },
556567
git,
557568
);
569+
558570
const issues = filterRelevantIssues({
559571
currReport: JSON.parse(currReport.content) as Report,
560572
prevReport: JSON.parse(prevReport.content) as Report,

0 commit comments

Comments
 (0)