diff --git a/script/release/ci-release-build.js b/script/release/ci-release-build.js index 6b1a8accc52e9..c5ff1a93f4b0f 100644 --- a/script/release/ci-release-build.js +++ b/script/release/ci-release-build.js @@ -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', @@ -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) @@ -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': { @@ -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 @@ -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 } @@ -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 }, @@ -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 @@ -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