From 8660d0692eaf8eef85960f7142999ee1e669ff5b Mon Sep 17 00:00:00 2001 From: Christopher Lord Date: Wed, 23 Jun 2021 00:09:23 -0600 Subject: [PATCH] CLI: Add option to skip tests and linting for `grafana-toolkit plugin:build` (#35068) * Add option to skip tests and linting for plugin:build Our plugin has a separate step of CI that tests and lints, so we'd like to be able to control whether the build step will run it too. defaults to continuing with lint and tests. update README for grafana-toolkit * remove accidental duplicate documentation of coverage --- packages/grafana-toolkit/README.md | 2 ++ packages/grafana-toolkit/src/cli/index.ts | 4 ++++ .../grafana-toolkit/src/cli/tasks/plugin.build.ts | 12 ++++++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/grafana-toolkit/README.md b/packages/grafana-toolkit/README.md index aac605e6614..a63160458f2 100644 --- a/packages/grafana-toolkit/README.md +++ b/packages/grafana-toolkit/README.md @@ -104,6 +104,8 @@ This command creates a production-ready build of your plugin. Available options: +- `--skipTest` - Skip running tests as part of build. Useful if you're running the build as part of a larger pipeline. +- `--skipLint` - Skip linting as part of build. Useful if you're running the build as part of a larger pipeline. - `--coverage` - Reports code coverage after the test step of the build. - `--preserveConsole` - Preserves console statements in the code. diff --git a/packages/grafana-toolkit/src/cli/index.ts b/packages/grafana-toolkit/src/cli/index.ts index ec08668a801..5aa698874be 100644 --- a/packages/grafana-toolkit/src/cli/index.ts +++ b/packages/grafana-toolkit/src/cli/index.ts @@ -148,6 +148,8 @@ export const run = (includeInternalScripts = false) => { .command('plugin:build') .option('--maxJestWorkers |', 'Limit number of Jest workers spawned') .option('--coverage', 'Run code coverage', false) + .option('--skipTest', 'Skip running tests (for pipelines that run it separate)', false) + .option('--skipLint', 'Skip running lint (for pipelines that run it separate)', false) .option('--preserveConsole', 'Preserves console calls', false) .description('Prepares plugin dist package') .action(async (cmd) => { @@ -156,6 +158,8 @@ export const run = (includeInternalScripts = false) => { silent: true, maxJestWorkers: cmd.maxJestWorkers, preserveConsole: cmd.preserveConsole, + skipLint: cmd.skipLint, + skipTest: cmd.skipTest, }); }); diff --git a/packages/grafana-toolkit/src/cli/tasks/plugin.build.ts b/packages/grafana-toolkit/src/cli/tasks/plugin.build.ts index 974c1c40ce8..7594bfdf9ab 100644 --- a/packages/grafana-toolkit/src/cli/tasks/plugin.build.ts +++ b/packages/grafana-toolkit/src/cli/tasks/plugin.build.ts @@ -18,6 +18,8 @@ interface PluginBuildOptions { coverage: boolean; maxJestWorkers?: string; preserveConsole?: boolean; + skipTest?: boolean; + skipLint?: boolean; } interface Fixable { @@ -132,11 +134,17 @@ export const pluginBuildRunner: TaskRunner = async ({ coverage, maxJestWorkers, preserveConsole, + skipTest, + skipLint, }) => { await versions(); await prepare(); - await lintPlugin({ fix: false }); - await testPlugin({ updateSnapshot: false, coverage, maxWorkers: maxJestWorkers, watch: false }); + if (!skipLint) { + await lintPlugin({ fix: false }); + } + if (!skipTest) { + await testPlugin({ updateSnapshot: false, coverage, maxWorkers: maxJestWorkers, watch: false }); + } await bundlePlugin({ watch: false, production: true, preserveConsole }); };