Skip to content

Commit

Permalink
build: lengthen wait times and retries for CircleCI releases (electro…
Browse files Browse the repository at this point in the history
…n#20889)

* build: lengthen wait times and retries for CircleCI releases

* Review suggestions
  • Loading branch information
John Kleinschmidt committed Oct 31, 2019
1 parent b060cbf commit 23ca7e3
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions script/release/ci-release-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ if (!process.env.CI) require('dotenv-safe').load()

const assert = require('assert')
const request = require('request')
const buildAppVeyorURL = 'https://ci.appveyor.com/api/builds'
const circleCIPipelineURL = 'https://circleci.com/api/v2/project/gh/electron/electron/pipeline'
const vstsURL = 'https://github.visualstudio.com/electron/_apis/build'

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 VSTS_URL = 'https://github.visualstudio.com/electron/_apis/build'
const CIRCLECI_RETRY_LIMIT = 10
const CIRCLECI_WAIT_TIME = 10000

const appVeyorJobs = {
'electron-x64': 'electron-x64-release',
Expand Down Expand Up @@ -78,7 +81,7 @@ async function circleCIcall (targetBranch, job, options) {
// If the workflows are changed in the CircleCI config.yml, this logic will
// also need to be changed as well as possibly changing sudowoodo.
try {
const circleResponse = await circleCIRequest(circleCIPipelineURL, 'POST', buildRequest)
const circleResponse = await circleCIRequest(CIRCLECI_PIPELINE_URL, 'POST', buildRequest)
console.log(`CircleCI release build pipeline ${circleResponse.id} for ${job} triggered.`)
const pipelineInfoUrl = `https://circleci.com/api/v2/pipeline/${circleResponse.id}`
const workflowId = await getCircleCIWorkflowId(circleResponse.id)
Expand All @@ -99,7 +102,7 @@ async function circleCIcall (targetBranch, job, options) {

async function getCircleCIWorkflowId (pipelineId) {
const pipelineInfoUrl = `https://circleci.com/api/v2/pipeline/${pipelineId}`
for (let i = 0; i < 5; i++) {
for (let i = 0; i < CIRCLECI_RETRY_LIMIT; i++) {
const pipelineInfo = await circleCIRequest(pipelineInfoUrl, 'GET')
switch (pipelineInfo.state) {
case 'created': {
Expand All @@ -114,14 +117,15 @@ async function getCircleCIWorkflowId (pipelineId) {
return -1
}
}
await new Promise(resolve => setTimeout(resolve, 5000))
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 -1
}

async function getCircleCIJobNumber (workflowId) {
const jobInfoUrl = `https://circleci.com/api/v2/workflow/${workflowId}/jobs`
for (let i = 0; i < 5; i++) {
for (let i = 0; i < CIRCLECI_RETRY_LIMIT; i++) {
const jobInfo = await circleCIRequest(jobInfoUrl, 'GET')
if (!jobInfo.items) {
continue
Expand All @@ -145,8 +149,9 @@ async function getCircleCIJobNumber (workflowId) {
return -1
}
}
await new Promise(resolve => setTimeout(resolve, 5000))
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 -1
}

Expand Down Expand Up @@ -189,7 +194,7 @@ async function callAppVeyor (targetBranch, job, options) {
}

const requestOpts = {
url: buildAppVeyorURL,
url: BUILD_APPVEYOR_URL,
auth: {
bearer: process.env.APPVEYOR_CLOUD_TOKEN
},
Expand Down Expand Up @@ -244,7 +249,7 @@ async function buildVSTS (targetBranch, options) {
}

const requestOpts = {
url: `${vstsURL}/definitions?api-version=4.1`,
url: `${VSTS_URL}/definitions?api-version=4.1`,
auth: {
user: '',
password: process.env.VSTS_TOKEN
Expand All @@ -270,7 +275,7 @@ async function callVSTSBuild (build, targetBranch, environmentVariables) {
buildBody.parameters = JSON.stringify(environmentVariables)
}
const requestOpts = {
url: `${vstsURL}/builds?api-version=4.1`,
url: `${VSTS_URL}/builds?api-version=4.1`,
auth: {
user: '',
password: process.env.VSTS_TOKEN
Expand Down

0 comments on commit 23ca7e3

Please sign in to comment.