Skip to content

Commit 022ee37

Browse files
author
John Kleinschmidt
authored
build: allow CircleCI timeout and retry to be set via env variables (7-0-x) (electron#20912)
* build: allow circleci timeout and retry to be set via env variables * check for more statuses and run indefinitely
1 parent 5c0e8c5 commit 022ee37

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

script/release/ci-release-build.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ const request = require('request')
66
const BUILD_APPVEYOR_URL = 'https://ci.appveyor.com/api/builds'
77
const CIRCLECI_PIPELINE_URL = 'https://circleci.com/api/v2/project/gh/electron/electron/pipeline'
88
const VSTS_URL = 'https://github.visualstudio.com/electron/_apis/build'
9-
const CIRCLECI_RETRY_LIMIT = 10
10-
const CIRCLECI_WAIT_TIME = 10000
9+
const CIRCLECI_WAIT_TIME = process.env.CIRCLECI_WAIT_TIME || 30000
1110

1211
const appVeyorJobs = {
1312
'electron-x64': 'electron-x64-release',
@@ -102,57 +101,67 @@ async function circleCIcall (targetBranch, job, options) {
102101

103102
async function getCircleCIWorkflowId (pipelineId) {
104103
const pipelineInfoUrl = `https://circleci.com/api/v2/pipeline/${pipelineId}`
105-
for (let i = 0; i < CIRCLECI_RETRY_LIMIT; i++) {
104+
let workflowId = 0
105+
while (workflowId === 0) {
106106
const pipelineInfo = await circleCIRequest(pipelineInfoUrl, 'GET')
107107
switch (pipelineInfo.state) {
108108
case 'created': {
109109
if (pipelineInfo.workflows.length === 1) {
110-
return pipelineInfo.workflows[0].id
110+
workflowId = pipelineInfo.workflows[0].id
111+
break
111112
}
112113
console.log('Unxpected number of workflows, response was:', pipelineInfo)
113-
return -1
114+
workflowId = -1
115+
break
114116
}
115117
case 'error': {
116118
console.log('Error retrieving workflows, response was:', pipelineInfo)
117-
return -1
119+
workflowId = -1
120+
break
118121
}
119122
}
120123
await new Promise(resolve => setTimeout(resolve, CIRCLECI_WAIT_TIME))
121124
}
122-
console.log(`Error: could not get CircleCI WorkflowId for ${pipelineId} after ${CIRCLECI_RETRY_LIMIT} times.`)
123-
return -1
125+
return workflowId
124126
}
125127

126128
async function getCircleCIJobNumber (workflowId) {
127129
const jobInfoUrl = `https://circleci.com/api/v2/workflow/${workflowId}/jobs`
128-
for (let i = 0; i < CIRCLECI_RETRY_LIMIT; i++) {
130+
let jobNumber = 0
131+
while (jobNumber === 0) {
129132
const jobInfo = await circleCIRequest(jobInfoUrl, 'GET')
130133
if (!jobInfo.items) {
131134
continue
132135
}
133136
if (jobInfo.items.length !== 1) {
134137
console.log('Unxpected number of jobs, response was:', jobInfo)
135-
return -1
138+
jobNumber = -1
139+
break
136140
}
137141

138142
switch (jobInfo.items[0].status) {
139143
case 'not_running':
140144
case 'queued':
141145
case 'running': {
142146
if (jobInfo.items[0].job_number && !isNaN(jobInfo.items[0].job_number)) {
143-
return jobInfo.items[0].job_number
147+
jobNumber = jobInfo.items[0].job_number
144148
}
145149
break
146150
}
147-
case 'error': {
148-
console.log('Error retrieving jobs, response was:', jobInfo)
149-
return -1
151+
case 'canceled':
152+
case 'error':
153+
case 'infrastructure_fail':
154+
case 'timedout':
155+
case 'not_run':
156+
case 'failed': {
157+
console.log(`Error job returned a status of ${jobInfo.items[0].status}, response was:`, jobInfo)
158+
jobNumber = -1
159+
break
150160
}
151161
}
152162
await new Promise(resolve => setTimeout(resolve, CIRCLECI_WAIT_TIME))
153163
}
154-
console.log(`Error: could not get CircleCI Job Number for ${workflowId} after ${CIRCLECI_RETRY_LIMIT} times.`)
155-
return -1
164+
return jobNumber
156165
}
157166

158167
async function circleCIRequest (url, method, requestBody) {

0 commit comments

Comments
 (0)