(opts = {})
| 368 | } |
| 369 | |
| 370 | async parseRunnerLog(opts = {}) { |
| 371 | let { data, name, cloudSpot } = opts; |
| 372 | if (!data) return []; |
| 373 | |
| 374 | data = data.toString('utf8'); |
| 375 | |
| 376 | const parseId = (key) => { |
| 377 | if (patterns[key]) { |
| 378 | const regex = patterns[key]; |
| 379 | const matches = regex.exec(data) || []; |
| 380 | return matches[1]; |
| 381 | } |
| 382 | }; |
| 383 | |
| 384 | const driver = await this.getDriver(); |
| 385 | const logs = []; |
| 386 | const patterns = driver.runnerLogPatterns(); |
| 387 | for (const status of ['ready', 'job_started', 'job_ended']) { |
| 388 | const regex = patterns[status]; |
| 389 | if (regex.test(data)) { |
| 390 | const date = new Date(); |
| 391 | const log = { |
| 392 | status, |
| 393 | date: date.toISOString(), |
| 394 | repo: this.repo |
| 395 | }; |
| 396 | |
| 397 | if (status === 'job_started') { |
| 398 | log.job = parseId('job'); |
| 399 | log.pipeline = parseId('pipeline'); |
| 400 | |
| 401 | // GitHub API doesn’t seem to provide a straightforward way to get the |
| 402 | // job identifier from the runner logs, so we need to query several API |
| 403 | // endpoints to retrieve it. Due to several broken parts of our logic and |
| 404 | // some unexpected API responses, performing these queries may trigger API |
| 405 | // rate limits, causing the whole `cml` process to crash. Given that |
| 406 | // retrieving the job identifier is only useful for spot instance recovery |
| 407 | // (i.e. automated retryWorkflow), we can save ourselves all the hassle if |
| 408 | // —-cloud-spot is not set or —-driver is not GitHub. |
| 409 | if (cloudSpot && this.driver === GITHUB) { |
| 410 | const { id: runnerId } = await this.runnerByName({ name }); |
| 411 | const { id } = await driver.runnerJob({ runnerId }); |
| 412 | log.job = id; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | if (status === 'job_ended') |
| 417 | log.success = patterns.job_ended_succeded.test(data); |
| 418 | |
| 419 | log.level = log.success ? 'info' : 'error'; |
| 420 | logs.push(log); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | return logs; |
| 425 | } |
| 426 | |
| 427 | async startRunner(opts = {}) { |
no test coverage detected