Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ncu-ci: add --cache and progress in display #328

Merged
merged 2 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
5 changes: 2 additions & 3 deletions 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/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unrelated change? (If it allows the GitHub bot posted links then that's 💯 👍 but should be in its own commit and probably have tests if that's the intention.)

type: LITE_CI
}],
[LITE_COMMIT, {
Expand Down Expand Up @@ -120,8 +120,7 @@ function parseJobFromURL(url) {
}

for (let [ type, info ] of CI_TYPES) {
const re = new RegExp(`job/${info.jobName}/(\\d+)`);
const match = url.match(re);
const match = url.match(info.pattern);
if (match) {
return {
link: url,
Expand Down
15 changes: 14 additions & 1 deletion test/unit/ci_type_parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,23 @@ const expected = new Map([
jobid: 7213
}]
]);

describe('JobParser', () => {
it('should parse CI results', () => {
const results = new JobParser(commentsWithCI).parse();
assert.deepStrictEqual([...results.entries()], [...expected.entries()]);
});

it('should parse pipeline links', () => {
const data = [{
'publishedAt': '2017-10-29T04:16:36.458Z',
'bodyText': '@contributer build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/3009/pipeline/'
}];
const results = new JobParser(data).parse();
assert.deepStrictEqual([...results.entries()], [
['LITE_PR_PIPELINE', {
link: 'https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/3009/pipeline/',
date: '2017-10-29T04:16:36.458Z',
jobid: 3009
}]]);
});
});