/ script / vsts / upload-crash-reports.js
upload-crash-reports.js
 1  'use strict';
 2  
 3  const glob = require('glob');
 4  const uploadToS3 = require('./lib/upload-to-s3');
 5  
 6  const yargs = require('yargs');
 7  const argv = yargs
 8    .usage('Usage: $0 [options]')
 9    .help('help')
10    .describe(
11      'crash-report-path',
12      'The local path of a directory containing crash reports to upload'
13    )
14    .describe(
15      's3-path',
16      'Indicates the S3 path in which the crash reports should be uploaded'
17    )
18    .wrap(yargs.terminalWidth()).argv;
19  
20  async function uploadCrashReports() {
21    const crashesPath = argv.crashReportPath;
22    const crashes = glob.sync('/*.dmp', { root: crashesPath });
23    const bucketPath = argv.s3Path;
24  
25    if (crashes && crashes.length > 0) {
26      console.log(
27        `Uploading ${
28          crashes.length
29        } private crash reports to S3 under '${bucketPath}'`
30      );
31  
32      await uploadToS3(
33        process.env.ATOM_RELEASES_S3_KEY,
34        process.env.ATOM_RELEASES_S3_SECRET,
35        process.env.ATOM_RELEASES_S3_BUCKET,
36        bucketPath,
37        crashes,
38        'private'
39      );
40    }
41  }
42  
43  // Wrap the call the async function and catch errors from its promise because
44  // Node.js doesn't yet allow use of await at the script scope
45  uploadCrashReports().catch(err => {
46    console.error('An error occurred while uploading crash reports:\n\n', err);
47    process.exit(1);
48  });