Cleanup x-pack build (#136980)

This commit is contained in:
Jonathan Budzenski 2022-07-22 15:44:42 -05:00 committed by GitHub
parent 812dce0e72
commit 22dc8c0739
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 6 additions and 169 deletions

View file

@ -677,7 +677,6 @@
"@types/express": "^4.17.13",
"@types/extract-zip": "^1.6.2",
"@types/faker": "^5.1.5",
"@types/fancy-log": "^1.3.1",
"@types/fetch-mock": "^7.3.1",
"@types/file-saver": "^2.0.0",
"@types/flot": "^0.0.31",
@ -1070,7 +1069,6 @@
"expect": "^28.1.1",
"expose-loader": "^0.7.5",
"faker": "^5.1.0",
"fancy-log": "^1.3.2",
"fetch-mock": "^7.3.9",
"file-loader": "^4.2.0",
"form-data": "^4.0.0",

View file

@ -13,18 +13,12 @@ import { pipeline } from 'stream';
import { discoverBazelPackages } from '@kbn/bazel-packages';
import { REPO_ROOT } from '@kbn/utils';
import { transformFileStream, transformFileWithBabel } from '@kbn/dev-utils';
import { ToolingLog } from '@kbn/tooling-log';
import gulp from 'gulp';
import del from 'del';
import fancyLog from 'fancy-log';
import chalk from 'chalk';
import vfs from 'vinyl-fs';
import { generateNoticeFromSource } from '../../src/dev/notice';
import { gitInfo } from './helpers/git_info';
import { PKG_NAME } from './helpers/pkg';
import { BUILD_VERSION } from './helpers/build_version';
const asyncPipeline = promisify(pipeline);
@ -33,29 +27,21 @@ const BUILD_DIR = resolve(XPACK_DIR, 'build');
const PLUGIN_BUILD_DIR = resolve(BUILD_DIR, 'plugin/kibana/x-pack');
async function cleanBuildTask() {
fancyLog('Deleting', BUILD_DIR);
const log = new ToolingLog();
log.info('Deleting', BUILD_DIR);
await del(BUILD_DIR);
fancyLog('[canvas] Deleting Shareable Runtime');
log.info('[canvas] Deleting Shareable Runtime');
await del(resolve(XPACK_DIR, 'plugins/canvas/shareable_runtime/build'));
}
async function reportTask() {
const info = await gitInfo();
fancyLog('Package Name', chalk.yellow(PKG_NAME));
fancyLog('Version', chalk.yellow(BUILD_VERSION));
fancyLog('Build Number', chalk.yellow(`${info.number}`));
fancyLog('Build SHA', chalk.yellow(info.sha));
}
async function copySourceAndBabelify() {
async function copySource() {
// get bazel packages inside x-pack
const xpackBazelPackages = (await discoverBazelPackages())
.filter((pkg) => pkg.normalizedRepoRelativeDir.startsWith('x-pack/'))
.map((pkg) => `${pkg.normalizedRepoRelativeDir.replace('x-pack/', '')}/**`);
// copy source files and apply some babel transformations in the process
// copy source files
await asyncPipeline(
vfs.src(
[
@ -99,12 +85,6 @@ async function copySourceAndBabelify() {
}
),
transformFileStream(async (file) => {
if (['.js', '.ts', '.tsx'].includes(file.extname)) {
await transformFileWithBabel(file);
}
}),
vfs.dest(PLUGIN_BUILD_DIR)
);
}
@ -140,8 +120,7 @@ async function generateNoticeText() {
export const buildTask = gulp.series(
cleanBuildTask,
reportTask,
buildCanvasShareableRuntime,
copySourceAndBabelify,
copySource,
generateNoticeText
);

View file

@ -1,13 +0,0 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { PKG_VERSION } from './pkg';
import { FLAGS } from './flags';
const snapshotText = FLAGS.release ? '' : '-SNAPSHOT';
const qualifierText = FLAGS.buildQualifier ? '-' + FLAGS.buildQualifier : '';
export const BUILD_VERSION = `${PKG_VERSION}${qualifierText}${snapshotText}`;

View file

@ -1,50 +0,0 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import log from 'fancy-log';
import getopts from 'getopts';
/*
Usage:
Specifying which plugins to run tests can be done with the --plugins flag.
One of more plugins can be specified, and each one should be command separated, like so:
gulp testserver --plugins monitoring,reporting
If using with yarn:
yarn test:mocha --plugins graph
*/
const opts = Object.freeze(
getopts(process.argv.slice(2), {
alias: {
release: 'r',
},
boolean: ['release', 'flags'],
string: ['build-qualifier', 'plugins'],
})
);
if (opts.flags) {
log(`
X-Pack Gulpfile Flags:
--flags Print this message
--plugins Comma-separated list of plugins
--release, -r Build to a release version
--build-qualifier Qualifier to include in the build version
`);
process.exit(0);
}
export const FLAGS = {
release: !!opts.release,
buildQualifier: opts.buildQualifier as string | undefined,
plugins: opts.plugins
? String(opts.plugins)
.split(',')
.map((id) => id.trim())
: undefined,
};

View file

@ -1,38 +0,0 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import fs from 'fs';
import path from 'path';
// @ts-ignore barely used, untyped module
import simpleGit from 'simple-git';
const gitDir = path.resolve(__dirname, '..', '..');
export async function gitInfo() {
if (!fs.existsSync(path.join(gitDir, '.git'))) {
// This info is only used for debugging purposes in the log
// So if .git is not available for some reason, it's fine to output this
return {
number: 1,
sha: process.env.GIT_COMMIT || process.env.BUILDKITE_COMMIT || 'none',
};
}
const git = simpleGit(gitDir);
return new Promise<{ number: number; sha: string }>((resolve, reject) => {
git.log((err: undefined | Error, log: { total: number; latest: { hash: string } }) => {
if (err) {
reject(err);
} else {
resolve({
number: log.total,
sha: log.latest.hash,
});
}
});
});
}

View file

@ -1,34 +0,0 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import Fs from 'fs';
import semverValid from 'semver/functions/valid';
interface PackageJson {
name: string;
version: string;
dependencies: Record<string, string>;
devDependencies: Record<string, string>;
[key: string]: unknown;
}
const PKG_PATH = require.resolve('../../package.json');
export const PKG: PackageJson = JSON.parse(Fs.readFileSync(PKG_PATH, 'utf8'));
export const PKG_VERSION = PKG.version;
export const PKG_NAME = PKG.name;
if (!PKG_VERSION) {
throw new Error('No "version" found in package.json');
}
if (!PKG_NAME) {
throw new Error('No "name" found in package.json');
}
if (!semverValid(PKG_VERSION)) {
throw new Error(`Version is not valid semver: ${PKG_VERSION}`);
}

View file

@ -6285,11 +6285,6 @@
resolved "https://registry.yarnpkg.com/@types/faker/-/faker-5.1.5.tgz#f14b015e0100232bb00c6dd7611505efb08709a0"
integrity sha512-2uEQFb7bsx68rqD4F8q95wZq6LTLOyexjv6BnvJogCO4jStkyc6IDEkODPQcWfovI6g6M3uPQ2/uD/oedJKkNw==
"@types/fancy-log@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@types/fancy-log/-/fancy-log-1.3.1.tgz#dd94fbc8c2e2ab8ab402ca8d04bb8c34965f0696"
integrity sha512-31Dt9JaGfHretvwVxCBrCFL5iC9MQ3zOXpu+8C4qzW0cxc5rJJVGxB5c/vZ+wmeTk/JjPz/D0gv8BZ+Ip6iCqQ==
"@types/fetch-mock@^7.3.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@types/fetch-mock/-/fetch-mock-7.3.1.tgz#df7421e8bcb351b430bfbfa5c52bb353826ac94f"