[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.
This commit is contained in:
Alex Szabo 2025-03-24 12:01:06 +01:00 committed by GitHub
parent 574e2580c6
commit 415d672d31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 28 deletions

View file

@ -19,7 +19,7 @@ import { CiStatsClient, TestGroupRunOrderResponse } from './client';
import DISABLED_JEST_CONFIGS from '../../disabled_jest_configs.json';
import { serverless, stateful } from '../../ftr_configs_manifests.json';
import { expandAgentQueue } from '#pipeline-utils';
import { collectEnvFromLabels, expandAgentQueue } from '#pipeline-utils';
const ALL_FTR_MANIFEST_REL_PATHS = serverless.concat(stateful);
@ -196,32 +196,6 @@ function getEnabledFtrConfigs(patterns?: string[]) {
}
}
/**
* Collects environment variables from labels on the PR
* TODO: extract this (and other functions from this big file) to a separate module
*/
function collectEnvFromLabels() {
const LABEL_MAPPING: Record<string, Record<string, string>> = {
'ci:use-chrome-beta': {
USE_CHROME_BETA: 'true',
},
};
const envFromlabels: Record<string, string> = {};
if (!process.env.GITHUB_PR_LABELS) {
return envFromlabels;
} else {
const labels = process.env.GITHUB_PR_LABELS.split(',');
labels.forEach((label) => {
const env = LABEL_MAPPING[label];
if (env) {
Object.assign(envFromlabels, env);
}
});
return envFromlabels;
}
}
export async function pickTestGroupRunOrder() {
const bk = new BuildkiteClient();
const ciStats = new CiStatsClient();

View file

@ -13,3 +13,4 @@ export * as CiStats from './ci-stats';
export * from './github';
export * as TestFailures from './test-failures';
export * from './utils';
export * from './pr_labels';

View file

@ -0,0 +1,38 @@
/*
* 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".
*/
/**
* Available auto-mapped label options, respected by 'collectEnvFromLabels' function.
*/
export const LABEL_MAPPING: Record<string, Record<string, string>> = {
'ci:use-chrome-beta': {
USE_CHROME_BETA: 'true', // Use if you want to run tests with Chrome Beta
},
};
/**
* This function reads available GITHUB_LABELS and maps them to environment variables.
*/
export function collectEnvFromLabels(
labels = process.env.GITHUB_PR_LABELS
): Record<string, string> {
const envFromlabels: Record<string, string> = {};
if (labels) {
const labelArray = labels.split(',');
labelArray.forEach((label) => {
const env = LABEL_MAPPING[label];
if (env) {
Object.assign(envFromlabels, env);
}
});
}
return envFromlabels;
}

View file

@ -8,7 +8,7 @@
*/
import { groups } from './groups.json';
import { BuildkiteStep, expandAgentQueue } from '#pipeline-utils';
import { BuildkiteStep, expandAgentQueue, collectEnvFromLabels } from '#pipeline-utils';
const configJson = process.env.KIBANA_FLAKY_TEST_RUNNER_CONFIG;
if (!configJson) {
@ -113,9 +113,11 @@ if (totalJobs > MAX_JOBS) {
}
const steps: BuildkiteStep[] = [];
const envFromLabels = collectEnvFromLabels(process.env.GITHUB_PR_LABELS);
const pipeline = {
env: {
IGNORE_SHIP_CI_STATS_ERROR: 'true',
...envFromLabels,
},
steps,
};