Skip to content

Commit

Permalink
chore(NA): bazel machinery installation on kbn bootstrap (#89469) (#8…
Browse files Browse the repository at this point in the history
…9521)

* chore(NA): bazel machinery installation on kbn bootstrap

* refact(NA): simplify install logic

* chore(NA): update kbn pm with last changes
  • Loading branch information
mistic authored Jan 28, 2021
1 parent 78d7dca commit 228666c
Show file tree
Hide file tree
Showing 10 changed files with 1,056 additions and 891 deletions.
1 change: 1 addition & 0 deletions .bazeliskversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.7.3
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.0
3 changes: 3 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
workspace(
name = "kibana",
)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@
"@babel/register": "^7.12.10",
"@babel/traverse": "^7.12.12",
"@babel/types": "^7.12.12",
"@bazel/ibazel": "^0.14.0",
"@cypress/snapshot": "^2.1.7",
"@cypress/webpack-preprocessor": "^5.5.0",
"@elastic/apm-rum": "^5.6.1",
Expand Down
1,863 changes: 973 additions & 890 deletions packages/kbn-pm/dist/index.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion packages/kbn-pm/src/commands/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ import { getAllChecksums } from '../utils/project_checksums';
import { BootstrapCacheFile } from '../utils/bootstrap_cache_file';
import { readYarnLock } from '../utils/yarn_lock';
import { validateDependencies } from '../utils/validate_dependencies';
import { installBazelTools } from '../utils/bazel';

export const BootstrapCommand: ICommand = {
description: 'Install dependencies and crosslink projects',
name: 'bootstrap',

async run(projects, projectGraph, { options, kbn }) {
async run(projects, projectGraph, { options, kbn, rootPath }) {
const batchedProjects = topologicallyBatchProjects(projects, projectGraph);
const kibanaProjectPath = projects.get('kibana')?.path;
const extraArgs = [
...(options['frozen-lockfile'] === true ? ['--frozen-lockfile'] : []),
...(options['prefer-offline'] === true ? ['--prefer-offline'] : []),
];

// Install bazel machinery tools if needed
await installBazelTools(rootPath);

// Install monorepo npm dependencies
for (const batch of batchedProjects) {
for (const project of batch) {
const isExternalPlugin = project.path.includes(`${kibanaProjectPath}${sep}plugins`);
Expand Down
9 changes: 9 additions & 0 deletions packages/kbn-pm/src/utils/bazel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

export * from './install_tools';
53 changes: 53 additions & 0 deletions packages/kbn-pm/src/utils/bazel/install_tools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* and the Server Side Public License, v 1; you may not use this file except in
* compliance with, at your election, the Elastic License or the Server Side
* Public License, v 1.
*/

import { resolve } from 'path';
import { spawn } from '../child_process';
import { readFile } from '../fs';
import { log } from '../log';

async function readBazelToolsVersionFile(repoRootPath: string, versionFilename: string) {
const version = (await readFile(resolve(repoRootPath, versionFilename)))
.toString()
.split('\n')[0];

if (!version) {
throw new Error(
`[bazel_tools] Failed on reading bazel tools versions\n ${versionFilename} file do not contain any version set`
);
}

return version;
}

export async function installBazelTools(repoRootPath: string) {
log.debug(`[bazel_tools] reading bazel tools versions from version files`);
const bazeliskVersion = await readBazelToolsVersionFile(repoRootPath, '.bazeliskversion');
const bazelVersion = await readBazelToolsVersionFile(repoRootPath, '.bazelversion');

// Check what globals are installed
log.debug(`[bazel_tools] verify if bazelisk is installed`);
const { stdout } = await spawn('yarn', ['global', 'list'], { stdio: 'pipe' });

// Install bazelisk if not installed
if (!stdout.includes(`@bazel/bazelisk@${bazeliskVersion}`)) {
log.info(`[bazel_tools] installing Bazel tools`);

log.debug(
`[bazel_tools] bazelisk is not installed. Installing @bazel/bazelisk@${bazeliskVersion} and bazel@${bazelVersion}`
);
await spawn('yarn', ['global', 'add', `@bazel/bazelisk@${bazeliskVersion}`], {
env: {
USE_BAZEL_VERSION: bazelVersion,
},
stdio: 'pipe',
});
}

log.success(`[bazel_tools] all bazel tools are correctly installed`);
}
4 changes: 4 additions & 0 deletions src/dev/precommit_hook/casing_check_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export const IGNORE_FILE_GLOBS = [
'x-pack/test/fleet_api_integration/apis/fixtures/test_packages/**/*',

'.teamcity/**/*',

// Bazel default files
'**/WORKSPACE.bazel',
'**/BUILD.bazel',
];

/**
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,11 @@
resolved "https://registry.yarnpkg.com/@base2/pretty-print-object/-/pretty-print-object-1.0.0.tgz#860ce718b0b73f4009e153541faff2cb6b85d047"
integrity sha512-4Th98KlMHr5+JkxfcoDT//6vY8vM+iSPrLNpHhRyLx2CFYi8e2RfqPLdpbnpo0Q5lQC5hNB79yes07zb02fvCw==

"@bazel/ibazel@^0.14.0":
version "0.14.0"
resolved "https://registry.yarnpkg.com/@bazel/ibazel/-/ibazel-0.14.0.tgz#86fa0002bed2ce1123b7ad98d4dd4623a0d93244"
integrity sha512-s0gyec6lArcRDwVfIP6xpY8iEaFpzrSpyErSppd3r2O49pOEg7n6HGS/qJ8ncvme56vrDk6crl/kQ6VAdEO+rg==

"@bcoe/v8-coverage@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
Expand Down

0 comments on commit 228666c

Please sign in to comment.