Skip to content

Commit

Permalink
[8.17] [CI] Prevent console.log in pipeline.ts (#204724) (#205713)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.17`:
- [[CI] Prevent console.log in pipeline.ts
(#204724)](#204724)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Alex
Szabo","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-07T11:42:45Z","message":"[CI]
Prevent console.log in pipeline.ts (#204724)\n\n## Summary\n~Logging to
stdout from this file would result uploading the logged\nstring to
buildkite as a pipeline definition, causing
errors\n(https://buildkite.com/elastic/kibana-pull-request/builds/261721#0193d94b-f05c-41d6-9865-3d3c331a6cc4)~\n\nAdds
an inline eslint rule to warn about `console.log/stdout` usage, as\nthis
has happened before by oversight.\n\nOverlaps with:
https://github.com/elastic/kibana/pull/204672\n\n---------\n\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"ae6d0463192501f4a81ffbe58a85e5c87d9aaca8","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Operations","release_note:skip","v9.0.0","backport:prev-major"],"title":"[CI]
Remove unwanted console.log from
pipeline.ts","number":204724,"url":"https://github.com/elastic/kibana/pull/204724","mergeCommit":{"message":"[CI]
Prevent console.log in pipeline.ts (#204724)\n\n## Summary\n~Logging to
stdout from this file would result uploading the logged\nstring to
buildkite as a pipeline definition, causing
errors\n(https://buildkite.com/elastic/kibana-pull-request/builds/261721#0193d94b-f05c-41d6-9865-3d3c331a6cc4)~\n\nAdds
an inline eslint rule to warn about `console.log/stdout` usage, as\nthis
has happened before by oversight.\n\nOverlaps with:
https://github.com/elastic/kibana/pull/204672\n\n---------\n\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"ae6d0463192501f4a81ffbe58a85e5c87d9aaca8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204724","number":204724,"mergeCommit":{"message":"[CI]
Prevent console.log in pipeline.ts (#204724)\n\n## Summary\n~Logging to
stdout from this file would result uploading the logged\nstring to
buildkite as a pipeline definition, causing
errors\n(https://buildkite.com/elastic/kibana-pull-request/builds/261721#0193d94b-f05c-41d6-9865-3d3c331a6cc4)~\n\nAdds
an inline eslint rule to warn about `console.log/stdout` usage, as\nthis
has happened before by oversight.\n\nOverlaps with:
https://github.com/elastic/kibana/pull/204672\n\n---------\n\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"ae6d0463192501f4a81ffbe58a85e5c87d9aaca8"}}]}]
BACKPORT-->

Co-authored-by: Alex Szabo <[email protected]>
  • Loading branch information
kibanamachine and delanni authored Jan 7, 2025
1 parent b56ed4c commit 6f9ccb4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
13 changes: 13 additions & 0 deletions .buildkite/pipeline-utils/buildkite/emitPipeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export function emitPipeline(pipelineSteps: string[]) {
const pipelineStr = [...new Set(pipelineSteps)].join('\n');
console.log(pipelineStr);
}
1 change: 1 addition & 0 deletions .buildkite/pipeline-utils/buildkite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

export * from './client';
export * from './types';
export * from './emitPipeline';
24 changes: 18 additions & 6 deletions .buildkite/scripts/pipelines/pull_request/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,22 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

/* eslint "no-restricted-syntax": [
"error",
{
"selector": "CallExpression[callee.object.name='console'][callee.property.name!=/^(warn|error)$/]",
"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."
}
] */

import fs from 'fs';
import prConfigs from '../../../pull_requests.json';
import { areChangesSkippable, doAnyChangesMatch, getAgentImageConfig } from '#pipeline-utils';
import {
areChangesSkippable,
doAnyChangesMatch,
getAgentImageConfig,
emitPipeline,
} from '#pipeline-utils';

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

if (skippable) {
console.log(emptyStep);
emitPipeline([emptyStep]);
return;
}

Expand All @@ -44,8 +57,8 @@ const getPipeline = (filename: string, removeSteps = true) => {
const onlyRunQuickChecks = await areChangesSkippable([/^renovate\.json$/], REQUIRED_PATHS);
if (onlyRunQuickChecks) {
pipeline.push(getPipeline('.buildkite/pipelines/pull_request/renovate.yml', false));

console.log([...new Set(pipeline)].join('\n'));
console.warn('Isolated changes to renovate.json. Skipping main PR pipeline.');
emitPipeline(pipeline);
return;
}

Expand Down Expand Up @@ -360,8 +373,7 @@ const getPipeline = (filename: string, removeSteps = true) => {

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

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

0 comments on commit 6f9ccb4

Please sign in to comment.