Skip to content

Commit

Permalink
Toolkit: plugin ci needs to cooperate better with make/mage (grafana#…
Browse files Browse the repository at this point in the history
…22588)

* cleanup

* cleanup
  • Loading branch information
ryantxu authored Mar 5, 2020
1 parent 0f8cfca commit e688f13
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
12 changes: 3 additions & 9 deletions packages/grafana-toolkit/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});

Expand All @@ -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
Expand Down
15 changes: 10 additions & 5 deletions packages/grafana-toolkit/src/cli/tasks/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ const manifestRunner: TaskRunner<ManifestOptions> = 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);

// TODO:
// gpg --output doc.sig --sign doc
fs.writeFileSync(path.join(folder, filename), stdout);

// 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);
Expand Down
38 changes: 14 additions & 24 deletions packages/grafana-toolkit/src/cli/tasks/plugin.ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ import { promisify } from 'util';
const rimraf = promisify(rimrafCallback);

export interface PluginCIOptions {
backend?: boolean;
full?: boolean;
finish?: boolean;
upload?: boolean;
}

Expand All @@ -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<PluginCIOptions> = async ({ backend }) => {
const buildPluginRunner: TaskRunner<PluginCIOptions> = 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<PluginCIOptions>('Build Plugin', buildPluginRunner);
Expand Down Expand Up @@ -239,7 +229,7 @@ export const ciPackagePluginTask = new Task<PluginCIOptions>('Bundle Plugin', pa
* deploy the zip to a running grafana instance
*
*/
const testPluginRunner: TaskRunner<PluginCIOptions> = async ({ full }) => {
const testPluginRunner: TaskRunner<PluginCIOptions> = async ({}) => {
const start = Date.now();
const workDir = getJobFolder();
const results: TestResultsInfo = { job, passed: 0, failed: 0, screenshots: [] };
Expand Down

0 comments on commit e688f13

Please sign in to comment.