build: allow CircleCI timeout and retry to be set via env variables (#20896)
* build: allow circleci timeout and retry to be set via env variables * check for more statuses and run indefinitely
This commit is contained in:
parent
d8aaaeb378
commit
4240017cb6
1 changed files with 25 additions and 16 deletions
|
@ -6,8 +6,7 @@ const request = require('request')
|
||||||
const BUILD_APPVEYOR_URL = 'https://ci.appveyor.com/api/builds'
|
const BUILD_APPVEYOR_URL = 'https://ci.appveyor.com/api/builds'
|
||||||
const CIRCLECI_PIPELINE_URL = 'https://circleci.com/api/v2/project/gh/electron/electron/pipeline'
|
const CIRCLECI_PIPELINE_URL = 'https://circleci.com/api/v2/project/gh/electron/electron/pipeline'
|
||||||
const VSTS_URL = 'https://github.visualstudio.com/electron/_apis/build'
|
const VSTS_URL = 'https://github.visualstudio.com/electron/_apis/build'
|
||||||
const CIRCLECI_RETRY_LIMIT = 10
|
const CIRCLECI_WAIT_TIME = process.env.CIRCLECI_WAIT_TIME || 30000
|
||||||
const CIRCLECI_WAIT_TIME = 10000
|
|
||||||
|
|
||||||
const appVeyorJobs = {
|
const appVeyorJobs = {
|
||||||
'electron-x64': 'electron-x64-release',
|
'electron-x64': 'electron-x64-release',
|
||||||
|
@ -102,37 +101,42 @@ async function circleCIcall (targetBranch, job, options) {
|
||||||
|
|
||||||
async function getCircleCIWorkflowId (pipelineId) {
|
async function getCircleCIWorkflowId (pipelineId) {
|
||||||
const pipelineInfoUrl = `https://circleci.com/api/v2/pipeline/${pipelineId}`
|
const pipelineInfoUrl = `https://circleci.com/api/v2/pipeline/${pipelineId}`
|
||||||
for (let i = 0; i < CIRCLECI_RETRY_LIMIT; i++) {
|
let workflowId = 0
|
||||||
|
while (workflowId === 0) {
|
||||||
const pipelineInfo = await circleCIRequest(pipelineInfoUrl, 'GET')
|
const pipelineInfo = await circleCIRequest(pipelineInfoUrl, 'GET')
|
||||||
switch (pipelineInfo.state) {
|
switch (pipelineInfo.state) {
|
||||||
case 'created': {
|
case 'created': {
|
||||||
if (pipelineInfo.workflows.length === 1) {
|
if (pipelineInfo.workflows.length === 1) {
|
||||||
return pipelineInfo.workflows[0].id
|
workflowId = pipelineInfo.workflows[0].id
|
||||||
|
break
|
||||||
}
|
}
|
||||||
console.log('Unxpected number of workflows, response was:', pipelineInfo)
|
console.log('Unxpected number of workflows, response was:', pipelineInfo)
|
||||||
return -1
|
workflowId = -1
|
||||||
|
break
|
||||||
}
|
}
|
||||||
case 'error': {
|
case 'error': {
|
||||||
console.log('Error retrieving workflows, response was:', pipelineInfo)
|
console.log('Error retrieving workflows, response was:', pipelineInfo)
|
||||||
return -1
|
workflowId = -1
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, CIRCLECI_WAIT_TIME))
|
await new Promise(resolve => setTimeout(resolve, CIRCLECI_WAIT_TIME))
|
||||||
}
|
}
|
||||||
console.log(`Error: could not get CircleCI WorkflowId for ${pipelineId} after ${CIRCLECI_RETRY_LIMIT} times.`)
|
return workflowId
|
||||||
return -1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCircleCIJobNumber (workflowId) {
|
async function getCircleCIJobNumber (workflowId) {
|
||||||
const jobInfoUrl = `https://circleci.com/api/v2/workflow/${workflowId}/jobs`
|
const jobInfoUrl = `https://circleci.com/api/v2/workflow/${workflowId}/jobs`
|
||||||
for (let i = 0; i < CIRCLECI_RETRY_LIMIT; i++) {
|
let jobNumber = 0
|
||||||
|
while (jobNumber === 0) {
|
||||||
const jobInfo = await circleCIRequest(jobInfoUrl, 'GET')
|
const jobInfo = await circleCIRequest(jobInfoUrl, 'GET')
|
||||||
if (!jobInfo.items) {
|
if (!jobInfo.items) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (jobInfo.items.length !== 1) {
|
if (jobInfo.items.length !== 1) {
|
||||||
console.log('Unxpected number of jobs, response was:', jobInfo)
|
console.log('Unxpected number of jobs, response was:', jobInfo)
|
||||||
return -1
|
jobNumber = -1
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (jobInfo.items[0].status) {
|
switch (jobInfo.items[0].status) {
|
||||||
|
@ -140,19 +144,24 @@ async function getCircleCIJobNumber (workflowId) {
|
||||||
case 'queued':
|
case 'queued':
|
||||||
case 'running': {
|
case 'running': {
|
||||||
if (jobInfo.items[0].job_number && !isNaN(jobInfo.items[0].job_number)) {
|
if (jobInfo.items[0].job_number && !isNaN(jobInfo.items[0].job_number)) {
|
||||||
return jobInfo.items[0].job_number
|
jobNumber = jobInfo.items[0].job_number
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'error': {
|
case 'canceled':
|
||||||
console.log('Error retrieving jobs, response was:', jobInfo)
|
case 'error':
|
||||||
return -1
|
case 'infrastructure_fail':
|
||||||
|
case 'timedout':
|
||||||
|
case 'not_run':
|
||||||
|
case 'failed': {
|
||||||
|
console.log(`Error job returned a status of ${jobInfo.items[0].status}, response was:`, jobInfo)
|
||||||
|
jobNumber = -1
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await new Promise(resolve => setTimeout(resolve, CIRCLECI_WAIT_TIME))
|
await new Promise(resolve => setTimeout(resolve, CIRCLECI_WAIT_TIME))
|
||||||
}
|
}
|
||||||
console.log(`Error: could not get CircleCI Job Number for ${workflowId} after ${CIRCLECI_RETRY_LIMIT} times.`)
|
return jobNumber
|
||||||
return -1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function circleCIRequest (url, method, requestBody) {
|
async function circleCIRequest (url, method, requestBody) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue