
* build: add WOA release to list of releases * Add job count info for sudowoodo * Add verification of all assets * Fix linting and add logic to wait before printing out results
260 lines
7.9 KiB
JavaScript
260 lines
7.9 KiB
JavaScript
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 vstsURL = 'https://github.visualstudio.com/electron/_apis/build'
|
|
|
|
const appVeyorJobs = {
|
|
'electron-x64': 'electron-x64-release',
|
|
'electron-ia32': 'electron-ia32-release',
|
|
'electron-woa': 'electron-woa-release'
|
|
}
|
|
|
|
const circleCIJobs = [
|
|
'linux-arm-publish',
|
|
'linux-arm64-publish',
|
|
'linux-ia32-publish',
|
|
'linux-x64-publish',
|
|
'mas-publish',
|
|
'osx-publish'
|
|
]
|
|
|
|
const vstsArmJobs = [
|
|
'electron-arm-testing',
|
|
'electron-arm64-testing',
|
|
'electron-woa-testing'
|
|
]
|
|
|
|
let jobRequestedCount = 0
|
|
let jobSuccessfulCount = 0
|
|
|
|
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 {
|
|
console.error('Error occurred while requesting:', requestOptions.url)
|
|
if (parseResponse) {
|
|
try {
|
|
console.log('Error: ', `(status ${res.statusCode})`, err || JSON.parse(res.body))
|
|
} catch (err) {
|
|
console.log('Error: ', `(status ${res.statusCode})`, res.body)
|
|
}
|
|
} else {
|
|
console.log('Error: ', `(status ${res.statusCode})`, err || res.body)
|
|
}
|
|
reject(err)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
async function circleCIcall (buildUrl, targetBranch, job, options) {
|
|
console.log(`Triggering CircleCI to run build job: ${job} on branch: ${targetBranch} with release flag.`)
|
|
const buildRequest = {
|
|
'build_parameters': {
|
|
'CIRCLE_JOB': job
|
|
}
|
|
}
|
|
|
|
if (!options.ghRelease) {
|
|
buildRequest.build_parameters.UPLOAD_TO_S3 = 1
|
|
}
|
|
jobRequestedCount++
|
|
const circleResponse = await makeRequest({
|
|
method: 'POST',
|
|
url: buildUrl,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/json'
|
|
},
|
|
body: JSON.stringify(buildRequest)
|
|
}, true).catch(err => {
|
|
console.log('Error calling CircleCI:', err)
|
|
})
|
|
jobSuccessfulCount++
|
|
console.log(`CircleCI release build request for ${job} successful. Check ${circleResponse.build_url} for status.`)
|
|
}
|
|
|
|
async 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}.`)
|
|
await callAppVeyor(targetBranch, options.job, options)
|
|
} else {
|
|
const appVeyorCalls = []
|
|
validJobs.forEach((job) => appVeyorCalls.push(callAppVeyor(targetBranch, job, options)))
|
|
await Promise.all(appVeyorCalls)
|
|
}
|
|
}
|
|
|
|
async function callAppVeyor (targetBranch, job, options) {
|
|
console.log(`Triggering AppVeyor to run build job: ${job} on branch: ${targetBranch} with release flag.`)
|
|
const environmentVariables = {
|
|
ELECTRON_RELEASE: 1
|
|
}
|
|
|
|
if (!options.ghRelease) {
|
|
environmentVariables.UPLOAD_TO_S3 = 1
|
|
}
|
|
|
|
const requestOpts = {
|
|
url: buildAppVeyorURL,
|
|
auth: {
|
|
bearer: process.env.APPVEYOR_CLOUD_TOKEN
|
|
},
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
accountName: 'electron-bot',
|
|
projectSlug: appVeyorJobs[job],
|
|
branch: targetBranch,
|
|
environmentVariables
|
|
}),
|
|
method: 'POST'
|
|
}
|
|
jobRequestedCount++
|
|
const appVeyorResponse = await makeRequest(requestOpts, true).catch(err => {
|
|
console.log('Error calling AppVeyor:', err)
|
|
})
|
|
jobSuccessfulCount++
|
|
const buildUrl = `https://ci.appveyor.com/project/electron-bot/${appVeyorJobs[job]}/build/${appVeyorResponse.version}`
|
|
console.log(`AppVeyor release build request for ${job} successful. Check build status at ${buildUrl}`)
|
|
}
|
|
|
|
async function buildCircleCI (targetBranch, options) {
|
|
const circleBuildUrl = `https://circleci.com/api/v1.1/project/github/electron/electron/tree/${targetBranch}?circle-token=${process.env.CIRCLE_TOKEN}`
|
|
if (options.job) {
|
|
assert(circleCIJobs.includes(options.job), `Unknown CircleCI job name: ${options.job}. Valid values are: ${circleCIJobs}.`)
|
|
await circleCIcall(circleBuildUrl, targetBranch, options.job, options)
|
|
} else {
|
|
const circleCalls = []
|
|
circleCIJobs.forEach((job) => circleCalls.push(circleCIcall(circleBuildUrl, targetBranch, job, options)))
|
|
await Promise.all(circleCalls)
|
|
}
|
|
}
|
|
|
|
async function buildVSTS (targetBranch, options) {
|
|
if (options.armTest) {
|
|
assert(vstsArmJobs.includes(options.job), `Unknown VSTS CI arm test job name: ${options.job}. Valid values are: ${vstsArmJobs}.`)
|
|
}
|
|
|
|
console.log(`Triggering VSTS to run build on branch: ${targetBranch} with release flag.`)
|
|
const environmentVariables = {
|
|
ELECTRON_RELEASE: 1
|
|
}
|
|
|
|
if (options.armTest) {
|
|
if (options.circleBuildNum) {
|
|
environmentVariables.CIRCLE_BUILD_NUM = options.circleBuildNum
|
|
} else if (options.appveyorJobId) {
|
|
environmentVariables.APPVEYOR_JOB_ID = options.appveyorJobId
|
|
}
|
|
} else {
|
|
if (!options.ghRelease) {
|
|
environmentVariables.UPLOAD_TO_S3 = 1
|
|
}
|
|
}
|
|
|
|
const requestOpts = {
|
|
url: `${vstsURL}/definitions?api-version=4.1`,
|
|
auth: {
|
|
user: '',
|
|
password: process.env.VSTS_TOKEN
|
|
},
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
}
|
|
const vstsResponse = await makeRequest(requestOpts, true).catch(err => {
|
|
console.log('Error calling VSTS to get build definitions:', err)
|
|
})
|
|
const buildsToRun = vstsResponse.value.filter(build => build.name === options.job)
|
|
const vstsJobs = []
|
|
buildsToRun.forEach((build) => vstsJobs.push(callVSTSBuild(build, targetBranch, environmentVariables)))
|
|
await Promise.all(vstsJobs)
|
|
}
|
|
|
|
async function callVSTSBuild (build, targetBranch, environmentVariables) {
|
|
const buildBody = {
|
|
definition: build,
|
|
sourceBranch: targetBranch,
|
|
priority: 'high'
|
|
}
|
|
if (Object.keys(environmentVariables).length !== 0) {
|
|
buildBody.parameters = JSON.stringify(environmentVariables)
|
|
}
|
|
const 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'
|
|
}
|
|
jobRequestedCount++
|
|
const vstsResponse = await makeRequest(requestOpts, true).catch(err => {
|
|
console.log(`Error calling VSTS for job ${build.name}`, err)
|
|
})
|
|
jobSuccessfulCount++
|
|
console.log(`VSTS release build request for ${build.name} successful. Check ${vstsResponse._links.web.href} for status.`)
|
|
}
|
|
|
|
async function runRelease (targetBranch, options) {
|
|
if (options.ci) {
|
|
switch (options.ci) {
|
|
case 'CircleCI': {
|
|
await buildCircleCI(targetBranch, options)
|
|
break
|
|
}
|
|
case 'AppVeyor': {
|
|
await buildAppVeyor(targetBranch, options)
|
|
break
|
|
}
|
|
case 'VSTS': {
|
|
await buildVSTS(targetBranch, options)
|
|
break
|
|
}
|
|
default: {
|
|
console.log(`Error! Unknown CI: ${options.ci}.`)
|
|
process.exit(1)
|
|
}
|
|
}
|
|
} else {
|
|
const jobQueue = []
|
|
jobQueue.push(buildCircleCI(targetBranch, options))
|
|
jobQueue.push(buildAppVeyor(targetBranch, options))
|
|
jobQueue.push(buildVSTS(targetBranch, options))
|
|
await Promise.all(jobQueue)
|
|
}
|
|
console.log(`${jobRequestedCount} jobs were requested. ${jobSuccessfulCount} succeeded.`)
|
|
}
|
|
|
|
module.exports = runRelease
|
|
|
|
if (require.main === module) {
|
|
const args = require('minimist')(process.argv.slice(2), {
|
|
boolean: ['ghRelease', 'armTest']
|
|
})
|
|
const targetBranch = args._[0]
|
|
if (args._.length < 1) {
|
|
console.log(`Trigger CI to build release builds of electron.
|
|
Usage: ci-release-build.js [--job=CI_JOB_NAME] [--ci=CircleCI|AppVeyor|VSTS]
|
|
[--ghRelease] [--armTest] [--circleBuildNum=xxx] [--appveyorJobId=xxx] TARGET_BRANCH
|
|
`)
|
|
process.exit(0)
|
|
}
|
|
runRelease(targetBranch, args)
|
|
}
|