Skip to content

Commit fa3f4c1

Browse files
joyeecheungpriyank-p
authored andcommitted
ci: parse console if all sub builds succeed in a failed build
Also added a few cases of build failure patterns
1 parent 50b0f8e commit fa3f4c1

File tree

2 files changed

+50
-31
lines changed

2 files changed

+50
-31
lines changed

lib/ci/ci_failure_parser.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ const FAILURE_FILTERS = [{
189189
const patterns = [{
190190
pattern: /FATAL: .+/g,
191191
context: { index: -1, contextBefore: 0, contextAfter: 5 }
192-
}, {
193-
pattern: /error: .+/g,
194-
context: { index: 0, contextBefore: 0, contextAfter: 5 }
195192
}, {
196193
pattern: /make.*: write error/mg,
197194
context: { index: 0, contextBefore: 0, contextAfter: 3 }
195+
}, {
196+
pattern: /error: .+/g,
197+
context: { index: 0, contextBefore: 0, contextAfter: 5 }
198198
}, {
199199
pattern: /Makefile:.+failed/g,
200200
context: { index: 0, contextBefore: 0, contextAfter: 5 }
@@ -204,6 +204,15 @@ const FAILURE_FILTERS = [{
204204
}, {
205205
pattern: /warning: failed .+/g,
206206
context: { index: 0, contextBefore: 0, contextAfter: 3 }
207+
}, {
208+
pattern: /Build timed out/g,
209+
context: { index: 0, contextBefore: 0, contextAfter: 1 }
210+
}, {
211+
pattern: /bash: line /g,
212+
context: { index: 0, contextBefore: 0, contextAfter: 1 }
213+
}, {
214+
pattern: /Cannot rebase: You have unstaged changes/g,
215+
context: { index: 0, contextBefore: 0, contextAfter: 1 }
207216
}];
208217
return buildFailureMatcher(patterns, ctx, text);
209218
}

lib/ci/ci_result_parser.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ class Job {
143143
.replace(/\//g, '-')
144144
.replace(/-$/, '');
145145
}
146+
147+
async parseConsoleText() {
148+
const text = await this.getConsoleText();
149+
const parser = new CIFailureParser(this, text);
150+
const results = parser.parse();
151+
152+
if (results) {
153+
this.failures = results;
154+
return results;
155+
}
156+
157+
this.failures = [
158+
new CIResult({ url: this.jobUrl, builtOn: this.builtOn }, 'Unknown')
159+
];
160+
return this.failures;
161+
}
146162
}
147163

148164
const jobCache = new Cache();
@@ -353,10 +369,16 @@ class CommitBuild extends TestBuild {
353369
}
354370

355371
const { result, builds } = this.getBuilds(data);
356-
if (result === SUCCESS || !builds.failed.length) {
372+
373+
if (result !== FAILURE) {
357374
return { result, builds, failures: [] };
358375
}
359376

377+
if (!builds.failed.length) {
378+
const failures = await this.parseConsoleText();
379+
return { result, builds, failures };
380+
}
381+
360382
cli.startSpinner(`Querying failures of ${path}`);
361383
const promises = builds.failed.map(({jobName, buildNumber, url}) => {
362384
if (jobName.includes('fanned')) {
@@ -496,7 +518,13 @@ class FannedBuild extends Job {
496518
];
497519
return this.failures;
498520
}
521+
499522
const failedPhase = data.subBuilds.find(build => build.result === FAILURE);
523+
524+
if (!failedPhase) {
525+
return this.parseConsoleText();
526+
}
527+
500528
if (failedPhase.phaseName !== TEST_PHASE &&
501529
!failedPhase.phaseName.toLowerCase().includes('compilation')) {
502530
this.failures = [
@@ -528,20 +556,8 @@ class LinterBuild extends Job {
528556

529557
async getResults() {
530558
const data = await this.getAPIData();
531-
const builtOn = this.builtOn = data.builtOn;
532-
const text = await this.getConsoleText();
533-
const parser = new CIFailureParser(this, text);
534-
const results = parser.parse();
535-
// TODO: add linter failure type
536-
if (results) {
537-
this.failures = results;
538-
return results;
539-
}
540-
541-
this.failures = [
542-
new CIResult({ url: this.jobUrl, builtOn }, 'Unknown')
543-
];
544-
return this.failures;
559+
this.builtOn = data.builtOn;
560+
return this.parseConsoleText();
545561
}
546562
}
547563

@@ -565,7 +581,7 @@ class NormalBuild extends Job {
565581
return this.failures;
566582
}
567583

568-
if (result === FAILURE && !(runs.length)) {
584+
if (!runs.length) {
569585
this.failures = [
570586
new BuildFailure(
571587
{ url: this.jobUrl, builtOn }, 'Failed to trigger runs'
@@ -575,6 +591,11 @@ class NormalBuild extends Job {
575591
}
576592

577593
const failed = runs.filter(run => run.result === FAILURE);
594+
595+
if (!failed.length) {
596+
return this.parseConsoleText();
597+
}
598+
578599
const tests = failed.map(({ url }) => new TestRun(cli, request, url));
579600

580601
// Skip runs that are not actually triggered by this job
@@ -618,18 +639,7 @@ class TestRun extends Job {
618639
}
619640

620641
async getResults() {
621-
const text = await this.getConsoleText();
622-
const parser = new CIFailureParser(this, text);
623-
const results = parser.parse();
624-
if (results) {
625-
this.failures = results;
626-
return results;
627-
}
628-
629-
this.failures = [
630-
new CIResult({ url: this.jobUrl, builtOn: this.builtOn }, 'Unknown')
631-
];
632-
return this.failures;
642+
return this.parseConsoleText();
633643
}
634644
}
635645

0 commit comments

Comments
 (0)