Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9d8b2e1

Browse files
committedApr 7, 2018
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

+95
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+
}

‎components/jenkins.js

+630
Large diffs are not rendered by default.

‎lib/cache.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ function isAsync(fn) {
1010

1111
class Cache {
1212
constructor(dir) {
13-
this.dir = dir || path.join(__dirname, '..', '.ncu', 'cache');
13+
this.dir = dir || this.computeCacheDir(path.join(__dirname, '..'));
1414
this.originals = {};
1515
this.disabled = true;
1616
}
1717

18+
computeCacheDir(base) {
19+
return path.join(base, '.ncu', 'cache');
20+
}
21+
1822
disable() {
1923
this.disabled = true;
2024
}

‎lib/cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class CLI {
9090
this.write(text + EOL);
9191
}
9292

93-
table(first, second, length) {
93+
table(first, second = '', length = 11) {
9494
this.log(head(first, length) + second);
9595
}
9696

‎lib/request.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ class Request {
1414
return fs.readFileSync(filePath, 'utf8');
1515
}
1616

17-
async text(url, options) {
17+
async text(url, options = {}) {
1818
return fetch(url, options).then(res => res.text());
1919
}
2020

21+
async json(url, options = {}) {
22+
options.headers = options.headers || {};
23+
options.headers.Accept = 'application/json';
24+
return fetch(url, options).then(res => res.json());
25+
}
26+
2127
async gql(name, variables, path) {
2228
const query = this.loadQuery(name);
2329
if (path) {

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"get-metadata": "./bin/get-metadata",
77
"ncu-config": "./bin/ncu-config",
88
"git-node": "./bin/git-node",
9-
"ncu-team": "./bin/ncu-team"
9+
"ncu-team": "./bin/ncu-team",
10+
"ncu-ci": "./bin/ncu-ci"
1011
},
1112
"scripts": {
1213
"test": "npm run test-unit && npm run lint",

0 commit comments

Comments
 (0)
Please sign in to comment.