Skip to content

Commit

Permalink
chore(NA): assure bazel bin is available on kbn clean and reset comma…
Browse files Browse the repository at this point in the history
…nds (#91406)
  • Loading branch information
mistic authored Feb 16, 2021
1 parent aa1f024 commit 86e0355
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
26 changes: 17 additions & 9 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48005,6 +48005,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "getBazelRepositoryCacheFolder", function() { return _get_cache_folders__WEBPACK_IMPORTED_MODULE_0__["getBazelRepositoryCacheFolder"]; });

/* harmony import */ var _install_tools__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(373);
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "isBazelBinAvailable", function() { return _install_tools__WEBPACK_IMPORTED_MODULE_1__["isBazelBinAvailable"]; });

/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "installBazelTools", function() { return _install_tools__WEBPACK_IMPORTED_MODULE_1__["installBazelTools"]; });

/* harmony import */ var _run__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(374);
Expand Down Expand Up @@ -48064,6 +48066,7 @@ async function getBazelRepositoryCacheFolder() {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isBazelBinAvailable", function() { return isBazelBinAvailable; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "installBazelTools", function() { return installBazelTools; });
/* harmony import */ var dedent__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
/* harmony import */ var dedent__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(dedent__WEBPACK_IMPORTED_MODULE_0__);
Expand Down Expand Up @@ -54434,8 +54437,10 @@ const CleanCommand = {
} // Runs Bazel soft clean


await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["runBazel"])(['clean']);
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].success('Soft cleaned bazel');
if (await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["isBazelBinAvailable"])()) {
await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["runBazel"])(['clean']);
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].success('Soft cleaned bazel');
}

if (toDelete.length === 0) {
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].success('Nothing to delete');
Expand Down Expand Up @@ -59124,16 +59129,19 @@ const ResetCommand = {
pattern: extraPatterns
});
}
} // Runs Bazel hard clean
} // Runs Bazel hard clean and deletes Bazel Cache Folders


await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["runBazel"])(['clean', '--expunge']);
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].success('Hard cleaned bazel'); // Deletes Bazel Cache Folders
if (await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["isBazelBinAvailable"])()) {
// Hard cleaning bazel
await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["runBazel"])(['clean', '--expunge']);
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].success('Hard cleaned bazel'); // Deletes Bazel Cache Folders

await del__WEBPACK_IMPORTED_MODULE_1___default()([await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["getBazelDiskCacheFolder"])(), await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["getBazelRepositoryCacheFolder"])()], {
force: true
});
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].success('Removed disk caches');
await del__WEBPACK_IMPORTED_MODULE_1___default()([await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["getBazelDiskCacheFolder"])(), await Object(_utils_bazel__WEBPACK_IMPORTED_MODULE_4__["getBazelRepositoryCacheFolder"])()], {
force: true
});
_utils_log__WEBPACK_IMPORTED_MODULE_6__["log"].success('Removed disk caches');
}

if (toDelete.length === 0) {
return;
Expand Down
8 changes: 5 additions & 3 deletions packages/kbn-pm/src/commands/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import del from 'del';
import ora from 'ora';
import { join, relative } from 'path';

import { runBazel } from '../utils/bazel';
import { isBazelBinAvailable, runBazel } from '../utils/bazel';
import { isDirectory } from '../utils/fs';
import { log } from '../utils/log';
import { ICommand } from './';
Expand Down Expand Up @@ -53,8 +53,10 @@ export const CleanCommand: ICommand = {
}

// Runs Bazel soft clean
await runBazel(['clean']);
log.success('Soft cleaned bazel');
if (await isBazelBinAvailable()) {
await runBazel(['clean']);
log.success('Soft cleaned bazel');
}

if (toDelete.length === 0) {
log.success('Nothing to delete');
Expand Down
26 changes: 17 additions & 9 deletions packages/kbn-pm/src/commands/reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import del from 'del';
import ora from 'ora';
import { join, relative } from 'path';

import { getBazelDiskCacheFolder, getBazelRepositoryCacheFolder, runBazel } from '../utils/bazel';
import {
getBazelDiskCacheFolder,
getBazelRepositoryCacheFolder,
isBazelBinAvailable,
runBazel,
} from '../utils/bazel';
import { isDirectory } from '../utils/fs';
import { log } from '../utils/log';
import { ICommand } from './';
Expand Down Expand Up @@ -52,15 +57,18 @@ export const ResetCommand: ICommand = {
}
}

// Runs Bazel hard clean
await runBazel(['clean', '--expunge']);
log.success('Hard cleaned bazel');
// Runs Bazel hard clean and deletes Bazel Cache Folders
if (await isBazelBinAvailable()) {
// Hard cleaning bazel
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');
// Deletes Bazel Cache Folders
await del([await getBazelDiskCacheFolder(), await getBazelRepositoryCacheFolder()], {
force: true,
});
log.success('Removed disk caches');
}

if (toDelete.length === 0) {
return;
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-pm/src/utils/bazel/install_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function readBazelToolsVersionFile(repoRootPath: string, versionFilename:
return version;
}

async function isBazelBinAvailable() {
export async function isBazelBinAvailable() {
try {
await spawn('bazel', ['--version'], { stdio: 'pipe' });

Expand Down

0 comments on commit 86e0355

Please sign in to comment.