Skip to content

Commit 9d8b2e1

Browse files
committed
ncu-ci: initial implementation
1 parent c6bbe1b commit 9d8b2e1

File tree

6 files changed

+740
-4
lines changed

6 files changed

+740
-4
lines changed

bin/ncu-ci

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
const {
6+
PRBuild, BenchmarkRun, CommitBuild, jobCache
7+
} = require('../components/jenkins');
8+
const { runPromise } = require('../lib/run');
9+
const Request = require('../lib/request');
10+
const CLI = require('../lib/cli');
11+
const yargs = require('yargs');
12+
13+
// This is used for testing
14+
// Default cache dir is ${ncu-source-dir}/.ncu/cache
15+
jobCache.enable();
16+
17+
// eslint-disable-next-line no-unused-vars
18+
const argv = yargs
19+
.command({
20+
command: 'pr <jobid>',
21+
desc: 'Show results of a node-test-pull-request CI job',
22+
builder: (yargs) => {
23+
yargs
24+
.positional('jobid', {
25+
describe: 'id of the job',
26+
type: 'number'
27+
});
28+
},
29+
handler
30+
})
31+
.command({
32+
command: 'commit <jobid>',
33+
desc: 'Show results of a node-test-commit CI job',
34+
builder: (yargs) => {
35+
yargs
36+
.positional('jobid', {
37+
describe: 'id of the job',
38+
type: 'number'
39+
});
40+
},
41+
handler
42+
})
43+
.command({
44+
command: 'benchmark <jobid>',
45+
desc: 'Show results of a benchmark-node-micro-benchmarks CI job',
46+
builder: (yargs) => {
47+
yargs
48+
.positional('jobid', {
49+
describe: 'id of the job',
50+
type: 'number'
51+
});
52+
},
53+
handler
54+
})
55+
.demandCommand(1, 'must provide a valid command')
56+
.option('markdown', {
57+
alias: 'm',
58+
type: 'string',
59+
describe: 'file to write results in markdown'
60+
})
61+
.argv;
62+
63+
async function main(command, argv) {
64+
const cli = new CLI();
65+
const request = new Request({});
66+
let build;
67+
const { jobid, markdown } = argv;
68+
switch (command) {
69+
case 'pr':
70+
build = new PRBuild(cli, request, jobid);
71+
await build.getResults();
72+
break;
73+
case 'commit':
74+
build = new CommitBuild(cli, request, jobid);
75+
await build.getResults();
76+
break;
77+
case 'benchmark':
78+
build = new BenchmarkRun(cli, request, jobid);
79+
await build.getResults();
80+
break;
81+
default:
82+
throw new Error('Unknown CI type!');
83+
}
84+
85+
build.display();
86+
87+
if (markdown) {
88+
build.writeToMarkdown(markdown);
89+
}
90+
}
91+
92+
function handler(argv) {
93+
const [ command ] = argv._;
94+
runPromise(main(command, argv));
95+
}

0 commit comments

Comments
 (0)