Skip to content

Commit

Permalink
ncu-ci: add --cache and progress in display
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Mar 22, 2019
1 parent 4e0ff00 commit 2ba181a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
24 changes: 15 additions & 9 deletions bin/ncu-ci
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const {
} = require('../lib/ci/ci_type_parser');

const {
PRBuild, BenchmarkRun, CommitBuild, listBuilds, FailureAggregator
// , jobCache
PRBuild, BenchmarkRun, CommitBuild,
listBuilds, FailureAggregator, jobCache
} = require('../lib/ci/ci_result_parser');
const clipboardy = require('clipboardy');
const { writeJson } = require('../lib/file');
Expand All @@ -23,10 +23,6 @@ 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({
Expand Down Expand Up @@ -54,6 +50,11 @@ const argv = yargs
default: false,
describe: 'Aggregate the results'
})
.option('cache', {
default: false,
describe: 'Cache the responses from Jenkins in .ncu/cache/ under' +
' the node-core-utils installation directory'
})
.option('limit', {
default: 99,
describe: 'Maximum number of CIs to get data from'
Expand Down Expand Up @@ -144,12 +145,14 @@ async function runQueue(queue, cli, request, argv) {
let dataToCopy = '';
let dataToJson = [];

for (let job of queue) {
for (let i = 0; i < queue.length; ++i) {
const job = queue[i];
cli.separator('');
const progress = `[${i + 1}/${queue.length}]`;
if (job.link) {
cli.log(`Running ${job.link}`);
cli.log(`${progress} Running ${job.link}`);
} else {
cli.log(`Running ${job.type}: ${job.jobid}`);
cli.log(`${progress} Running ${job.type}: ${job.jobid}`);
}
cli.separator('');
const build = await getResults(cli, request, job);
Expand Down Expand Up @@ -211,6 +214,9 @@ async function main(command, argv) {
const type = commandToType[argv.type];
const builds = await listBuilds(cli, request, type);
if (command === 'walk') {
if (argv.cache) {
jobCache.enable();
}
for (const build of builds.failed.slice(0, argv.limit)) {
queue.push(build);
}
Expand Down
1 change: 1 addition & 0 deletions lib/ci/ci_result_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class Job {
}
}

// TODO(joyeecheung): do not cache pending jobs
const jobCache = new Cache();
jobCache.wrap(Job, {
getConsoleText() {
Expand Down
2 changes: 1 addition & 1 deletion lib/ci/ci_type_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const CI_TYPES = new Map([
[LITE_PR_PIPELINE, {
name: 'Lite PR Pipeline',
jobName: 'node-test-pull-request-lite-pipeline',
pattern: /job\/node-test-pull-request-lite-pipeline\/(\d+)\/pipeline/,
pattern: /node-test-pull-request-lite-pipeline\/(\d+)\/pipeline/,
type: LITE_CI
}],
[LITE_COMMIT, {
Expand Down

0 comments on commit 2ba181a

Please sign in to comment.