Skip to content

Commit 415d672

Browse files
authored
[ci] Flaky test runner respect labels (#215167)
## Summary Extracts `collectEnvFromLabels` to a separate module, so it can be used in the flaky test runner. With this, the label `ci:use-chrome-beta` will be passed along to the flaky test runner, allowing for flaky testing on chrome beta. Other labels we treat as modifiers for PR behavior through setting env variables should also be added to this set of mapping.
1 parent 574e258 commit 415d672

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

.buildkite/pipeline-utils/ci-stats/pick_test_group_run_order.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { CiStatsClient, TestGroupRunOrderResponse } from './client';
1919

2020
import DISABLED_JEST_CONFIGS from '../../disabled_jest_configs.json';
2121
import { serverless, stateful } from '../../ftr_configs_manifests.json';
22-
import { expandAgentQueue } from '#pipeline-utils';
22+
import { collectEnvFromLabels, expandAgentQueue } from '#pipeline-utils';
2323

2424
const ALL_FTR_MANIFEST_REL_PATHS = serverless.concat(stateful);
2525

@@ -196,32 +196,6 @@ function getEnabledFtrConfigs(patterns?: string[]) {
196196
}
197197
}
198198

199-
/**
200-
* Collects environment variables from labels on the PR
201-
* TODO: extract this (and other functions from this big file) to a separate module
202-
*/
203-
function collectEnvFromLabels() {
204-
const LABEL_MAPPING: Record<string, Record<string, string>> = {
205-
'ci:use-chrome-beta': {
206-
USE_CHROME_BETA: 'true',
207-
},
208-
};
209-
210-
const envFromlabels: Record<string, string> = {};
211-
if (!process.env.GITHUB_PR_LABELS) {
212-
return envFromlabels;
213-
} else {
214-
const labels = process.env.GITHUB_PR_LABELS.split(',');
215-
labels.forEach((label) => {
216-
const env = LABEL_MAPPING[label];
217-
if (env) {
218-
Object.assign(envFromlabels, env);
219-
}
220-
});
221-
return envFromlabels;
222-
}
223-
}
224-
225199
export async function pickTestGroupRunOrder() {
226200
const bk = new BuildkiteClient();
227201
const ciStats = new CiStatsClient();

.buildkite/pipeline-utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export * as CiStats from './ci-stats';
1313
export * from './github';
1414
export * as TestFailures from './test-failures';
1515
export * from './utils';
16+
export * from './pr_labels';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
/**
11+
* Available auto-mapped label options, respected by 'collectEnvFromLabels' function.
12+
*/
13+
export const LABEL_MAPPING: Record<string, Record<string, string>> = {
14+
'ci:use-chrome-beta': {
15+
USE_CHROME_BETA: 'true', // Use if you want to run tests with Chrome Beta
16+
},
17+
};
18+
19+
/**
20+
* This function reads available GITHUB_LABELS and maps them to environment variables.
21+
*/
22+
export function collectEnvFromLabels(
23+
labels = process.env.GITHUB_PR_LABELS
24+
): Record<string, string> {
25+
const envFromlabels: Record<string, string> = {};
26+
27+
if (labels) {
28+
const labelArray = labels.split(',');
29+
labelArray.forEach((label) => {
30+
const env = LABEL_MAPPING[label];
31+
if (env) {
32+
Object.assign(envFromlabels, env);
33+
}
34+
});
35+
}
36+
37+
return envFromlabels;
38+
}

.buildkite/pipelines/flaky_tests/pipeline.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import { groups } from './groups.json';
11-
import { BuildkiteStep, expandAgentQueue } from '#pipeline-utils';
11+
import { BuildkiteStep, expandAgentQueue, collectEnvFromLabels } from '#pipeline-utils';
1212

1313
const configJson = process.env.KIBANA_FLAKY_TEST_RUNNER_CONFIG;
1414
if (!configJson) {
@@ -113,9 +113,11 @@ if (totalJobs > MAX_JOBS) {
113113
}
114114

115115
const steps: BuildkiteStep[] = [];
116+
const envFromLabels = collectEnvFromLabels(process.env.GITHUB_PR_LABELS);
116117
const pipeline = {
117118
env: {
118119
IGNORE_SHIP_CI_STATS_ERROR: 'true',
120+
...envFromLabels,
119121
},
120122
steps,
121123
};

0 commit comments

Comments
 (0)