'use strict';
const envs = [
{
index: 'CI_NODE_INDEX',
total: 'CI_NODE_TOTAL',
},
{
index: 'CIRCLE_NODE_INDEX',
total: 'CIRCLE_NODE_TOTAL',
},
{
index: 'BITBUCKET_PARALLEL_STEP',
total: 'BITBUCKET_PARALLEL_STEP_COUNT',
},
{
index: 'BUILDKITE_PARALLEL_JOB',
total: 'BUILDKITE_PARALLEL_JOB_COUNT',
},
{
index: 'SEMAPHORE_CURRENT_JOB',
total: 'SEMAPHORE_JOB_COUNT',
},
];
let maybeNum = val => {
let num = parseInt(val, 10);
return Number.isNaN(num) ? null : num;
};
let match = null;
for (let env of envs) {
let index = maybeNum(process.env[env.index]);
let total = maybeNum(process.env[env.total]);
if (index !== null && total !== null) {
if (process.env.GITLAB_CI) {
index = index - 1;
}
match = { index, total };
break;
}
}
module.exports = match;