Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ftr] Speed up FTR code owner check #205093

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/kbn-test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ export { getUrl } from './src/jest/get_url';

export { runCheckJestConfigsCli } from './src/jest/run_check_jest_configs_cli';

export { runCheckFtrCodeOwnersCli } from './src/functional_test_runner/run_check_ftr_code_owners';

export { runJest } from './src/jest/run';

export * from './src/kbn_archiver_cli';
Expand Down
44 changes: 44 additions & 0 deletions packages/kbn-test/src/functional_test_runner/cli/code_owners.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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".
*/

import { run } from '@kbn/dev-cli-runner';
import { createFailError } from '@kbn/dev-cli-errors';
import { getRepoFiles } from '@kbn/get-repo-files';
import { getCodeOwnersEntries } from '@kbn/code-owners';
import ignore from 'ignore';

const TEST_DIRECTORIES = ['test', 'x-pack/test', 'x-pack/test_serverless'];

export async function checkFTRCodeOwnersCLI() {
await run(
async ({ log }) => {
const matcher = ignore().add(getCodeOwnersEntries().map((entry) => entry.pattern));
const hasOwner = (path: string): boolean => matcher.test(path).ignored;

const testFiles = await getRepoFiles(TEST_DIRECTORIES);
const filesWithoutOwner = testFiles
.filter((repoPath) => !hasOwner(repoPath.repoRel))
.map((repoPath) => repoPath.repoRel);

log.info(`Checked ${testFiles.length} test files in ${process.uptime().toFixed(2)}s`);

if (filesWithoutOwner.length === 0) {
log.success(`All test files have a code owner 🥳`);
return;
}

log.write('Test files without a code owner:');
log.write(filesWithoutOwner.map((i) => ` - ${i}`).join('\n'));
throw createFailError(`Found ${filesWithoutOwner.length} test files without code owner`);
},
{
description: 'Check that all test files are covered by GitHub CODEOWNERS',
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { ToolingLog } from '@kbn/tooling-log';
import { getTimeReporter } from '@kbn/ci-stats-reporter';
import exitHook from 'exit-hook';

import { readConfigFile, EsVersion } from './lib';
import { FunctionalTestRunner } from './functional_test_runner';
import { readConfigFile, EsVersion } from '../lib';
import { FunctionalTestRunner } from '../functional_test_runner';

export function runFtrCli() {
const runStartTime = Date.now();
Expand Down
11 changes: 11 additions & 0 deletions packages/kbn-test/src/functional_test_runner/cli/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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 { runFtrCli } from './ftr';
export { checkFTRCodeOwnersCLI } from './code_owners';
2 changes: 1 addition & 1 deletion packages/kbn-test/src/functional_test_runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export {
runCheckFtrConfigsCli,
DedicatedTaskRunner,
} from './lib';
export { runFtrCli } from './cli';
export * from './cli';
export * from './lib/docker_servers';
export * from './public_types';

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/check_ftr_code_owners.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
*/

require('../src/setup_node_env');
require('@kbn/test').runCheckFtrCodeOwnersCli();
void require('@kbn/test').checkFTRCodeOwnersCLI();