Skip to content

Commit ae6d046

Browse files
[CI] Prevent console.log in pipeline.ts (#204724)
## Summary ~Logging to stdout from this file would result uploading the logged string to buildkite as a pipeline definition, causing errors (https://buildkite.com/elastic/kibana-pull-request/builds/261721#0193d94b-f05c-41d6-9865-3d3c331a6cc4)~ Adds an inline eslint rule to warn about `console.log/stdout` usage, as this has happened before by oversight. Overlaps with: #204672 --------- Co-authored-by: kibanamachine <[email protected]>
1 parent 23c28eb commit ae6d046

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
export function emitPipeline(pipelineSteps: string[]) {
11+
const pipelineStr = [...new Set(pipelineSteps)].join('\n');
12+
console.log(pipelineStr);
13+
}

.buildkite/pipeline-utils/buildkite/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99

1010
export * from './client';
1111
export * from './types';
12+
export * from './emitPipeline';

.buildkite/scripts/pipelines/pull_request/pipeline.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,22 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10+
/* eslint "no-restricted-syntax": [
11+
"error",
12+
{
13+
"selector": "CallExpression[callee.object.name='console'][callee.property.name!=/^(warn|error)$/]",
14+
"message": "Debug logging to stdout in this file will attempt to upload the log message as yaml to buildkite, which might result in pipeline syntax error. Use emitPipeline() to upload steps, or log to stderr."
15+
}
16+
] */
17+
1018
import fs from 'fs';
1119
import prConfigs from '../../../pull_requests.json';
12-
import { areChangesSkippable, doAnyChangesMatch, getAgentImageConfig } from '#pipeline-utils';
20+
import {
21+
areChangesSkippable,
22+
doAnyChangesMatch,
23+
getAgentImageConfig,
24+
emitPipeline,
25+
} from '#pipeline-utils';
1326

1427
const prConfig = prConfigs.jobs.find((job) => job.pipelineSlug === 'kibana-pull-request');
1528
const emptyStep = `steps: []`;
@@ -35,7 +48,7 @@ const getPipeline = (filename: string, removeSteps = true) => {
3548
const skippable = await areChangesSkippable(SKIPPABLE_PR_MATCHERS, REQUIRED_PATHS);
3649

3750
if (skippable) {
38-
console.log(emptyStep);
51+
emitPipeline([emptyStep]);
3952
return;
4053
}
4154

@@ -44,8 +57,8 @@ const getPipeline = (filename: string, removeSteps = true) => {
4457
const onlyRunQuickChecks = await areChangesSkippable([/^renovate\.json$/], REQUIRED_PATHS);
4558
if (onlyRunQuickChecks) {
4659
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/renovate.yml', false));
47-
48-
console.log([...new Set(pipeline)].join('\n'));
60+
console.warn('Isolated changes to renovate.json. Skipping main PR pipeline.');
61+
emitPipeline(pipeline);
4962
return;
5063
}
5164

@@ -401,8 +414,7 @@ const getPipeline = (filename: string, removeSteps = true) => {
401414

402415
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/post_build.yml'));
403416

404-
// remove duplicated steps
405-
console.log([...new Set(pipeline)].join('\n'));
417+
emitPipeline(pipeline);
406418
} catch (ex) {
407419
console.error('Error while generating the pipeline steps: ' + ex.message, ex);
408420
process.exit(1);

0 commit comments

Comments
 (0)