@@ -2,9 +2,12 @@ if (!process.env.CI) require('dotenv-safe').load()
2
2
3
3
const assert = require ( 'assert' )
4
4
const request = require ( 'request' )
5
- const buildAppVeyorURL = 'https://ci.appveyor.com/api/builds'
6
- const circleCIPipelineURL = 'https://circleci.com/api/v2/project/gh/electron/electron/pipeline'
7
- const vstsURL = 'https://github.visualstudio.com/electron/_apis/build'
5
+
6
+ const BUILD_APPVEYOR_URL = 'https://ci.appveyor.com/api/builds'
7
+ const CIRCLECI_PIPELINE_URL = 'https://circleci.com/api/v2/project/gh/electron/electron/pipeline'
8
+ const VSTS_URL = 'https://github.visualstudio.com/electron/_apis/build'
9
+ const CIRCLECI_RETRY_LIMIT = 10
10
+ const CIRCLECI_WAIT_TIME = 10000
8
11
9
12
const appVeyorJobs = {
10
13
'electron-x64' : 'electron-x64-release' ,
@@ -78,7 +81,7 @@ async function circleCIcall (targetBranch, job, options) {
78
81
// If the workflows are changed in the CircleCI config.yml, this logic will
79
82
// also need to be changed as well as possibly changing sudowoodo.
80
83
try {
81
- const circleResponse = await circleCIRequest ( circleCIPipelineURL , 'POST' , buildRequest )
84
+ const circleResponse = await circleCIRequest ( CIRCLECI_PIPELINE_URL , 'POST' , buildRequest )
82
85
console . log ( `CircleCI release build pipeline ${ circleResponse . id } for ${ job } triggered.` )
83
86
const pipelineInfoUrl = `https://circleci.com/api/v2/pipeline/${ circleResponse . id } `
84
87
const workflowId = await getCircleCIWorkflowId ( circleResponse . id )
@@ -99,7 +102,7 @@ async function circleCIcall (targetBranch, job, options) {
99
102
100
103
async function getCircleCIWorkflowId ( pipelineId ) {
101
104
const pipelineInfoUrl = `https://circleci.com/api/v2/pipeline/${ pipelineId } `
102
- for ( let i = 0 ; i < 5 ; i ++ ) {
105
+ for ( let i = 0 ; i < CIRCLECI_RETRY_LIMIT ; i ++ ) {
103
106
const pipelineInfo = await circleCIRequest ( pipelineInfoUrl , 'GET' )
104
107
switch ( pipelineInfo . state ) {
105
108
case 'created' : {
@@ -114,14 +117,15 @@ async function getCircleCIWorkflowId (pipelineId) {
114
117
return - 1
115
118
}
116
119
}
117
- await new Promise ( resolve => setTimeout ( resolve , 5000 ) )
120
+ await new Promise ( resolve => setTimeout ( resolve , CIRCLECI_WAIT_TIME ) )
118
121
}
122
+ console . log ( `Error: could not get CircleCI WorkflowId for ${ pipelineId } after ${ CIRCLECI_RETRY_LIMIT } times.` )
119
123
return - 1
120
124
}
121
125
122
126
async function getCircleCIJobNumber ( workflowId ) {
123
127
const jobInfoUrl = `https://circleci.com/api/v2/workflow/${ workflowId } /jobs`
124
- for ( let i = 0 ; i < 5 ; i ++ ) {
128
+ for ( let i = 0 ; i < CIRCLECI_RETRY_LIMIT ; i ++ ) {
125
129
const jobInfo = await circleCIRequest ( jobInfoUrl , 'GET' )
126
130
if ( ! jobInfo . items ) {
127
131
continue
@@ -145,8 +149,9 @@ async function getCircleCIJobNumber (workflowId) {
145
149
return - 1
146
150
}
147
151
}
148
- await new Promise ( resolve => setTimeout ( resolve , 5000 ) )
152
+ await new Promise ( resolve => setTimeout ( resolve , CIRCLECI_WAIT_TIME ) )
149
153
}
154
+ console . log ( `Error: could not get CircleCI Job Number for ${ workflowId } after ${ CIRCLECI_RETRY_LIMIT } times.` )
150
155
return - 1
151
156
}
152
157
@@ -189,7 +194,7 @@ async function callAppVeyor (targetBranch, job, options) {
189
194
}
190
195
191
196
const requestOpts = {
192
- url : buildAppVeyorURL ,
197
+ url : BUILD_APPVEYOR_URL ,
193
198
auth : {
194
199
bearer : process . env . APPVEYOR_CLOUD_TOKEN
195
200
} ,
@@ -244,7 +249,7 @@ async function buildVSTS (targetBranch, options) {
244
249
}
245
250
246
251
const requestOpts = {
247
- url : `${ vstsURL } /definitions?api-version=4.1` ,
252
+ url : `${ VSTS_URL } /definitions?api-version=4.1` ,
248
253
auth : {
249
254
user : '' ,
250
255
password : process . env . VSTS_TOKEN
@@ -270,7 +275,7 @@ async function callVSTSBuild (build, targetBranch, environmentVariables) {
270
275
buildBody . parameters = JSON . stringify ( environmentVariables )
271
276
}
272
277
const requestOpts = {
273
- url : `${ vstsURL } /builds?api-version=4.1` ,
278
+ url : `${ VSTS_URL } /builds?api-version=4.1` ,
274
279
auth : {
275
280
user : '' ,
276
281
password : process . env . VSTS_TOKEN
0 commit comments