Skip to content

Commit b6c9f4b

Browse files
Spencerkibanamachine
andauthored
[ftr] rework ciGroup validation to remove JOBS.yml and avoid duplication (#109149) (#109324)
Co-authored-by: spalger <spalger@users.noreply.github.com> # Conflicts: # .ci/jobs.yml # test/scripts/jenkins_code_coverage.sh Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent f047b20 commit b6c9f4b

File tree

15 files changed

+100
-115
lines changed

15 files changed

+100
-115
lines changed

.ci/ci_groups.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
root:
2+
- ciGroup1
3+
- ciGroup2
4+
- ciGroup3
5+
- ciGroup4
6+
- ciGroup5
7+
- ciGroup6
8+
- ciGroup7
9+
- ciGroup8
10+
- ciGroup9
11+
- ciGroup10
12+
- ciGroup11
13+
- ciGroup12
14+
15+
xpack:
16+
- ciGroup1
17+
- ciGroup2
18+
- ciGroup3
19+
- ciGroup4
20+
- ciGroup5
21+
- ciGroup6
22+
- ciGroup7
23+
- ciGroup8
24+
- ciGroup9
25+
- ciGroup10
26+
- ciGroup11
27+
- ciGroup12
28+
- ciGroup13
29+
- ciGroupDocker

.ci/jobs.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/kbn-test/src/functional_test_runner/lib/config/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const defaultRelativeToConfigPath = (path: string) => {
7171

7272
export const schema = Joi.object()
7373
.keys({
74+
rootTags: Joi.array().items(Joi.string()),
7475
testFiles: Joi.array().items(Joi.string()),
7576
testRunner: Joi.func(),
7677

packages/kbn-test/src/functional_test_runner/lib/mocha/decorate_mocha_ui.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function split(arr, fn) {
2121
return [a, b];
2222
}
2323

24-
export function decorateMochaUi(log, lifecycle, context, { isDockerGroup }) {
24+
export function decorateMochaUi(log, lifecycle, context, { isDockerGroup, rootTags }) {
2525
// incremented at the start of each suite, decremented after
2626
// so that in each non-suite call we can know if we are within
2727
// a suite, or that when a suite is defined it is within a suite
@@ -62,7 +62,13 @@ export function decorateMochaUi(log, lifecycle, context, { isDockerGroup }) {
6262
});
6363

6464
const relativeFilePath = relative(REPO_ROOT, this.file);
65-
this._tags = isDockerGroup ? ['ciGroupDocker', relativeFilePath] : [relativeFilePath];
65+
this._tags = [
66+
...(isDockerGroup ? ['ciGroupDocker', relativeFilePath] : [relativeFilePath]),
67+
// we attach the "root tags" to all the child suites of the root suite, so that if they
68+
// need to be excluded they can be removed from the root suite without removing the entire
69+
// root suite
70+
...(this.parent.root ? [...(rootTags ?? [])] : []),
71+
];
6672
this.suiteTag = relativeFilePath; // The tag that uniquely targets this suite/file
6773
this.tags = (tags) => {
6874
const newTags = Array.isArray(tags) ? tags : [tags];

packages/kbn-test/src/functional_test_runner/lib/mocha/load_test_files.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const loadTestFiles = ({
6262

6363
const context = decorateMochaUi(log, lifecycle, global, {
6464
isDockerGroup,
65+
rootTags: config.get('rootTags'),
6566
});
6667
mocha.suite.emit('pre-require', context, path, mocha);
6768

packages/kbn-test/src/functional_tests/lib/run_ftr.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export async function assertNoneExcluded({ configPath, options }) {
5252
throw new CliError(`
5353
${stats.excludedTests.length} tests in the ${configPath} config
5454
are excluded when filtering by the tags run on CI. Make sure that all suites are
55-
tagged with one of the following tags, or extend the list of tags in test/scripts/jenkins_xpack.sh
55+
tagged with one of the following tags:
5656
57-
tags: ${JSON.stringify(options.suiteTags)}
57+
${JSON.stringify(options.suiteTags)}
5858
5959
- ${stats.excludedTests.join('\n - ')}
6060
`);

packages/kbn-test/src/functional_tests/tasks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const makeSuccessMessage = (options) => {
5555
* @property {string} options.esFrom Optionally run from source instead of snapshot
5656
*/
5757
export async function runTests(options) {
58-
if (!process.env.KBN_NP_PLUGINS_BUILT) {
58+
if (!process.env.KBN_NP_PLUGINS_BUILT && !options.assertNoneExcluded) {
5959
const log = options.createLogger();
6060
log.warning('❗️❗️❗️');
6161
log.warning('❗️❗️❗️');

scripts/ensure_all_tests_in_ci_group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
*/
88

99
require('../src/setup_node_env');
10-
require('../src/dev/run_ensure_all_tests_in_ci_group');
10+
require('../src/dev/ensure_all_tests_in_ci_group').runEnsureAllTestsInCiGroupsCli();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import Path from 'path';
10+
import Fs from 'fs/promises';
11+
12+
import execa from 'execa';
13+
import { safeLoad } from 'js-yaml';
14+
15+
import { run, REPO_ROOT } from '@kbn/dev-utils';
16+
import { schema } from '@kbn/config-schema';
17+
18+
const RELATIVE_JOBS_YAML_PATH = '.ci/ci_groups.yml';
19+
const JOBS_YAML_PATH = Path.resolve(REPO_ROOT, RELATIVE_JOBS_YAML_PATH);
20+
const SCHEMA = schema.object({
21+
root: schema.arrayOf(schema.string()),
22+
xpack: schema.arrayOf(schema.string()),
23+
});
24+
25+
export function runEnsureAllTestsInCiGroupsCli() {
26+
run(async ({ log }) => {
27+
const { root, xpack } = SCHEMA.validate(safeLoad(await Fs.readFile(JOBS_YAML_PATH, 'utf-8')));
28+
29+
log.info(
30+
'validating root tests directory contains all "root" ciGroups from',
31+
RELATIVE_JOBS_YAML_PATH
32+
);
33+
await execa(process.execPath, [
34+
'scripts/functional_tests',
35+
...root.map((tag) => `--include-tag=${tag}`),
36+
'--include-tag=runOutsideOfCiGroups',
37+
'--assert-none-excluded',
38+
]);
39+
40+
log.info(
41+
'validating x-pack/tests directory contains all "xpack" ciGroups from',
42+
RELATIVE_JOBS_YAML_PATH
43+
);
44+
await execa(process.execPath, [
45+
'x-pack/scripts/functional_tests',
46+
...xpack.map((tag) => `--include-tag=${tag}`),
47+
'--assert-none-excluded',
48+
]);
49+
50+
log.success('all tests are in a valid ciGroup');
51+
});
52+
}

src/dev/run_ensure_all_tests_in_ci_group.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)