2018-10-04 16:01:16 +00:00
|
|
|
if (!process.env.CI) require('dotenv-safe').load()
|
2018-07-11 18:02:03 +00:00
|
|
|
|
2017-11-02 07:26:37 +00:00
|
|
|
const assert = require('assert')
|
|
|
|
const request = require('request')
|
2019-05-23 20:54:34 +00:00
|
|
|
const buildAppVeyorURL = 'https://ci.appveyor.com/api/builds'
|
2019-09-17 18:48:02 +00:00
|
|
|
const circleCIPipelineURL = 'https://circleci.com/api/v2/project/gh/electron/electron/pipeline'
|
2018-06-13 20:11:26 +00:00
|
|
|
const vstsURL = 'https://github.visualstudio.com/electron/_apis/build'
|
2017-11-02 07:26:37 +00:00
|
|
|
|
2018-07-09 19:29:44 +00:00
|
|
|
const appVeyorJobs = {
|
2019-05-23 20:54:34 +00:00
|
|
|
'electron-x64': 'electron-x64-release',
|
2019-09-04 18:24:46 +00:00
|
|
|
'electron-ia32': 'electron-ia32-release',
|
|
|
|
'electron-woa': 'electron-woa-release'
|
2018-07-09 19:29:44 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 21:04:50 +00:00
|
|
|
const circleCIJobs = [
|
2019-01-22 21:14:01 +00:00
|
|
|
'linux-arm-publish',
|
|
|
|
'linux-arm64-publish',
|
2018-09-27 14:58:57 +00:00
|
|
|
'linux-ia32-publish',
|
2019-01-31 17:59:32 +00:00
|
|
|
'linux-x64-publish',
|
|
|
|
'mas-publish',
|
|
|
|
'osx-publish'
|
2017-11-02 07:26:37 +00:00
|
|
|
]
|
|
|
|
|
2019-01-22 21:14:01 +00:00
|
|
|
const vstsArmJobs = [
|
|
|
|
'electron-arm-testing',
|
2019-08-21 21:37:30 +00:00
|
|
|
'electron-arm64-testing',
|
|
|
|
'electron-woa-testing'
|
2019-01-22 21:14:01 +00:00
|
|
|
]
|
2018-10-04 16:01:16 +00:00
|
|
|
|
2019-09-04 18:24:46 +00:00
|
|
|
let jobRequestedCount = 0
|
|
|
|
|
2017-11-16 21:04:50 +00:00
|
|
|
async function makeRequest (requestOptions, parseResponse) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
request(requestOptions, (err, res, body) => {
|
|
|
|
if (!err && res.statusCode >= 200 && res.statusCode < 300) {
|
|
|
|
if (parseResponse) {
|
|
|
|
const build = JSON.parse(body)
|
|
|
|
resolve(build)
|
|
|
|
} else {
|
|
|
|
resolve(body)
|
|
|
|
}
|
|
|
|
} else {
|
2018-08-21 18:39:51 +00:00
|
|
|
console.error('Error occurred while requesting:', requestOptions.url)
|
2017-11-16 21:04:50 +00:00
|
|
|
if (parseResponse) {
|
2018-08-21 18:39:51 +00:00
|
|
|
try {
|
2019-08-21 21:37:30 +00:00
|
|
|
console.log('Error: ', `(status ${res.statusCode})`, err || JSON.parse(res.body))
|
2018-08-21 18:39:51 +00:00
|
|
|
} catch (err) {
|
2019-08-21 21:37:30 +00:00
|
|
|
console.log('Error: ', `(status ${res.statusCode})`, res.body)
|
2018-08-21 18:39:51 +00:00
|
|
|
}
|
2017-11-16 21:04:50 +00:00
|
|
|
} else {
|
2019-08-21 21:37:30 +00:00
|
|
|
console.log('Error: ', `(status ${res.statusCode})`, err || res.body)
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
2017-11-23 21:42:31 +00:00
|
|
|
reject(err)
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-17 18:48:02 +00:00
|
|
|
async function circleCIcall (targetBranch, job, options) {
|
2017-11-03 06:51:40 +00:00
|
|
|
console.log(`Triggering CircleCI to run build job: ${job} on branch: ${targetBranch} with release flag.`)
|
2018-10-02 01:56:31 +00:00
|
|
|
const buildRequest = {
|
2019-09-17 18:48:02 +00:00
|
|
|
'branch': targetBranch,
|
|
|
|
'parameters': {
|
|
|
|
'run-lint': false,
|
|
|
|
'run-build-linux': false,
|
|
|
|
'run-build-mac': false
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-17 18:48:02 +00:00
|
|
|
if (options.ghRelease) {
|
|
|
|
buildRequest.parameters['upload-to-s3'] = '0'
|
|
|
|
} else {
|
|
|
|
buildRequest.parameters['upload-to-s3'] = '1'
|
2018-05-14 21:21:51 +00:00
|
|
|
}
|
2019-09-17 18:48:02 +00:00
|
|
|
buildRequest.parameters[`run-${job}`] = true
|
2019-09-04 18:24:46 +00:00
|
|
|
jobRequestedCount++
|
2019-09-17 18:48:02 +00:00
|
|
|
// The logic below expects that the CircleCI workflows for releases each
|
|
|
|
// contain only one job in order to maintain compatibility with sudowoodo.
|
|
|
|
// 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)
|
|
|
|
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)
|
|
|
|
if (workflowId === -1) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.log(`CircleCI release build workflow running at https://circleci.com/workflow-run/${workflowId} for ${job}.`)
|
|
|
|
const jobInfoUrl = `https://circleci.com/api/v2/workflow/${workflowId}/jobs`
|
|
|
|
const jobInfo = await circleCIRequest(jobInfoUrl, 'GET')
|
|
|
|
if (!jobInfo.items || jobInfo.items.length !== 1) {
|
|
|
|
console.log('Error retrieving job for workflow, response was:', jobInfo)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const jobUrl = `https://circleci.com/gh/electron/electron/${jobInfo.items[0].job_number}`
|
|
|
|
console.log(`CircleCI release build request for ${job} successful. Check ${jobUrl} for status.`)
|
|
|
|
} catch (err) {
|
|
|
|
console.log('Error calling CircleCI: ', err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getCircleCIWorkflowId (pipelineId) {
|
|
|
|
const pipelineInfoUrl = `https://circleci.com/api/v2/pipeline/${pipelineId}`
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
const pipelineInfo = await circleCIRequest(pipelineInfoUrl, 'GET')
|
|
|
|
switch (pipelineInfo.state) {
|
|
|
|
case 'created': {
|
|
|
|
if (pipelineInfo.workflows.length === 1) {
|
|
|
|
return pipelineInfo.workflows[0].id
|
|
|
|
}
|
|
|
|
console.log('Unxpected number of workflows, response was:', pipelineInfo)
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
case 'error': {
|
|
|
|
console.log('Error retrieving workflows, response was:', pipelineInfo)
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 5000))
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
async function circleCIRequest (url, method, requestBody) {
|
|
|
|
return makeRequest({
|
|
|
|
auth: {
|
|
|
|
username: process.env.CIRCLE_TOKEN,
|
|
|
|
password: ''
|
|
|
|
},
|
|
|
|
method,
|
|
|
|
url,
|
2017-11-03 06:51:40 +00:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Accept': 'application/json'
|
|
|
|
},
|
2019-09-17 18:48:02 +00:00
|
|
|
body: requestBody ? JSON.stringify(requestBody) : null
|
2017-11-16 21:04:50 +00:00
|
|
|
}, true).catch(err => {
|
|
|
|
console.log('Error calling CircleCI:', err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-05 17:57:47 +00:00
|
|
|
function buildAppVeyor (targetBranch, options) {
|
2018-07-09 19:29:44 +00:00
|
|
|
const validJobs = Object.keys(appVeyorJobs)
|
|
|
|
if (options.job) {
|
|
|
|
assert(validJobs.includes(options.job), `Unknown AppVeyor CI job name: ${options.job}. Valid values are: ${validJobs}.`)
|
2019-09-05 17:57:47 +00:00
|
|
|
callAppVeyor(targetBranch, options.job, options)
|
2018-07-09 19:29:44 +00:00
|
|
|
} else {
|
2019-09-05 17:57:47 +00:00
|
|
|
validJobs.forEach((job) => callAppVeyor(targetBranch, job, options))
|
2018-07-09 19:29:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function callAppVeyor (targetBranch, job, options) {
|
|
|
|
console.log(`Triggering AppVeyor to run build job: ${job} on branch: ${targetBranch} with release flag.`)
|
2018-09-27 05:38:06 +00:00
|
|
|
const environmentVariables = {
|
|
|
|
ELECTRON_RELEASE: 1
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
|
|
|
|
2018-09-27 05:38:06 +00:00
|
|
|
if (!options.ghRelease) {
|
|
|
|
environmentVariables.UPLOAD_TO_S3 = 1
|
2018-05-14 21:21:51 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 21:04:50 +00:00
|
|
|
const requestOpts = {
|
|
|
|
url: buildAppVeyorURL,
|
|
|
|
auth: {
|
2019-05-23 20:54:34 +00:00
|
|
|
bearer: process.env.APPVEYOR_CLOUD_TOKEN
|
2017-11-16 21:04:50 +00:00
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
2017-11-03 06:51:40 +00:00
|
|
|
body: JSON.stringify({
|
2019-05-23 20:54:34 +00:00
|
|
|
accountName: 'electron-bot',
|
2018-07-09 19:29:44 +00:00
|
|
|
projectSlug: appVeyorJobs[job],
|
2017-11-16 21:04:50 +00:00
|
|
|
branch: targetBranch,
|
|
|
|
environmentVariables
|
|
|
|
}),
|
|
|
|
method: 'POST'
|
|
|
|
}
|
2019-09-04 18:24:46 +00:00
|
|
|
jobRequestedCount++
|
2018-10-02 01:56:31 +00:00
|
|
|
const appVeyorResponse = await makeRequest(requestOpts, true).catch(err => {
|
2017-11-16 21:04:50 +00:00
|
|
|
console.log('Error calling AppVeyor:', err)
|
|
|
|
})
|
2019-05-23 20:54:34 +00:00
|
|
|
const buildUrl = `https://ci.appveyor.com/project/electron-bot/${appVeyorJobs[job]}/build/${appVeyorResponse.version}`
|
2018-07-09 19:29:44 +00:00
|
|
|
console.log(`AppVeyor release build request for ${job} successful. Check build status at ${buildUrl}`)
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 17:57:47 +00:00
|
|
|
function buildCircleCI (targetBranch, options) {
|
2018-05-14 21:21:51 +00:00
|
|
|
if (options.job) {
|
2018-07-09 19:29:44 +00:00
|
|
|
assert(circleCIJobs.includes(options.job), `Unknown CircleCI job name: ${options.job}. Valid values are: ${circleCIJobs}.`)
|
2019-09-17 18:48:02 +00:00
|
|
|
circleCIcall(targetBranch, options.job, options)
|
2017-11-16 21:04:50 +00:00
|
|
|
} else {
|
2019-09-17 18:48:02 +00:00
|
|
|
circleCIJobs.forEach((job) => circleCIcall(targetBranch, job, options))
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 20:11:26 +00:00
|
|
|
async function buildVSTS (targetBranch, options) {
|
2019-01-22 21:14:01 +00:00
|
|
|
if (options.armTest) {
|
|
|
|
assert(vstsArmJobs.includes(options.job), `Unknown VSTS CI arm test job name: ${options.job}. Valid values are: ${vstsArmJobs}.`)
|
2018-06-13 20:11:26 +00:00
|
|
|
}
|
2019-02-06 21:36:17 +00:00
|
|
|
|
2018-06-13 20:11:26 +00:00
|
|
|
console.log(`Triggering VSTS to run build on branch: ${targetBranch} with release flag.`)
|
2018-09-27 05:38:06 +00:00
|
|
|
const environmentVariables = {
|
|
|
|
ELECTRON_RELEASE: 1
|
|
|
|
}
|
2018-06-13 20:11:26 +00:00
|
|
|
|
2018-10-04 16:01:16 +00:00
|
|
|
if (options.armTest) {
|
2019-08-21 21:37:30 +00:00
|
|
|
if (options.circleBuildNum) {
|
|
|
|
environmentVariables.CIRCLE_BUILD_NUM = options.circleBuildNum
|
|
|
|
} else if (options.appveyorJobId) {
|
|
|
|
environmentVariables.APPVEYOR_JOB_ID = options.appveyorJobId
|
|
|
|
}
|
2018-10-04 16:01:16 +00:00
|
|
|
} else {
|
|
|
|
if (!options.ghRelease) {
|
|
|
|
environmentVariables.UPLOAD_TO_S3 = 1
|
|
|
|
}
|
2018-06-13 20:11:26 +00:00
|
|
|
}
|
|
|
|
|
2018-10-02 01:56:31 +00:00
|
|
|
const requestOpts = {
|
2018-06-13 20:11:26 +00:00
|
|
|
url: `${vstsURL}/definitions?api-version=4.1`,
|
|
|
|
auth: {
|
|
|
|
user: '',
|
|
|
|
password: process.env.VSTS_TOKEN
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}
|
2018-10-02 01:56:31 +00:00
|
|
|
const vstsResponse = await makeRequest(requestOpts, true).catch(err => {
|
2018-06-13 20:11:26 +00:00
|
|
|
console.log('Error calling VSTS to get build definitions:', err)
|
|
|
|
})
|
2019-02-06 21:36:17 +00:00
|
|
|
const buildsToRun = vstsResponse.value.filter(build => build.name === options.job)
|
2019-09-05 17:57:47 +00:00
|
|
|
buildsToRun.forEach((build) => callVSTSBuild(build, targetBranch, environmentVariables))
|
2018-06-13 20:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function callVSTSBuild (build, targetBranch, environmentVariables) {
|
2018-10-02 01:56:31 +00:00
|
|
|
const buildBody = {
|
2018-06-13 20:11:26 +00:00
|
|
|
definition: build,
|
2018-10-19 12:56:40 +00:00
|
|
|
sourceBranch: targetBranch,
|
|
|
|
priority: 'high'
|
2018-06-13 20:11:26 +00:00
|
|
|
}
|
|
|
|
if (Object.keys(environmentVariables).length !== 0) {
|
|
|
|
buildBody.parameters = JSON.stringify(environmentVariables)
|
|
|
|
}
|
2018-10-02 01:56:31 +00:00
|
|
|
const requestOpts = {
|
2018-06-13 20:11:26 +00:00
|
|
|
url: `${vstsURL}/builds?api-version=4.1`,
|
|
|
|
auth: {
|
|
|
|
user: '',
|
|
|
|
password: process.env.VSTS_TOKEN
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
|
|
|
body: JSON.stringify(buildBody),
|
|
|
|
method: 'POST'
|
|
|
|
}
|
2019-09-04 18:24:46 +00:00
|
|
|
jobRequestedCount++
|
2018-10-02 01:56:31 +00:00
|
|
|
const vstsResponse = await makeRequest(requestOpts, true).catch(err => {
|
2018-06-13 20:11:26 +00:00
|
|
|
console.log(`Error calling VSTS for job ${build.name}`, err)
|
|
|
|
})
|
|
|
|
console.log(`VSTS release build request for ${build.name} successful. Check ${vstsResponse._links.web.href} for status.`)
|
|
|
|
}
|
|
|
|
|
2019-09-05 17:57:47 +00:00
|
|
|
function runRelease (targetBranch, options) {
|
2017-11-16 21:04:50 +00:00
|
|
|
if (options.ci) {
|
|
|
|
switch (options.ci) {
|
|
|
|
case 'CircleCI': {
|
2019-09-05 17:57:47 +00:00
|
|
|
buildCircleCI(targetBranch, options)
|
2017-11-16 21:04:50 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
case 'AppVeyor': {
|
2019-09-05 17:57:47 +00:00
|
|
|
buildAppVeyor(targetBranch, options)
|
2017-11-16 21:04:50 +00:00
|
|
|
break
|
|
|
|
}
|
2018-06-13 20:11:26 +00:00
|
|
|
case 'VSTS': {
|
2019-09-05 17:57:47 +00:00
|
|
|
buildVSTS(targetBranch, options)
|
2018-06-13 20:11:26 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
console.log(`Error! Unknown CI: ${options.ci}.`)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-09-05 17:57:47 +00:00
|
|
|
buildCircleCI(targetBranch, options)
|
|
|
|
buildAppVeyor(targetBranch, options)
|
|
|
|
buildVSTS(targetBranch, options)
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
2019-09-05 17:57:47 +00:00
|
|
|
console.log(`${jobRequestedCount} jobs were requested.`)
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
2017-11-02 07:26:37 +00:00
|
|
|
|
2017-11-16 21:04:50 +00:00
|
|
|
module.exports = runRelease
|
2017-11-02 07:26:37 +00:00
|
|
|
|
2017-11-16 21:04:50 +00:00
|
|
|
if (require.main === module) {
|
2018-05-14 21:21:51 +00:00
|
|
|
const args = require('minimist')(process.argv.slice(2), {
|
2018-10-09 20:19:05 +00:00
|
|
|
boolean: ['ghRelease', 'armTest']
|
2018-05-14 21:21:51 +00:00
|
|
|
})
|
2017-11-16 21:04:50 +00:00
|
|
|
const targetBranch = args._[0]
|
|
|
|
if (args._.length < 1) {
|
|
|
|
console.log(`Trigger CI to build release builds of electron.
|
2018-10-04 16:01:16 +00:00
|
|
|
Usage: ci-release-build.js [--job=CI_JOB_NAME] [--ci=CircleCI|AppVeyor|VSTS]
|
2019-08-21 21:37:30 +00:00
|
|
|
[--ghRelease] [--armTest] [--circleBuildNum=xxx] [--appveyorJobId=xxx] TARGET_BRANCH
|
2017-11-16 21:04:50 +00:00
|
|
|
`)
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
runRelease(targetBranch, args)
|
2017-11-03 06:51:40 +00:00
|
|
|
}
|