-
Notifications
You must be signed in to change notification settings - Fork 8.5k
chore(NA): introduce new yarn kbn reset command to support bazel workflow #89597
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
Merged
mistic
merged 34 commits into
elastic:master
from
mistic:add-kbn-destroy-cmd-for-bazel-integration
Feb 3, 2021
Merged
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
b89c402
chore(NA): introduce new yarn kbn destroy command to support bazel wo…
mistic 229e602
Merge remote-tracking branch 'upstream/master' into add-kbn-destroy-c…
mistic 4149c35
chore(NA): update wording for new kbn pm changes
mistic 5bc9861
Merge branch 'master' into add-kbn-destroy-cmd-for-bazel-integration
kibanamachine 2a6aebf
Merge branch 'master' into add-kbn-destroy-cmd-for-bazel-integration
kibanamachine 60ad545
Merge branch 'master' into add-kbn-destroy-cmd-for-bazel-integration
kibanamachine 77ed40a
Merge remote-tracking branch 'upstream/master' into add-kbn-destroy-c…
mistic bf74bf8
Merge branch 'master' into add-kbn-destroy-cmd-for-bazel-integration
kibanamachine c62a943
Merge branch 'master' into add-kbn-destroy-cmd-for-bazel-integration
kibanamachine 0ebe848
Merge branch 'master' into add-kbn-destroy-cmd-for-bazel-integration
kibanamachine c830f51
chore(NA): update .bazelrc.common
mistic dafb69f
chore(NA): update .bazelrc
mistic 198ab76
chore(NA): update packages/kbn-pm/src/commands/clean.ts
mistic 8b4b975
chore(NA): update packages/kbn-pm/src/commands/destroy.ts
mistic 6174436
chore(NA): update packages/kbn-pm/src/commands/clean.ts
mistic 19f1413
chore(NA): update packages/kbn-pm/src/commands/destroy.ts
mistic f5ef355
chore(NA): rename destroy command into reset
mistic 12b83f7
Merge remote-tracking branch 'upstream/master' into add-kbn-destroy-c…
mistic 94def68
chore(NA): update packages/kbn-pm/src/commands/clean.ts
mistic 37ba587
chore(NA): restore old behaviour on kbn clean
mistic 5c52143
chore(NA): update reset command to delete bazel caches on disk
mistic 5a46fa8
chore(NA): update packages/kbn-pm/src/commands/clean.ts
mistic 976eb34
chore(NA): update prefix to match bazel defined one for cache settings
mistic 4740d1b
Merge branch 'add-kbn-destroy-cmd-for-bazel-integration' of github.co…
mistic aee3b7f
chore(NA): update kbn pm dist file
mistic a8abd93
chore(NA): merge and solve conflicts with master
mistic 9f844e9
chore(NA): update kbn pm dist
mistic ac98e19
chore(NA): update gitignore
mistic 1354eeb
Merge remote-tracking branch 'upstream/master' into add-kbn-destroy-c…
mistic f8a9ef5
chore(NA): add new ignore files after changed bazel aggregated folder
mistic 3176915
Merge remote-tracking branch 'upstream/master' into add-kbn-destroy-c…
mistic 4f35ee9
Merge branch 'master' into add-kbn-destroy-cmd-for-bazel-integration
kibanamachine 7e0afa2
chore(NA): merging and solve conflicts with master
mistic e27c9bb
Merge branch 'add-kbn-destroy-cmd-for-bazel-integration' of github.co…
mistic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,7 @@ | |
| .idea | ||
| .teamcity | ||
| .yarn-local-mirror | ||
| bazel-cache | ||
| bazel-dist | ||
| /bazel | ||
| build | ||
| node_modules | ||
| target | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,4 +46,4 @@ snapshots.js | |
| /packages/kbn-monaco/src/painless/antlr | ||
|
|
||
| # Bazel | ||
| /bazel-* | ||
| /bazel | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,5 +78,5 @@ report.asciidoc | |
| .yarn-local-mirror | ||
|
|
||
| # Bazel | ||
| /bazel-* | ||
| /bazel | ||
| /.bazelrc.user | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "main": "../target/stdio" | ||
| } |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| /* | ||
| * 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 dedent from 'dedent'; | ||
| import del from 'del'; | ||
| import ora from 'ora'; | ||
| import { join, relative } from 'path'; | ||
|
|
||
| import { getBazelDiskCacheFolder, getBazelRepositoryCacheFolder, runBazel } from '../utils/bazel'; | ||
| import { isDirectory } from '../utils/fs'; | ||
| import { log } from '../utils/log'; | ||
| import { ICommand } from './'; | ||
|
|
||
| export const ResetCommand: ICommand = { | ||
| description: | ||
| 'Deletes node_modules and output directories, resets internal and disk caches, and stops Bazel server', | ||
| name: 'reset', | ||
|
|
||
| async run(projects) { | ||
| log.warning(dedent` | ||
| In most cases, 'yarn kbn clean' is all that should be needed to recover a consistent state when | ||
| problems arise. If you need to use this command, please let us know, as it should not be necessary. | ||
| `); | ||
|
|
||
| const toDelete = []; | ||
| for (const project of projects.values()) { | ||
| if (await isDirectory(project.nodeModulesLocation)) { | ||
| toDelete.push({ | ||
| cwd: project.path, | ||
| pattern: relative(project.path, project.nodeModulesLocation), | ||
| }); | ||
| } | ||
|
|
||
| if (await isDirectory(project.targetLocation)) { | ||
| toDelete.push({ | ||
| cwd: project.path, | ||
| pattern: relative(project.path, project.targetLocation), | ||
| }); | ||
| } | ||
|
|
||
| const { extraPatterns } = project.getCleanConfig(); | ||
| if (extraPatterns) { | ||
| toDelete.push({ | ||
| cwd: project.path, | ||
| pattern: extraPatterns, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Runs Bazel hard clean | ||
| await runBazel(['clean', '--expunge']); | ||
| log.success('Hard cleaned bazel'); | ||
|
|
||
| // Deletes Bazel Cache Folders | ||
| await del([await getBazelDiskCacheFolder(), await getBazelRepositoryCacheFolder()], { | ||
| force: true, | ||
| }); | ||
| log.success('Removed disk caches'); | ||
|
|
||
| if (toDelete.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * In order to avoid patterns like `/build` in packages from accidentally | ||
| * impacting files outside the package we use `process.chdir()` to change | ||
| * the cwd to the package and execute `del()` without the `force` option | ||
| * so it will check that each file being deleted is within the package. | ||
| * | ||
| * `del()` does support a `cwd` option, but it's only for resolving the | ||
| * patterns and does not impact the cwd check. | ||
| */ | ||
| const originalCwd = process.cwd(); | ||
| try { | ||
| for (const { pattern, cwd } of toDelete) { | ||
| process.chdir(cwd); | ||
| const promise = del(pattern); | ||
|
|
||
| if (log.wouldLogLevel('info')) { | ||
| ora.promise(promise, relative(originalCwd, join(cwd, String(pattern)))); | ||
| } | ||
|
|
||
| await promise; | ||
| } | ||
| } finally { | ||
| process.chdir(originalCwd); | ||
| } | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * 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 { dirname, resolve } from 'path'; | ||
| import { spawn } from '../child_process'; | ||
|
|
||
| async function rawRunBazelInfoRepoCache() { | ||
| const { stdout: bazelRepositoryCachePath } = await spawn('bazel', ['info', 'repository_cache'], { | ||
| stdio: 'pipe', | ||
| }); | ||
| return bazelRepositoryCachePath; | ||
| } | ||
|
|
||
| export async function getBazelDiskCacheFolder() { | ||
| return resolve(dirname(await rawRunBazelInfoRepoCache()), 'disk-cache'); | ||
mistic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| export async function getBazelRepositoryCacheFolder() { | ||
| return await rawRunBazelInfoRepoCache(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * 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 chalk from 'chalk'; | ||
| import execa from 'execa'; | ||
| import * as Rx from 'rxjs'; | ||
| import { tap } from 'rxjs/operators'; | ||
| import { observeLines } from '@kbn/dev-utils/stdio'; | ||
| import { spawn } from '../child_process'; | ||
| import { log } from '../log'; | ||
|
|
||
| export async function runBazel(bazelArgs: string[], runOpts: execa.Options = {}) { | ||
| // Force logs to pipe in order to control the output of them | ||
| const bazelOpts: execa.Options = { | ||
| ...runOpts, | ||
| stdio: 'pipe', | ||
| }; | ||
|
|
||
| const bazelProc = spawn('bazel', bazelArgs, bazelOpts); | ||
|
|
||
| const bazelLogs$ = new Rx.Subject<string>(); | ||
|
|
||
| // Bazel outputs machine readable output into stdout and human readable output goes to stderr. | ||
| // Therefore we need to get both. In order to get errors we need to parse the actual text line | ||
| const bazelLogSubscription = Rx.merge( | ||
| observeLines(bazelProc.stdout!).pipe( | ||
| tap((line) => log.info(`${chalk.cyan('[bazel]')} ${line}`)) | ||
| ), | ||
| observeLines(bazelProc.stderr!).pipe( | ||
| tap((line) => log.info(`${chalk.cyan('[bazel]')} ${line}`)) | ||
| ) | ||
| ).subscribe(bazelLogs$); | ||
|
|
||
| // Wait for process and logs to finish, unsubscribing in the end | ||
| await bazelProc; | ||
| await bazelLogs$.toPromise(); | ||
| await bazelLogSubscription.unsubscribe(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.