Skip to content

Commit 705c3b5

Browse files
authoredApr 24, 2020
Handle service_job_number for parallelism in Travis and CircleCI (#290)
* support `service_job_number` for CircleCI/Travis * Travis use TRAVIS_JOB_ID
1 parent eb6dc35 commit 705c3b5

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed
 

‎lib/convertLcovToCoveralls.js

+4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ const convertLcovToCoveralls = (input, options, cb) => {
9292
postJson.service_job_id = options.service_job_id;
9393
}
9494

95+
if (options.service_job_number) {
96+
postJson.service_job_number = options.service_job_number;
97+
}
98+
9599
if (options.service_pull_request) {
96100
postJson.service_pull_request = options.service_pull_request;
97101
}

‎lib/getOptions.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const getBaseOptions = cb => {
2424

2525
if (process.env.TRAVIS) {
2626
options.service_name = 'travis-ci';
27+
options.service_number = process.env.TRAVIS_BUILD_NUMBER;
2728
options.service_job_id = process.env.TRAVIS_JOB_ID;
2829
options.service_pull_request = process.env.TRAVIS_PULL_REQUEST;
2930
git_commit = 'HEAD';
@@ -53,7 +54,8 @@ const getBaseOptions = cb => {
5354

5455
if (process.env.CIRCLECI) {
5556
options.service_name = 'circleci';
56-
options.service_job_id = process.env.CIRCLE_BUILD_NUM;
57+
options.service_number = process.env.CIRCLE_WORKFLOW_ID;
58+
options.service_job_number = process.env.CIRCLE_BUILD_NUM;
5759

5860
if (process.env.CI_PULL_REQUEST) {
5961
const pr = process.env.CI_PULL_REQUEST.split('/pull/');
@@ -147,6 +149,10 @@ const getBaseOptions = cb => {
147149
options.service_number = process.env.COVERALLS_SERVICE_NUMBER;
148150
}
149151

152+
if (process.env.COVERALLS_SERVICE_JOB_NUMBER) {
153+
options.service_job_number = process.env.COVERALLS_SERVICE_JOB_NUMBER;
154+
}
155+
150156
if (process.env.COVERALLS_SERVICE_JOB_ID) {
151157
options.service_job_id = process.env.COVERALLS_SERVICE_JOB_ID;
152158
}

‎test/convertLcovToCoveralls.js

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('convertLcovToCoveralls', () => {
3131
process.env.COVERALLS_SERVICE_NAME = 'SERVICE_NAME';
3232
process.env.COVERALLS_SERVICE_NUMBER = 'SERVICE_NUMBER';
3333
process.env.COVERALLS_SERVICE_JOB_ID = 'SERVICE_JOB_ID';
34+
process.env.COVERALLS_SERVICE_JOB_NUMBER = 'SERVICE_JOB_NUMBER';
3435
process.env.COVERALLS_REPO_TOKEN = 'REPO_TOKEN';
3536
process.env.CI_PULL_REQUEST = 'https://github.com/fake/fake/pulls/123';
3637
process.env.COVERALLS_PARALLEL = 'true';
@@ -48,6 +49,7 @@ describe('convertLcovToCoveralls', () => {
4849
output.service_name.should.equal('SERVICE_NAME');
4950
output.service_number.should.equal('SERVICE_NUMBER');
5051
output.service_job_id.should.equal('SERVICE_JOB_ID');
52+
output.service_job_number.should.equal('SERVICE_JOB_NUMBER');
5153
output.service_pull_request.should.equal('123');
5254
output.parallel.should.equal(true);
5355
output.flag_name.should.equal('FLAG_NAME');

‎test/getOptions.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,14 @@ const testServicePullRequest = (sut, done) => {
357357

358358
const testTravisCi = (sut, done) => {
359359
process.env.TRAVIS = 'TRUE';
360-
process.env.TRAVIS_JOB_ID = '1234';
360+
process.env.TRAVIS_BUILD_NUMBER = '1';
361+
process.env.TRAVIS_JOB_ID = '12';
361362
process.env.TRAVIS_PULL_REQUEST = '123';
362363
sut((err, options) => {
363364
should.not.exist(err);
364365
options.service_name.should.equal('travis-ci');
365-
options.service_job_id.should.equal('1234');
366+
options.service_number.should.equal('1');
367+
options.service_job_id.should.equal('12');
366368
options.service_pull_request.should.equal('123');
367369
done();
368370
});
@@ -373,12 +375,12 @@ const testTravisPro = (sut, done) => {
373375
const service_name = 'travis-pro';
374376
fs.writeFileSync(file, `service_name: ${service_name}`);
375377
process.env.TRAVIS = 'TRUE';
376-
process.env.TRAVIS_JOB_ID = '1234';
378+
process.env.TRAVIS_BUILD_NUMBER = '1234';
377379
process.env.TRAVIS_COMMIT = 'a12s2d3df4f435g45g45g67h5g6';
378380
sut((err, options) => {
379381
should.not.exist(err);
380382
options.service_name.should.equal(service_name);
381-
options.service_job_id.should.equal('1234');
383+
options.service_number.should.equal('1234');
382384
options.git.head.id.should.equal('HEAD');
383385
fs.unlinkSync(file);
384386
done();
@@ -416,7 +418,8 @@ const testJenkins = (sut, done) => {
416418
const testCircleCi = (sut, done) => {
417419
process.env.CIRCLECI = true;
418420
process.env.CIRCLE_BRANCH = 'master';
419-
process.env.CIRCLE_BUILD_NUM = '1234';
421+
process.env.CIRCLE_WORKFLOW_ID = '1';
422+
process.env.CIRCLE_BUILD_NUM = '2';
420423
process.env.CIRCLE_SHA1 = 'e3e3e3e3e3e3e3e3e';
421424
process.env.CI_PULL_REQUEST = 'http://github.com/node-coveralls/pull/3';
422425

@@ -436,7 +439,8 @@ const testCircleCi = (sut, done) => {
436439
sut((err, options) => {
437440
should.not.exist(err);
438441
options.service_name.should.equal('circleci');
439-
options.service_job_id.should.equal('1234');
442+
options.service_number.should.equal('1');
443+
options.service_job_number.should.equal('2');
440444
options.service_pull_request.should.equal('3');
441445
options.git.should.eql(git);
442446
done();

0 commit comments

Comments
 (0)
Please sign in to comment.