Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion packages/ci/src/lib/run-monorepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
type RunEnv,
checkPrintConfig,
configFromPatterns,
findNewIssues,
hasDefaultPersistFormats,
loadCachedBaseReport,
prepareReportFilesToCompare,
Expand Down Expand Up @@ -251,11 +252,20 @@ async function compareManyProjects(
hasFormats: allProjectsHaveDefaultPersistFormats(projectsToCompare),
});

const projectsNewIssues = env.settings.detectNewIssues
? Object.fromEntries(
await asyncSequential(projectsToCompare, async args => [
args.project.name,
await findNewIssues(args),
]),
)
: {};

return Object.fromEntries(
await Promise.all(
projectsToCompare.map(async args => [
args.project.name,
await saveDiffFiles(args),
await saveDiffFiles(args, projectsNewIssues[args.project.name]),
]),
),
);
Expand Down
32 changes: 22 additions & 10 deletions packages/ci/src/lib/run-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import type {
GitRefs,
Logger,
Options,
OutputFiles,
ProjectRunResult,
ProviderAPIClient,
Settings,
Expand Down Expand Up @@ -201,14 +200,19 @@ export async function compareReports(
args: CompareReportsArgs,
): Promise<ProjectRunResult> {
const { ctx, env, config } = args;
const { logger } = env.settings;
const { settings } = env;
const { logger } = settings;

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

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

return saveDiffFiles(args);
const newIssues = settings.detectNewIssues
? await findNewIssues(args)
: undefined;

return saveDiffFiles(args, newIssues);
}

export async function prepareReportFilesToCompare(
Expand Down Expand Up @@ -264,7 +268,10 @@ export async function prepareReportFilesToCompare(
);
}

export async function saveDiffFiles(args: CompareReportsArgs) {
export async function saveDiffFiles(
args: CompareReportsArgs,
newIssues: SourceFileIssue[] | undefined,
) {
const {
project,
ctx,
Expand All @@ -291,10 +298,8 @@ export async function saveDiffFiles(args: CompareReportsArgs) {
settings,
}),
},
...(settings.detectNewIssues && {
newIssues: await findNewIssues({ ...args, diffFiles }),
}),
};
...(newIssues && { newIssues }),
} satisfies ProjectRunResult;
}

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

export async function findNewIssues(
args: CompareReportsArgs & { diffFiles: OutputFiles },
args: CompareReportsArgs,
): Promise<SourceFileIssue[]> {
const {
base,
currReport,
prevReport,
diffFiles,
config,
ctx,
env: {
git,
settings: { logger },
},
} = args;

const diffFiles = persistedFilesFromConfig(config, {
directory: ctx.directory,
isDiff: true,
});

await git.fetch('origin', base.ref, ['--depth=1']);
const reportsDiff = await readFile(diffFiles.json, 'utf8');
const changedFiles = await listChangedFiles(
{ base: 'FETCH_HEAD', head: 'HEAD' },
git,
);

const issues = filterRelevantIssues({
currReport: JSON.parse(currReport.content) as Report,
prevReport: JSON.parse(prevReport.content) as Report,
Expand Down
Loading
Loading