Skip to content

Commit

Permalink
Handle service_job_number for parallelism in Travis and CircleCI (#290)
Browse files Browse the repository at this point in the history
* support `service_job_number` for CircleCI/Travis
* Travis use TRAVIS_JOB_ID
  • Loading branch information
nickmerwin authored Apr 24, 2020
1 parent eb6dc35 commit 705c3b5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/convertLcovToCoveralls.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ const convertLcovToCoveralls = (input, options, cb) => {
postJson.service_job_id = options.service_job_id;
}

if (options.service_job_number) {
postJson.service_job_number = options.service_job_number;
}

if (options.service_pull_request) {
postJson.service_pull_request = options.service_pull_request;
}
Expand Down
8 changes: 7 additions & 1 deletion lib/getOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const getBaseOptions = cb => {

if (process.env.TRAVIS) {
options.service_name = 'travis-ci';
options.service_number = process.env.TRAVIS_BUILD_NUMBER;
options.service_job_id = process.env.TRAVIS_JOB_ID;
options.service_pull_request = process.env.TRAVIS_PULL_REQUEST;
git_commit = 'HEAD';
Expand Down Expand Up @@ -53,7 +54,8 @@ const getBaseOptions = cb => {

if (process.env.CIRCLECI) {
options.service_name = 'circleci';
options.service_job_id = process.env.CIRCLE_BUILD_NUM;
options.service_number = process.env.CIRCLE_WORKFLOW_ID;
options.service_job_number = process.env.CIRCLE_BUILD_NUM;

if (process.env.CI_PULL_REQUEST) {
const pr = process.env.CI_PULL_REQUEST.split('/pull/');
Expand Down Expand Up @@ -147,6 +149,10 @@ const getBaseOptions = cb => {
options.service_number = process.env.COVERALLS_SERVICE_NUMBER;
}

if (process.env.COVERALLS_SERVICE_JOB_NUMBER) {
options.service_job_number = process.env.COVERALLS_SERVICE_JOB_NUMBER;
}

if (process.env.COVERALLS_SERVICE_JOB_ID) {
options.service_job_id = process.env.COVERALLS_SERVICE_JOB_ID;
}
Expand Down
2 changes: 2 additions & 0 deletions test/convertLcovToCoveralls.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('convertLcovToCoveralls', () => {
process.env.COVERALLS_SERVICE_NAME = 'SERVICE_NAME';
process.env.COVERALLS_SERVICE_NUMBER = 'SERVICE_NUMBER';
process.env.COVERALLS_SERVICE_JOB_ID = 'SERVICE_JOB_ID';
process.env.COVERALLS_SERVICE_JOB_NUMBER = 'SERVICE_JOB_NUMBER';
process.env.COVERALLS_REPO_TOKEN = 'REPO_TOKEN';
process.env.CI_PULL_REQUEST = 'https://github.com/fake/fake/pulls/123';
process.env.COVERALLS_PARALLEL = 'true';
Expand All @@ -48,6 +49,7 @@ describe('convertLcovToCoveralls', () => {
output.service_name.should.equal('SERVICE_NAME');
output.service_number.should.equal('SERVICE_NUMBER');
output.service_job_id.should.equal('SERVICE_JOB_ID');
output.service_job_number.should.equal('SERVICE_JOB_NUMBER');
output.service_pull_request.should.equal('123');
output.parallel.should.equal(true);
output.flag_name.should.equal('FLAG_NAME');
Expand Down
16 changes: 10 additions & 6 deletions test/getOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,14 @@ const testServicePullRequest = (sut, done) => {

const testTravisCi = (sut, done) => {
process.env.TRAVIS = 'TRUE';
process.env.TRAVIS_JOB_ID = '1234';
process.env.TRAVIS_BUILD_NUMBER = '1';
process.env.TRAVIS_JOB_ID = '12';
process.env.TRAVIS_PULL_REQUEST = '123';
sut((err, options) => {
should.not.exist(err);
options.service_name.should.equal('travis-ci');
options.service_job_id.should.equal('1234');
options.service_number.should.equal('1');
options.service_job_id.should.equal('12');
options.service_pull_request.should.equal('123');
done();
});
Expand All @@ -373,12 +375,12 @@ const testTravisPro = (sut, done) => {
const service_name = 'travis-pro';
fs.writeFileSync(file, `service_name: ${service_name}`);
process.env.TRAVIS = 'TRUE';
process.env.TRAVIS_JOB_ID = '1234';
process.env.TRAVIS_BUILD_NUMBER = '1234';
process.env.TRAVIS_COMMIT = 'a12s2d3df4f435g45g45g67h5g6';
sut((err, options) => {
should.not.exist(err);
options.service_name.should.equal(service_name);
options.service_job_id.should.equal('1234');
options.service_number.should.equal('1234');
options.git.head.id.should.equal('HEAD');
fs.unlinkSync(file);
done();
Expand Down Expand Up @@ -416,7 +418,8 @@ const testJenkins = (sut, done) => {
const testCircleCi = (sut, done) => {
process.env.CIRCLECI = true;
process.env.CIRCLE_BRANCH = 'master';
process.env.CIRCLE_BUILD_NUM = '1234';
process.env.CIRCLE_WORKFLOW_ID = '1';
process.env.CIRCLE_BUILD_NUM = '2';
process.env.CIRCLE_SHA1 = 'e3e3e3e3e3e3e3e3e';
process.env.CI_PULL_REQUEST = 'http://github.com/node-coveralls/pull/3';

Expand All @@ -436,7 +439,8 @@ const testCircleCi = (sut, done) => {
sut((err, options) => {
should.not.exist(err);
options.service_name.should.equal('circleci');
options.service_job_id.should.equal('1234');
options.service_number.should.equal('1');
options.service_job_number.should.equal('2');
options.service_pull_request.should.equal('3');
options.git.should.eql(git);
done();
Expand Down

0 comments on commit 705c3b5

Please sign in to comment.