Skip to content

Commit

Permalink
[8.8] fix(NA): build external plugins with correct bazel artifacts ou…
Browse files Browse the repository at this point in the history
…tput mode (#159630) (#159761)

# Backport

This will backport the following commits from `main` to `8.8`:
- [fix(NA): build external plugins with correct bazel artifacts output
mode (#159630)](#159630)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Tiago
Costa","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-06-14T23:43:05Z","message":"fix(NA):
build external plugins with correct bazel artifacts output mode
(#159630)\n\nCloses #159328
,\r\nhttps://github.com//issues/154325,\r\nhttps://github.com//issues/157440\r\n\r\nThis
PR fixes a problem in the plugin helpers tasks used to build\r\nexternal
plugins. After changes to transpile packages differently in the\r\npast
months a bug was introduced and external plugins were being
built\r\nwith the wrong shared ui deps output mode causing development
form\r\nimports to be bundled and causing problems at page load
time.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"7e067ec47866007051be6afad2a46ab9f8438cb7","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["chore","Team:Operations","release_note:skip","auto-backport","v8.7.2","v8.9.0","v8.8.2"],"number":159630,"url":"https://github.com/elastic/kibana/pull/159630","mergeCommit":{"message":"fix(NA):
build external plugins with correct bazel artifacts output mode
(#159630)\n\nCloses #159328
,\r\nhttps://github.com//issues/154325,\r\nhttps://github.com//issues/157440\r\n\r\nThis
PR fixes a problem in the plugin helpers tasks used to build\r\nexternal
plugins. After changes to transpile packages differently in the\r\npast
months a bug was introduced and external plugins were being
built\r\nwith the wrong shared ui deps output mode causing development
form\r\nimports to be bundled and causing problems at page load
time.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"7e067ec47866007051be6afad2a46ab9f8438cb7"}},"sourceBranch":"main","suggestedTargetBranches":["8.7","8.8"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/159630","number":159630,"mergeCommit":{"message":"fix(NA):
build external plugins with correct bazel artifacts output mode
(#159630)\n\nCloses #159328
,\r\nhttps://github.com//issues/154325,\r\nhttps://github.com//issues/157440\r\n\r\nThis
PR fixes a problem in the plugin helpers tasks used to build\r\nexternal
plugins. After changes to transpile packages differently in the\r\npast
months a bug was introduced and external plugins were being
built\r\nwith the wrong shared ui deps output mode causing development
form\r\nimports to be bundled and causing problems at page load
time.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"7e067ec47866007051be6afad2a46ab9f8438cb7"}},{"branch":"8.8","label":"v8.8.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Tiago Costa <[email protected]>
  • Loading branch information
kibanamachine and mistic authored Jun 15, 2023
1 parent 2088c4d commit 2a02b2a
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-bazel-runner/src/bazel_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async function runBazelRunner(runner, args, options = undefined) {
]),
]);

if (process.env.CI) {
if (process.env.CI && !options?.quiet) {
// on CI it's useful to reduce the logging output, but we still want to see basic info from Bazel so continue to log the INFO: lines from bazel
for (const line of buffer) {
if (line.startsWith('INFO:') && !line.startsWith('INFO: From ')) {
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-plugin-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ Generated plugins receive a handful of scripts that can be used during developme

> ***NOTE:*** The following scripts should be run from the generated plugin root folder.
- `yarn kbn bootstrap`
- `yarn bootstrap`

Install dependencies and crosslink Kibana and all projects/plugins.
Install dependencies both on Kibana and in your plugin.

> ***IMPORTANT:*** Use this script instead of `yarn` to install dependencies when switching branches, and re-run it whenever your dependencies change.
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-plugin-generator/template/package.json.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.0",
"private": true,
"scripts": {
"bootstrap": "yarn kbn bootstrap && yarn install",
"build": "yarn plugin-helpers build",
"dev": "yarn plugin-helpers dev",
"plugin-helpers": "node ../../scripts/plugin_helpers",
Expand Down
2 changes: 2 additions & 0 deletions packages/kbn-plugin-helpers/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function runCli() {
};

await Tasks.initTargets(context);
await Tasks.buildBazelPackages(context);
await Tasks.optimize(context);
await Tasks.writePublicAssets(context);
await Tasks.writeServerFiles(context);
Expand Down Expand Up @@ -160,6 +161,7 @@ export function runCli() {
};

await Tasks.initDev(context);
await Tasks.buildBazelPackages(context);
await Tasks.optimize(context);
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ it('builds a generated plugin into a viable archive', async () => {

expect(filterLogs(buildProc.all)).toMatchInlineSnapshot(`
" info deleting the build and target directories
info run bazel and build required artifacts for the optimizer
succ bazel run successfully and artifacts were created
info running @kbn/optimizer
│ succ browser bundle created at plugins/foo_test_plugin/build/kibana/fooTestPlugin/target/public
│ info stopping @kbn/optimizer
Expand Down
35 changes: 35 additions & 0 deletions packages/kbn-plugin-helpers/src/tasks/bazel_packages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/

import { runBazel } from '@kbn/bazel-runner';
import { TaskContext } from '../task_context';

export async function buildBazelPackages({ log, dist }: TaskContext) {
log.info('run bazel and build required artifacts for the optimizer');

try {
await runBazel(
[
'build',
'//packages/kbn-ui-shared-deps-npm:shared_built_assets',
'//packages/kbn-ui-shared-deps-src:shared_built_assets',
'//packages/kbn-monaco:target_workers',
'--show_result=1',
].concat(dist ? [`--define=dist=true`] : []),
{
logPrefix: ' │ ',
quiet: true,
}
);

log.success('bazel run successfully and artifacts were created');
} catch (e) {
log.error(`bazel run failed: ${e}`);
process.exit(1);
}
}
1 change: 1 addition & 0 deletions packages/kbn-plugin-helpers/src/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

export * from './bazel_packages';
export * from './clean';
export * from './create_archive';
export * from './optimize';
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-plugin-helpers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@kbn/jest-serializers",
"@kbn/repo-packages",
"@kbn/stdio-dev-helpers",
"@kbn/bazel-runner",
],
"exclude": [
"target/**/*",
Expand Down

0 comments on commit 2a02b2a

Please sign in to comment.