-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
56 lines (49 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// @flow
'use strict';
/*::
type Match = null | { index: number, total: number };
*/
const envs = [
// Knapsack / TravisCI / GitLab
{
index: 'CI_NODE_INDEX',
total: 'CI_NODE_TOTAL',
},
// CircleCI
{
index: 'CIRCLE_NODE_INDEX',
total: 'CIRCLE_NODE_TOTAL',
},
// Bitbucket Pipelines
{
index: 'BITBUCKET_PARALLEL_STEP',
total: 'BITBUCKET_PARALLEL_STEP_COUNT',
},
// Buildkite
{
index: 'BUILDKITE_PARALLEL_JOB',
total: 'BUILDKITE_PARALLEL_JOB_COUNT',
},
// Semaphore
{
index: 'SEMAPHORE_CURRENT_JOB',
total: 'SEMAPHORE_JOB_COUNT',
},
];
let maybeNum = val => {
let num = parseInt(val, 10);
return Number.isNaN(num) ? null : num;
};
let match /*: 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;