-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathci_failure_parser.js
325 lines (306 loc) · 9.09 KB
/
ci_failure_parser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
function unique(arr) {
return Array.from(new Set(arr).values());
}
function pickContext(matches, text, {
index = 0, // which one in the matches should be picked
contextBefore = 0,
contextAfter = 0
}) {
if (index < 0) { index = matches.length + index; }
const match = matches[index];
const offset = text.indexOf(match);
let after = offset + match.length;
for (let i = 0; i < contextAfter; ++i) {
const next = text.indexOf('\n', after + 1);
after = next > 0 ? next : after;
}
let before = offset;
for (let i = 0; i < contextBefore; ++i) {
const next = text.lastIndexOf('\n', before - 1);
before = next > 0 ? next : before;
}
return text.slice(before, after);
}
const BUILD_FAILURE = 'BUILD_FAILURE';
const JS_TEST_FAILURE = 'JS_TEST_FAILURE';
const CC_TEST_FAILURE = 'CC_TEST_FAILURE';
const JENKINS_FAILURE = 'JENKINS_FAILURE';
const GIT_FAILURE = 'GIT_FAILURE';
const NCU_FAILURE = 'NCU_FAILURE';
const RESUME_FAILURE = 'RESUME_FAILURE';
const INFRA_FAILURE = 'INFRA_FAILURE';
const FAILURE_TYPES = {
BUILD_FAILURE, JS_TEST_FAILURE, CC_TEST_FAILURE,
JENKINS_FAILURE, GIT_FAILURE, NCU_FAILURE, RESUME_FAILURE,
INFRA_FAILURE
};
class CIResult {
constructor(ctx, reason) {
this.url = ctx.url || ctx.consoleUIUrl || ctx.jobUrl;
this.builtOn = ctx.builtOn;
this.reason = reason;
// Default: the first line is the highlight, we will slice
// the context to make it so.
// TODO: better highlights
this.highlight = 0;
}
}
// Usually need a fix to the build files
class BuildFailure extends CIResult {
constructor(ctx, reason) {
super(ctx, reason);
this.type = BUILD_FAILURE;
}
}
// Usually needs to fix something in the Jenkins agent (or just restart it)
class InfraFailure extends CIResult {
constructor(ctx, reason) {
super(ctx, reason);
this.type = INFRA_FAILURE;
}
}
// Usually needs a fix in the test or the core
class JSTestFailure extends CIResult {
constructor(ctx, reason) {
super(ctx, reason);
this.type = JS_TEST_FAILURE;
// Example: not ok 749 parallel/test-http-readable-data-event
this.file = this.reason.split('\n')[this.highlight].split(' ').pop();
this.severity = this.reason.match(/^\s+severity: (\w+)/m)[1];
}
}
// Usually needs a fix in the test or the core
class CCTestFailure extends CIResult {
constructor(ctx, reason) {
super(ctx, reason);
this.type = CC_TEST_FAILURE;
}
}
// Usually needs someone to log into the machines and fix it
class JenkinsFailure extends CIResult {
constructor(ctx, reason) {
super(ctx, reason);
this.type = JENKINS_FAILURE;
}
}
// Usually need a fix to the build scripts or in workers
class GitFailure extends CIResult {
constructor(ctx, reason) {
super(ctx, reason);
this.type = GIT_FAILURE;
}
}
// Failures in this tool, we wrap them to avoid exceptions when
// walking the CI
class NCUFailure extends CIResult {
constructor(ctx, reason) {
super(ctx, reason);
this.type = NCU_FAILURE;
}
}
// Refs: https://github.com/nodejs/build/issues/1496
class ResumeFailure extends CIResult {
constructor(ctx, reason) {
super(ctx, reason);
this.type = RESUME_FAILURE;
}
}
function failureMatcher(Failure, patterns, ctx, text) {
for (const pattern of patterns) {
const matches = text.match(pattern.pattern);
if (!matches) {
continue;
}
const reason = pickContext(matches, text, pattern.context).trim();
return [new Failure(ctx, reason)];
}
return null;
}
// The elements are ranked by priority
const FAILURE_FILTERS = [{
// NOTE(mmarchini): infra-related issues should have the highest priority, as
// they can cause other issues to happen.
filter(ctx, text) {
const patterns = [{
pattern: /Read-only file system/g,
context: { index: 0, contextBefore: 1, contextAfter: 0 }
},
{
pattern: /Device or resource busy/g,
context: { index: 0, contextBefore: 1, contextAfter: 0 }
},
{
pattern: /There is not enough space in the file system./g,
context: { index: 0, contextBefore: 1, contextAfter: 0 }
}
];
return failureMatcher(InfraFailure, patterns, ctx, text);
}
}, {
// TODO: match indentation to avoid skipping context with '...'
filter(ctx, text) {
const pattern = /^not ok \d+[\s\S]+? {2}\.\.\.\r?\n/mg;
const matches = text.match(pattern);
if (!matches) {
return null;
}
const nonFlaky = matches.filter((m) => !m.includes('# TODO :'));
if (!nonFlaky.length) {
return null;
}
return unique(nonFlaky).map(
match => new JSTestFailure(ctx, match)
);
}
}, {
filter(ctx, text) {
const patterns = [{
pattern: /\[ {2}FAILED {2}\].+/g,
context: { index: 0, contextBefore: 5, contextAfter: 0 }
}];
return failureMatcher(CCTestFailure, patterns, ctx, text);
}
}, {
// VS compilation error
filter(ctx, text) {
const patterns = [{
pattern: /error C\d+:/mg,
context: { index: 0, contextBefore: 0, contextAfter: 5 }
}];
return failureMatcher(BuildFailure, patterns, ctx, text);
}
}, {
filter(ctx, text) {
const patterns = [{
pattern: /java\.io\.IOException.+/g,
context: { index: -1, contextBefore: 0, contextAfter: 5 }
}, {
pattern: /Build timed out/g,
context: { index: 0, contextBefore: 0, contextAfter: 1 }
}];
return failureMatcher(JenkinsFailure, patterns, ctx, text);
}
}, {
filter(ctx, text) {
const patterns = [{
pattern:
/Changes not staged for commit:[\s\S]+no changes added to commit/mg,
context: { index: 0, contextBefore: 0, contextAfter: 0 }
}, {
pattern:
// eslint-disable-next-line max-len
/error: Your local changes to the following files[\s\S]+Failed to merge in the changes./g,
context: { index: 0, contextBefore: 0, contextAfter: 0 }
}, {
pattern: /warning: failed to remove .+/g,
context: { index: 0, contextBefore: 0, contextAfter: 0 }
}];
return failureMatcher(GitFailure, patterns, ctx, text);
}
}, {
filter(ctx, text) {
const patterns = [{
pattern: /ERROR: Error fetching .+/g,
context: { index: 0, contextBefore: 0, contextAfter: 5 }
}, {
pattern: /hudson\.plugins\.git\.GitException+/g,
context: { index: 0, contextBefore: 0, contextAfter: 5 }
}, {
pattern: /Cannot rebase: .+/g,
context: { index: 0, contextBefore: 0, contextAfter: 1 }
}];
return failureMatcher(GitFailure, patterns, ctx, text);
}
}, {
filter(ctx, text) {
const patterns = [{
pattern: /sh: line /g,
context: { index: 0, contextBefore: 0, contextAfter: 1 }
}, {
pattern: /fatal error:/g,
context: { index: 0, contextBefore: 0, contextAfter: 1 }
}, {
pattern: /dtrace: failed to compile script/g,
context: { index: 0, contextBefore: 0, contextAfter: 1 }
}, {
pattern: /ERROR: .+/g,
// Pick the last one
context: { index: -1, contextBefore: 0, contextAfter: 5 }
}, {
// Pick the first one
pattern: /Error: .+/g,
context: { index: 0, contextBefore: 0, contextAfter: 5 }
}];
return failureMatcher(BuildFailure, patterns, ctx, text);
}
}, {
filter(ctx, text) {
const pattern = /fatal: .+/g;
const matches = text.match(pattern);
if (!matches) {
return null;
}
const reason = unique(matches).join('\n');
return [new BuildFailure(ctx, reason)];
}
}, {
filter(ctx, text) {
const patterns = [{
pattern: /FATAL: .+/g,
context: { index: -1, contextBefore: 0, contextAfter: 5 }
}, {
pattern: /make.*: write error/mg,
context: { index: 0, contextBefore: 0, contextAfter: 3 }
}, {
pattern: /error: .+/g,
context: { index: 0, contextBefore: 0, contextAfter: 5 }
}, {
pattern: /Makefile:.+failed/g,
context: { index: 0, contextBefore: 0, contextAfter: 5 }
}, {
pattern: /make.*: .+ Error \d.*/g,
context: { index: 0, contextBefore: 0, contextAfter: 3 }
}, {
pattern: /warning: failed .+/g,
context: { index: 0, contextBefore: 0, contextAfter: 3 }
}];
return failureMatcher(BuildFailure, patterns, ctx, text);
}
}];
export default class CIFailureParser {
constructor(ctx, text) {
this.ctx = ctx;
this.text = text;
}
parse() {
const text = this.text;
for (const { filter } of FAILURE_FILTERS) {
const result = filter(this.ctx, text);
// TODO: we may want to concat certain types of failures
if (result) {
return result;
}
}
return null;
}
}
CIFailureParser.FAILURE_TYPES = FAILURE_TYPES;
CIFailureParser.FAILURE_CONSTRUCTORS = {
BUILD_FAILURE: BuildFailure,
JENKINS_FAILURE: JenkinsFailure,
JS_TEST_FAILURE: JSTestFailure,
CC_TEST_FAILURE: CCTestFailure,
GIT_FAILURE: GitFailure,
NCU_FAILURE: NCUFailure,
RESUME_FAILURE: ResumeFailure
};
CIFailureParser.CIResult = CIResult;
CIFailureParser.FAILURE_TYPES_NAME = {
BUILD_FAILURE: 'Build Failure',
JENKINS_FAILURE: 'Jenkins Failure',
JS_TEST_FAILURE: 'JSTest Failure',
CC_TEST_FAILURE: 'CCTest Failure',
GIT_FAILURE: 'Git Failure',
NCU_FAILURE: 'node-core-utils failure',
RESUME_FAILURE: 'resume failure'
};