From 6303afa5be224af282a555066d104a15674ec1c4 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 31 Mar 2023 17:20:14 -0700 Subject: [PATCH] Mention infra failures and still report results when they occur --- src/postGithubComments.ts | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/postGithubComments.ts b/src/postGithubComments.ts index 8933b8b..f542f0b 100644 --- a/src/postGithubComments.ts +++ b/src/postGithubComments.ts @@ -21,7 +21,7 @@ let newTscResolvedVersion: string | undefined; let oldTscResolvedVersion: string | undefined; let somethingChanged = false; -let infrastructureFailed = false; +const infrastructureFailures = new Map(); for (const path of metadataFilePaths) { const metadata: Metadata = JSON.parse(fs.readFileSync(path, { encoding: "utf-8" })); @@ -38,21 +38,32 @@ for (const path of metadataFilePaths) { somethingChanged = true; break; default: - infrastructureFailed = true; + infrastructureFailures.set(status, (infrastructureFailures.get(status) ?? 0) + 1) break; } } } -let summary: string; -if (somethingChanged && (isTopReposRun || !infrastructureFailed)) { - summary = `Something interesting changed - please have a look.`; +const summary: string[] = []; + +// In a top-repos run, the test set is arbitrary, so we ignore infrastructure failures +// as it's possible that there's a repo that just doesn't work. +if (!isTopReposRun && infrastructureFailures.size) { + summary.push("There were infrastructure failures potentially unrelated to your change:"); + summary.push(""); + for (const [status, count] of infrastructureFailures) { + summary.push(`- ${count} ${count === 1 ? "instance" : "instances"} of "${status}"`); + } + summary.push(""); + summary.push("Otherwise..."); + summary.push(""); } -else if (infrastructureFailed && !isTopReposRun) { - summary = `Unfortunately, something went wrong, but it probably wasn't caused by your change.`; + +if (somethingChanged) { + summary.push("Something interesting changed - please have a look."); } else { - summary = `Everything looks good!`; + summary.push("Everything looks good!"); } const resultPaths = pu.glob(resultDirPath, `**/*.${resultFileNameSuffix}`).sort((a, b) => path.basename(a).localeCompare(path.basename(b))); @@ -61,7 +72,7 @@ const outputs = resultPaths.map(p => fs.readFileSync(p, { encoding: "utf-8" }).r const suiteDescription = isTopReposRun ? "top-repos" : "user test"; let header = `@${userToTag} Here are the results of running the ${suiteDescription} suite comparing \`${oldTscResolvedVersion}\` and \`${newTscResolvedVersion}\`: -${summary}`; +${summary.join("\n")}`; if (!outputs.length) { git.createComment(+prNumber, +commentNumber, postResult, [header]);