2018-07-11 18:02:03 +00:00
|
|
|
require('dotenv-safe').load()
|
|
|
|
|
2017-11-02 07:26:37 +00:00
|
|
|
const assert = require('assert')
|
|
|
|
const request = require('request')
|
2017-11-16 21:04:50 +00:00
|
|
|
const buildAppVeyorURL = 'https://windows-ci.electronjs.org/api/builds'
|
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 = {
|
|
|
|
'electron-x64': 'electron',
|
|
|
|
'electron-ia32': 'electron-39ng6'
|
|
|
|
}
|
|
|
|
|
2017-11-16 21:04:50 +00:00
|
|
|
const circleCIJobs = [
|
2017-11-22 02:27:21 +00:00
|
|
|
'electron-linux-arm',
|
2017-11-02 07:26:37 +00:00
|
|
|
'electron-linux-arm64',
|
|
|
|
'electron-linux-ia32',
|
2018-05-14 21:21:51 +00:00
|
|
|
// 'electron-linux-mips64el',
|
2017-11-22 02:27:21 +00:00
|
|
|
'electron-linux-x64'
|
2017-11-02 07:26:37 +00:00
|
|
|
]
|
|
|
|
|
2018-06-13 20:11:26 +00:00
|
|
|
const vstsJobs = [
|
|
|
|
'electron-release-mas-x64',
|
|
|
|
'electron-release-osx-x64'
|
|
|
|
]
|
|
|
|
|
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 {
|
|
|
|
console.log('Error: ', `(status ${res.statusCode})`, err || JSON.parse(res.body), requestOptions)
|
|
|
|
} catch (err) {
|
|
|
|
console.log('Error: ', `(status ${res.statusCode})`, err || res.body, requestOptions)
|
|
|
|
}
|
2017-11-16 21:04:50 +00:00
|
|
|
} else {
|
|
|
|
console.log('Error: ', `(status ${res.statusCode})`, err || res.body, requestOptions)
|
|
|
|
}
|
2017-11-23 21:42:31 +00:00
|
|
|
reject(err)
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-05-14 21:21:51 +00:00
|
|
|
async function circleCIcall (buildUrl, 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.`)
|
2017-11-16 21:04:50 +00:00
|
|
|
let buildRequest = {
|
|
|
|
'build_parameters': {
|
|
|
|
'CIRCLE_JOB': job
|
|
|
|
}
|
|
|
|
}
|
2017-11-03 06:51:40 +00:00
|
|
|
|
2018-05-14 21:21:51 +00:00
|
|
|
if (options.ghRelease) {
|
2017-11-16 21:04:50 +00:00
|
|
|
buildRequest.build_parameters.ELECTRON_RELEASE = 1
|
|
|
|
} else {
|
|
|
|
buildRequest.build_parameters.RUN_RELEASE_BUILD = 'true'
|
|
|
|
}
|
|
|
|
|
2018-05-14 21:21:51 +00:00
|
|
|
if (options.automaticRelease) {
|
|
|
|
buildRequest.build_parameters.AUTO_RELEASE = 'true'
|
|
|
|
}
|
|
|
|
|
2017-11-16 21:04:50 +00:00
|
|
|
let circleResponse = await makeRequest({
|
2017-11-03 06:51:40 +00:00
|
|
|
method: 'POST',
|
|
|
|
url: buildUrl,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
'Accept': 'application/json'
|
|
|
|
},
|
2017-11-16 21:04:50 +00:00
|
|
|
body: JSON.stringify(buildRequest)
|
|
|
|
}, true).catch(err => {
|
|
|
|
console.log('Error calling CircleCI:', err)
|
|
|
|
})
|
2018-06-13 20:11:26 +00:00
|
|
|
console.log(`CircleCI release build request for ${job} successful. Check ${circleResponse.build_url} for status.`)
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 19:29:44 +00:00
|
|
|
function buildAppVeyor (targetBranch, options) {
|
|
|
|
const validJobs = Object.keys(appVeyorJobs)
|
|
|
|
if (options.job) {
|
|
|
|
assert(validJobs.includes(options.job), `Unknown AppVeyor CI job name: ${options.job}. Valid values are: ${validJobs}.`)
|
|
|
|
callAppVeyor(targetBranch, options.job, options)
|
|
|
|
} else {
|
|
|
|
validJobs.forEach((job) => callAppVeyor(targetBranch, job, options))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function callAppVeyor (targetBranch, job, options) {
|
|
|
|
console.log(`Triggering AppVeyor to run build job: ${job} on branch: ${targetBranch} with release flag.`)
|
2017-11-16 21:04:50 +00:00
|
|
|
let environmentVariables = {}
|
|
|
|
|
2018-05-14 21:21:51 +00:00
|
|
|
if (options.ghRelease) {
|
2017-11-16 21:04:50 +00:00
|
|
|
environmentVariables.ELECTRON_RELEASE = 1
|
|
|
|
} else {
|
|
|
|
environmentVariables.RUN_RELEASE_BUILD = 'true'
|
|
|
|
}
|
|
|
|
|
2018-05-14 21:21:51 +00:00
|
|
|
if (options.automaticRelease) {
|
|
|
|
environmentVariables.AUTO_RELEASE = 'true'
|
|
|
|
}
|
|
|
|
|
2017-11-16 21:04:50 +00:00
|
|
|
const requestOpts = {
|
|
|
|
url: buildAppVeyorURL,
|
|
|
|
auth: {
|
|
|
|
bearer: process.env.APPVEYOR_TOKEN
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
},
|
2017-11-03 06:51:40 +00:00
|
|
|
body: JSON.stringify({
|
2017-11-16 21:04:50 +00:00
|
|
|
accountName: 'AppVeyor',
|
2018-07-09 19:29:44 +00:00
|
|
|
projectSlug: appVeyorJobs[job],
|
2017-11-16 21:04:50 +00:00
|
|
|
branch: targetBranch,
|
|
|
|
environmentVariables
|
|
|
|
}),
|
|
|
|
method: 'POST'
|
|
|
|
}
|
|
|
|
let appVeyorResponse = await makeRequest(requestOpts, true).catch(err => {
|
|
|
|
console.log('Error calling AppVeyor:', err)
|
|
|
|
})
|
2018-07-12 12:53:07 +00:00
|
|
|
const buildUrl = `https://windows-ci.electronjs.org/project/AppVeyor/${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
|
|
|
}
|
|
|
|
|
2018-05-14 21:21:51 +00:00
|
|
|
function buildCircleCI (targetBranch, options) {
|
2017-11-16 21:04:50 +00:00
|
|
|
const circleBuildUrl = `https://circleci.com/api/v1.1/project/github/electron/electron/tree/${targetBranch}?circle-token=${process.env.CIRCLE_TOKEN}`
|
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}.`)
|
2018-05-14 21:21:51 +00:00
|
|
|
circleCIcall(circleBuildUrl, targetBranch, options.job, options)
|
2017-11-16 21:04:50 +00:00
|
|
|
} else {
|
2018-05-14 21:21:51 +00:00
|
|
|
circleCIJobs.forEach((job) => circleCIcall(circleBuildUrl, targetBranch, job, options))
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-13 20:11:26 +00:00
|
|
|
async function buildVSTS (targetBranch, options) {
|
|
|
|
if (options.job) {
|
2018-07-09 19:29:44 +00:00
|
|
|
assert(vstsJobs.includes(options.job), `Unknown VSTS CI job name: ${options.job}. Valid values are: ${vstsJobs}.`)
|
2018-06-13 20:11:26 +00:00
|
|
|
}
|
|
|
|
console.log(`Triggering VSTS to run build on branch: ${targetBranch} with release flag.`)
|
|
|
|
let environmentVariables = {}
|
|
|
|
|
|
|
|
if (!options.ghRelease) {
|
|
|
|
environmentVariables.UPLOAD_TO_S3 = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.automaticRelease) {
|
|
|
|
environmentVariables.AUTO_RELEASE = 'true'
|
|
|
|
}
|
|
|
|
|
|
|
|
let requestOpts = {
|
|
|
|
url: `${vstsURL}/definitions?api-version=4.1`,
|
|
|
|
auth: {
|
|
|
|
user: '',
|
|
|
|
password: process.env.VSTS_TOKEN
|
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let vstsResponse = await makeRequest(requestOpts, true).catch(err => {
|
|
|
|
console.log('Error calling VSTS to get build definitions:', err)
|
|
|
|
})
|
|
|
|
let buildsToRun = []
|
|
|
|
if (options.job) {
|
|
|
|
buildsToRun = vstsResponse.value.filter(build => build.name === options.job)
|
|
|
|
} else {
|
|
|
|
buildsToRun = vstsResponse.value.filter(build => vstsJobs.includes(build.name))
|
|
|
|
}
|
|
|
|
buildsToRun.forEach((build) => callVSTSBuild(build, targetBranch, environmentVariables))
|
|
|
|
}
|
|
|
|
|
|
|
|
async function callVSTSBuild (build, targetBranch, environmentVariables) {
|
|
|
|
let buildBody = {
|
|
|
|
definition: build,
|
|
|
|
sourceBranch: targetBranch
|
|
|
|
}
|
|
|
|
if (Object.keys(environmentVariables).length !== 0) {
|
|
|
|
buildBody.parameters = JSON.stringify(environmentVariables)
|
|
|
|
}
|
|
|
|
let requestOpts = {
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
let vstsResponse = await makeRequest(requestOpts, true).catch(err => {
|
|
|
|
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.`)
|
|
|
|
}
|
|
|
|
|
2017-11-16 21:04:50 +00:00
|
|
|
function runRelease (targetBranch, options) {
|
|
|
|
if (options.ci) {
|
|
|
|
switch (options.ci) {
|
|
|
|
case 'CircleCI': {
|
2018-05-14 21:21:51 +00:00
|
|
|
buildCircleCI(targetBranch, options)
|
2017-11-16 21:04:50 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
case 'AppVeyor': {
|
2018-05-14 21:21:51 +00:00
|
|
|
buildAppVeyor(targetBranch, options)
|
2017-11-16 21:04:50 +00:00
|
|
|
break
|
|
|
|
}
|
2018-06-13 20:11:26 +00:00
|
|
|
case 'VSTS': {
|
|
|
|
buildVSTS(targetBranch, options)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
console.log(`Error! Unknown CI: ${options.ci}.`)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2017-11-16 21:04:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-14 21:21:51 +00:00
|
|
|
buildCircleCI(targetBranch, options)
|
|
|
|
buildAppVeyor(targetBranch, options)
|
2018-06-13 20:11:26 +00:00
|
|
|
buildVSTS(targetBranch, options)
|
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), {
|
|
|
|
boolean: ['ghRelease', 'automaticRelease']
|
|
|
|
})
|
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-06-13 20:11:26 +00:00
|
|
|
Usage: ci-release-build.js [--job=CI_JOB_NAME] [--ci=CircleCI|AppVeyor|VSTS] [--ghRelease] [--automaticRelease] TARGET_BRANCH
|
2017-11-16 21:04:50 +00:00
|
|
|
`)
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
runRelease(targetBranch, args)
|
2017-11-03 06:51:40 +00:00
|
|
|
}
|