Skip to content

Commit

Permalink
[CI] Add failure count and github issue link to new failed test page (#…
Browse files Browse the repository at this point in the history
…114138) (#114338)

Co-authored-by: Brian Seeders <[email protected]>
  • Loading branch information
kibanamachine and brianseeders committed Oct 7, 2021
1 parent d02fd35 commit c1aa1ef
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/kbn-test/src/failed_tests_reporter/get_failures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type TestFailure = FailedTestCase['$'] & {
failure: string;
likelyIrrelevant: boolean;
'system-out'?: string;
githubIssue?: string;
failureCount?: number;
};

const getText = (node?: Array<string | { _: string }>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,19 @@ export function reportFailuresToFile(log: ToolingLog, failures: TestFailure[]) {
? ` #${parseInt(process.env.BUILDKITE_PARALLEL_JOB, 10) + 1}`
: '';

const buildUrl = process.env.BUILDKITE_BUILD_URL || '';
const jobUrl = process.env.BUILDKITE_JOB_ID
? `${buildUrl}#${process.env.BUILDKITE_JOB_ID}`
: '';

const failureJSON = JSON.stringify(
{
...failure,
hash,
buildId: process.env.BUJILDKITE_BUILD_ID || '',
jobId: process.env.BUILDKITE_JOB_ID || '',
url: process.env.BUILDKITE_BUILD_URL || '',
url: buildUrl,
jobUrl,
jobName: process.env.BUILDKITE_LABEL
? `${process.env.BUILDKITE_LABEL}${jobNumberSuffix}`
: '',
Expand Down Expand Up @@ -128,6 +134,30 @@ export function reportFailuresToFile(log: ToolingLog, failures: TestFailure[]) {
.join('')}
<hr />
<p><strong>${escape(failure.name)}</strong></p>
<p>
<small>
<strong>Failures in tracked branches</strong>: <span class="badge rounded-pill bg-danger">${
failure.failureCount || 0
}</span>
${
failure.githubIssue
? `<br /><a href="${escape(failure.githubIssue)}">${escape(
failure.githubIssue
)}</a>`
: ''
}
</small>
</p>
${
jobUrl
? `<p>
<small>
<strong>Buildkite Job</strong><br />
<a href="${escape(jobUrl)}">${escape(jobUrl)}</a>
</small>
</p>`
: ''
}
<pre>${escape(failure.failure)}</pre>
${screenshotHtml}
<pre>${escape(failure['system-out'] || '')}</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ export function runFailedTestsReporterCli() {
const messages = Array.from(getReportMessageIter(report));
const failures = await getFailures(report);

reportFailuresToFile(log, failures);

if (indexInEs) {
await reportFailuresToEs(log, failures);
}
Expand Down Expand Up @@ -146,6 +144,8 @@ export function runFailedTestsReporterCli() {
branch
);
const url = existingIssue.html_url;
failure.githubIssue = url;
failure.failureCount = updateGithub ? newFailureCount : newFailureCount - 1;
pushMessage(`Test has failed ${newFailureCount - 1} times on tracked branches: ${url}`);
if (updateGithub) {
pushMessage(`Updated existing issue: ${url} (fail count: ${newFailureCount})`);
Expand All @@ -157,8 +157,10 @@ export function runFailedTestsReporterCli() {
pushMessage('Test has not failed recently on tracked branches');
if (updateGithub) {
pushMessage(`Created new issue: ${newIssue.html_url}`);
failure.githubIssue = newIssue.html_url;
}
newlyCreatedIssues.push({ failure, newIssue });
failure.failureCount = updateGithub ? 1 : 0;
}

// mutates report to include messages and writes updated report to disk
Expand All @@ -169,6 +171,8 @@ export function runFailedTestsReporterCli() {
reportPath,
dryRun: !flags['report-update'],
});

reportFailuresToFile(log, failures);
}
},
{
Expand Down

0 comments on commit c1aa1ef

Please sign in to comment.