From e688f13535cce0f58fb7d755235977756f56cdf5 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Thu, 5 Mar 2020 06:06:06 -0800 Subject: [PATCH] Toolkit: plugin ci needs to cooperate better with make/mage (#22588) * cleanup * cleanup --- packages/grafana-toolkit/src/cli/index.ts | 12 ++---- .../grafana-toolkit/src/cli/tasks/manifest.ts | 13 +++++-- .../src/cli/tasks/plugin.ci.ts | 38 +++++++------------ 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/packages/grafana-toolkit/src/cli/index.ts b/packages/grafana-toolkit/src/cli/index.ts index 3bad754e436..e26915c8829 100644 --- a/packages/grafana-toolkit/src/cli/index.ts +++ b/packages/grafana-toolkit/src/cli/index.ts @@ -168,15 +168,11 @@ export const run = (includeInternalScripts = false) => { program .command('plugin:ci-build') - .option('--backend', 'Run Makefile for backend task', false) + .option('--finish', 'move all results to the jobs folder', false) .description('Build the plugin, leaving results in /dist and /coverage') .action(async cmd => { - if (typeof cmd === 'string') { - console.error(`Invalid argument: ${cmd}\nSee --help for a list of available commands.`); - process.exit(1); - } await execTask(ciBuildPluginTask)({ - backend: cmd.backend, + finish: cmd.finish, }); }); @@ -199,9 +195,7 @@ export const run = (includeInternalScripts = false) => { .option('--full', 'run all the tests (even stuff that will break)') .description('end-to-end test using bundle in /artifacts') .action(async cmd => { - await execTask(ciTestPluginTask)({ - full: cmd.full, - }); + await execTask(ciTestPluginTask)({}); }); program diff --git a/packages/grafana-toolkit/src/cli/tasks/manifest.ts b/packages/grafana-toolkit/src/cli/tasks/manifest.ts index bf82f748c1a..89dfe38f124 100644 --- a/packages/grafana-toolkit/src/cli/tasks/manifest.ts +++ b/packages/grafana-toolkit/src/cli/tasks/manifest.ts @@ -31,13 +31,18 @@ const manifestRunner: TaskRunner = async ({ folder }) => { const originalDir = __dirname; process.chdir(folder); - const out = await execa('sha1sum', files); + const { stdout } = await execa('sha1sum', files); // Write the process output - fs.writeFileSync(path.join(folder, filename), out.stdout); + fs.writeFileSync(path.join(folder, filename), stdout); - // TODO: - // gpg --output doc.sig --sign doc + // Call a signing service + const GRAFANA_API_KEY = process.env.GRAFANA_API_KEY; + if (GRAFANA_API_KEY) { + const plugin = require('plugin.json'); + const url = `https://grafana.com/api/plugins/${plugin.id}/sign`; + console.log(`TODO: sign and save: ${url}`); + } // Go back to where you were process.chdir(originalDir); diff --git a/packages/grafana-toolkit/src/cli/tasks/plugin.ci.ts b/packages/grafana-toolkit/src/cli/tasks/plugin.ci.ts index 982f2124aae..076fca90391 100644 --- a/packages/grafana-toolkit/src/cli/tasks/plugin.ci.ts +++ b/packages/grafana-toolkit/src/cli/tasks/plugin.ci.ts @@ -30,8 +30,7 @@ import { promisify } from 'util'; const rimraf = promisify(rimrafCallback); export interface PluginCIOptions { - backend?: boolean; - full?: boolean; + finish?: boolean; upload?: boolean; } @@ -46,35 +45,26 @@ export interface PluginCIOptions { * Anything that should be put into the final zip file should be put in: * ~/ci/jobs/build_xxx/dist */ -const buildPluginRunner: TaskRunner = async ({ backend }) => { +const buildPluginRunner: TaskRunner = async ({ finish }) => { const start = Date.now(); - const workDir = getJobFolder(); - await rimraf(`${process.cwd()}/dist`); - await rimraf(workDir); - fs.mkdirSync(workDir); + if (finish) { + const workDir = getJobFolder(); + await rimraf(workDir); + fs.mkdirSync(workDir); - if (backend) { - const makefile = path.resolve(process.cwd(), 'Makefile'); - if (!fs.existsSync(makefile)) { - throw new Error(`Missing: ${makefile}. A Makefile is required for backend plugins.`); + // Move local folders to the scoped job folder + for (const name of ['dist', 'coverage']) { + const dir = path.resolve(process.cwd(), name); + if (fs.existsSync(dir)) { + fs.renameSync(dir, path.resolve(workDir, name)); + } } - - // Run plugin-ci task - execa('make', ['backend-plugin-ci']).stdout!.pipe(process.stdout); + writeJobStats(start, workDir); } else { // Do regular build process with coverage await pluginBuildRunner({ coverage: true }); } - - // Move local folders to the scoped job folder - for (const name of ['dist', 'coverage']) { - const dir = path.resolve(process.cwd(), name); - if (fs.existsSync(dir)) { - fs.renameSync(dir, path.resolve(workDir, name)); - } - } - writeJobStats(start, workDir); }; export const ciBuildPluginTask = new Task('Build Plugin', buildPluginRunner); @@ -239,7 +229,7 @@ export const ciPackagePluginTask = new Task('Bundle Plugin', pa * deploy the zip to a running grafana instance * */ -const testPluginRunner: TaskRunner = async ({ full }) => { +const testPluginRunner: TaskRunner = async ({}) => { const start = Date.now(); const workDir = getJobFolder(); const results: TestResultsInfo = { job, passed: 0, failed: 0, screenshots: [] };