Skip to content

Commit

Permalink
ncu-ci: initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Apr 22, 2018
1 parent ea357a9 commit 4451d21
Show file tree
Hide file tree
Showing 17 changed files with 33,272 additions and 4 deletions.
96 changes: 96 additions & 0 deletions bin/ncu-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env node

'use strict';

const {
PRBuild, BenchmarkRun, CommitBuild, jobCache
} = require('../components/jenkins');
const { runPromise } = require('../lib/run');
const Request = require('../lib/request');
const CLI = require('../lib/cli');
const yargs = require('yargs');

// This is used for testing
// Default cache dir is ${ncu-source-dir}/.ncu/cache
jobCache.enable();

// eslint-disable-next-line no-unused-vars
const argv = yargs
.command({
command: 'pr <jobid>',
desc: 'Show results of a node-test-pull-request CI job',
builder: (yargs) => {
yargs
.positional('jobid', {
describe: 'id of the job',
type: 'number'
});
},
handler
})
.command({
command: 'commit <jobid>',
desc: 'Show results of a node-test-commit CI job',
builder: (yargs) => {
yargs
.positional('jobid', {
describe: 'id of the job',
type: 'number'
});
},
handler
})
.command({
command: 'benchmark <jobid>',
desc: 'Show results of a benchmark-node-micro-benchmarks CI job',
builder: (yargs) => {
yargs
.positional('jobid', {
describe: 'id of the job',
type: 'number'
});
},
handler
})
.demandCommand(1, 'must provide a valid command')
.option('markdown', {
alias: 'm',
type: 'string',
describe: 'file to write results in markdown'
})
.help()
.argv;

async function main(command, argv) {
const cli = new CLI();
const request = new Request({});
let build;
const { jobid, markdown } = argv;
switch (command) {
case 'pr':
build = new PRBuild(cli, request, jobid);
await build.getResults();
break;
case 'commit':
build = new CommitBuild(cli, request, jobid);
await build.getResults();
break;
case 'benchmark':
build = new BenchmarkRun(cli, request, jobid);
await build.getResults();
break;
default:
throw new Error('Unknown CI type!');
}

build.display();

if (markdown) {
build.writeToMarkdown(markdown);
}
}

function handler(argv) {
const [ command ] = argv._;
runPromise(main(command, argv));
}
Loading

0 comments on commit 4451d21

Please sign in to comment.