build: enable JS semicolons (#22783)
This commit is contained in:
parent
24e21467b9
commit
5d657dece4
354 changed files with 21512 additions and 21510 deletions
|
@ -1,38 +1,38 @@
|
|||
const args = require('minimist')(process.argv.slice(2))
|
||||
const nugget = require('nugget')
|
||||
const request = require('request')
|
||||
const args = require('minimist')(process.argv.slice(2));
|
||||
const nugget = require('nugget');
|
||||
const request = require('request');
|
||||
|
||||
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)
|
||||
const build = JSON.parse(body);
|
||||
resolve(build);
|
||||
} else {
|
||||
resolve(body)
|
||||
resolve(body);
|
||||
}
|
||||
} else {
|
||||
if (args.verbose) {
|
||||
console.error('Error occurred while requesting:', requestOptions.url)
|
||||
console.error('Error occurred while requesting:', requestOptions.url);
|
||||
if (parseResponse) {
|
||||
try {
|
||||
console.log('Error: ', `(status ${res.statusCode})`, err || JSON.parse(res.body), requestOptions)
|
||||
console.log('Error: ', `(status ${res.statusCode})`, err || JSON.parse(res.body), requestOptions);
|
||||
} catch (err) {
|
||||
console.log('Error: ', `(status ${res.statusCode})`, err || res.body, requestOptions)
|
||||
console.log('Error: ', `(status ${res.statusCode})`, err || res.body, requestOptions);
|
||||
}
|
||||
} else {
|
||||
console.log('Error: ', `(status ${res.statusCode})`, err || res.body, requestOptions)
|
||||
console.log('Error: ', `(status ${res.statusCode})`, err || res.body, requestOptions);
|
||||
}
|
||||
}
|
||||
reject(err)
|
||||
reject(err);
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function downloadArtifact (name, buildNum, dest) {
|
||||
const circleArtifactUrl = `https://circleci.com/api/v1.1/project/github/electron/electron/${args.buildNum}/artifacts?circle-token=${process.env.CIRCLE_TOKEN}`
|
||||
const circleArtifactUrl = `https://circleci.com/api/v1.1/project/github/electron/electron/${args.buildNum}/artifacts?circle-token=${process.env.CIRCLE_TOKEN}`;
|
||||
const artifacts = await makeRequest({
|
||||
method: 'GET',
|
||||
url: circleArtifactUrl,
|
||||
|
@ -42,47 +42,47 @@ async function downloadArtifact (name, buildNum, dest) {
|
|||
}
|
||||
}, true).catch(err => {
|
||||
if (args.verbose) {
|
||||
console.log('Error calling CircleCI:', err)
|
||||
console.log('Error calling CircleCI:', err);
|
||||
} else {
|
||||
console.error('Error calling CircleCI to get artifact details')
|
||||
console.error('Error calling CircleCI to get artifact details');
|
||||
}
|
||||
})
|
||||
});
|
||||
const artifactToDownload = artifacts.find(artifact => {
|
||||
return (artifact.path === name)
|
||||
})
|
||||
return (artifact.path === name);
|
||||
});
|
||||
if (!artifactToDownload) {
|
||||
console.log(`Could not find artifact called ${name} to download for build #${buildNum}.`)
|
||||
process.exit(1)
|
||||
console.log(`Could not find artifact called ${name} to download for build #${buildNum}.`);
|
||||
process.exit(1);
|
||||
} else {
|
||||
console.log(`Downloading ${artifactToDownload.url}.`)
|
||||
let downloadError = false
|
||||
console.log(`Downloading ${artifactToDownload.url}.`);
|
||||
let downloadError = false;
|
||||
await downloadWithRetry(artifactToDownload.url, dest).catch(err => {
|
||||
if (args.verbose) {
|
||||
console.log(`${artifactToDownload.url} could not be successfully downloaded. Error was:`, err)
|
||||
console.log(`${artifactToDownload.url} could not be successfully downloaded. Error was:`, err);
|
||||
} else {
|
||||
console.log(`${artifactToDownload.url} could not be successfully downloaded.`)
|
||||
console.log(`${artifactToDownload.url} could not be successfully downloaded.`);
|
||||
}
|
||||
downloadError = true
|
||||
})
|
||||
downloadError = true;
|
||||
});
|
||||
if (!downloadError) {
|
||||
console.log(`Successfully downloaded ${name}.`)
|
||||
console.log(`Successfully downloaded ${name}.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadWithRetry (url, directory) {
|
||||
let lastError
|
||||
const downloadURL = `${url}?circle-token=${process.env.CIRCLE_TOKEN}`
|
||||
let lastError;
|
||||
const downloadURL = `${url}?circle-token=${process.env.CIRCLE_TOKEN}`;
|
||||
for (let i = 0; i < 5; i++) {
|
||||
console.log(`Attempting to download ${url} - attempt #${(i + 1)}`)
|
||||
console.log(`Attempting to download ${url} - attempt #${(i + 1)}`);
|
||||
try {
|
||||
return await downloadFile(downloadURL, directory)
|
||||
return await downloadFile(downloadURL, directory);
|
||||
} catch (err) {
|
||||
lastError = err
|
||||
await new Promise((resolve, reject) => setTimeout(resolve, 30000))
|
||||
lastError = err;
|
||||
await new Promise((resolve, reject) => setTimeout(resolve, 30000));
|
||||
}
|
||||
}
|
||||
throw lastError
|
||||
throw lastError;
|
||||
}
|
||||
|
||||
function downloadFile (url, directory) {
|
||||
|
@ -90,21 +90,21 @@ function downloadFile (url, directory) {
|
|||
const nuggetOpts = {
|
||||
dir: directory,
|
||||
quiet: args.verbose
|
||||
}
|
||||
};
|
||||
nugget(url, nuggetOpts, (err) => {
|
||||
if (err) {
|
||||
reject(err)
|
||||
reject(err);
|
||||
} else {
|
||||
resolve()
|
||||
resolve();
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (!args.name || !args.buildNum || !args.dest) {
|
||||
console.log(`Download CircleCI artifacts.
|
||||
Usage: download-circleci-artifacts.js [--buildNum=CIRCLE_BUILD_NUMBER] [--name=artifactName] [--dest] [--verbose]`)
|
||||
process.exit(0)
|
||||
Usage: download-circleci-artifacts.js [--buildNum=CIRCLE_BUILD_NUMBER] [--name=artifactName] [--dest] [--verbose]`);
|
||||
process.exit(0);
|
||||
} else {
|
||||
downloadArtifact(args.name, args.buildNum, args.dest)
|
||||
downloadArtifact(args.name, args.buildNum, args.dest);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue