From 7df11f4d8475dbf6deefe8fa12df4fea0125b860 Mon Sep 17 00:00:00 2001 From: mikewrighton Date: Thu, 28 Sep 2023 10:15:29 -0400 Subject: [PATCH] build(cdk-build): Include lint commands in build timing info. (#27326) Includes individual lint commands (eslint, pkglint, markdownlint, awslint) in the build timing info emitted by `cdk-build`. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- tools/@aws-cdk/cdk-build-tools/bin/cdk-build.ts | 2 +- tools/@aws-cdk/cdk-build-tools/bin/cdk-lint.ts | 11 +++++++++-- tools/@aws-cdk/cdk-build-tools/lib/lint.ts | 14 +++++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/tools/@aws-cdk/cdk-build-tools/bin/cdk-build.ts b/tools/@aws-cdk/cdk-build-tools/bin/cdk-build.ts index 2a250ac14b810..0507b33126ff2 100644 --- a/tools/@aws-cdk/cdk-build-tools/bin/cdk-build.ts +++ b/tools/@aws-cdk/cdk-build-tools/bin/cdk-build.ts @@ -57,7 +57,7 @@ async function main() { const overrides: CompilerOverrides = { eslint: args.eslint, jsii: args.jsii, tsc: args.tsc }; await compileCurrentPackage(options, timers, overrides); if (!args['skip-lint']) { - await lintCurrentPackage(options, { ...overrides, fix: args.fix }); + await lintCurrentPackage(options, timers, { ...overrides, fix: args.fix }); } if (options.post) { diff --git a/tools/@aws-cdk/cdk-build-tools/bin/cdk-lint.ts b/tools/@aws-cdk/cdk-build-tools/bin/cdk-lint.ts index 25fc45c33944b..5d451b9085b38 100644 --- a/tools/@aws-cdk/cdk-build-tools/bin/cdk-lint.ts +++ b/tools/@aws-cdk/cdk-build-tools/bin/cdk-lint.ts @@ -1,6 +1,7 @@ import * as yargs from 'yargs'; import { lintCurrentPackage } from '../lib/lint'; -import { cdkBuildOptions } from '../lib/package-info'; +import { cdkBuildOptions, currentPackageJson } from '../lib/package-info'; +import { Timers } from '../lib/timer'; async function main() { const args = yargs @@ -19,11 +20,17 @@ async function main() { const options = cdkBuildOptions(); - await lintCurrentPackage(options, { eslint: args.eslint, fix: args.fix }); + await lintCurrentPackage(options, timers, { eslint: args.eslint, fix: args.fix }); } +const timers = new Timers(); +const buildTimer = timers.start('Total time'); + main().catch(e => { process.stderr.write(`${e.toString()}\n`); process.stderr.write('Linting failed.\n'); process.exit(1); +}).finally(() => { + buildTimer.end(); + process.stdout.write(`Lint times for ${currentPackageJson().name}: ${timers.display()}\n`); }); diff --git a/tools/@aws-cdk/cdk-build-tools/lib/lint.ts b/tools/@aws-cdk/cdk-build-tools/lib/lint.ts index b9a174c04eda2..912f3da6cbe9e 100644 --- a/tools/@aws-cdk/cdk-build-tools/lib/lint.ts +++ b/tools/@aws-cdk/cdk-build-tools/lib/lint.ts @@ -3,8 +3,12 @@ import * as process from 'process'; import * as fs from 'fs-extra'; import { shell, escape } from './os'; import { CDKBuildOptions, CompilerOverrides } from './package-info'; +import { Timers } from './timer'; -export async function lintCurrentPackage(options: CDKBuildOptions, compilers: CompilerOverrides & { fix?: boolean } = {}): Promise { +export async function lintCurrentPackage( + options: CDKBuildOptions, + timers: Timers, + compilers: CompilerOverrides & { fix?: boolean } = {}): Promise { const env = options.env; const fixOption = compilers.fix ? ['--fix'] : []; @@ -15,14 +19,14 @@ export async function lintCurrentPackage(options: CDKBuildOptions, compilers: Co '--ext=.ts', `--resolve-plugins-relative-to=${__dirname}`, ...fixOption, - ], { env }); + ], { timers, env }); } if (!options.pkglint?.disable) { await shell([ 'pkglint', ...fixOption, - ], { env }); + ], { timers, env }); } if (await fs.pathExists('README.md')) { @@ -34,8 +38,8 @@ export async function lintCurrentPackage(options: CDKBuildOptions, compilers: Co '--config', path.resolve(__dirname, '..', 'config', 'markdownlint.json'), ...fixOption, 'README.md', - ]); + ], { timers }); } - await shell([path.join(__dirname, '..', 'bin', 'cdk-awslint')], { env }); + await shell([path.join(__dirname, '..', 'bin', 'cdk-awslint')], { timers, env }); }