1. #!/usr/bin/env node
    
  2. 
    
  3. 'use strict';
    
  4. 
    
  5. const commandLineArgs = require('command-line-args');
    
  6. const getBuildIdForCommit = require('./get-build-id-for-commit');
    
  7. const theme = require('../theme');
    
  8. const {logPromise} = require('../utils');
    
  9. 
    
  10. const paramDefinitions = [
    
  11.   {
    
  12.     name: 'build',
    
  13.     type: String,
    
  14.     description:
    
  15.       'CI build ID corresponding to the "process_artifacts_combined" task.',
    
  16.     defaultValue: null,
    
  17.   },
    
  18.   {
    
  19.     name: 'commit',
    
  20.     type: String,
    
  21.     description:
    
  22.       'GitHub commit SHA. When provided, automatically finds corresponding CI build.',
    
  23.     defaultValue: null,
    
  24.   },
    
  25.   {
    
  26.     name: 'skipTests',
    
  27.     type: Boolean,
    
  28.     description: 'Skip automated fixture tests.',
    
  29.     defaultValue: false,
    
  30.   },
    
  31.   {
    
  32.     name: 'releaseChannel',
    
  33.     alias: 'r',
    
  34.     type: String,
    
  35.     description: 'Release channel (stable, experimental, or latest)',
    
  36.   },
    
  37.   {
    
  38.     name: 'allowBrokenCI',
    
  39.     type: Boolean,
    
  40.     description:
    
  41.       'Continue even if CI is failing. Useful if you need to debug a broken build.',
    
  42.     defaultValue: false,
    
  43.   },
    
  44. ];
    
  45. 
    
  46. module.exports = async () => {
    
  47.   const params = commandLineArgs(paramDefinitions);
    
  48. 
    
  49.   const channel = params.releaseChannel;
    
  50.   if (
    
  51.     channel !== 'experimental' &&
    
  52.     channel !== 'stable' &&
    
  53.     channel !== 'latest'
    
  54.   ) {
    
  55.     console.error(
    
  56.       theme.error`Invalid release channel (-r) "${channel}". Must be "stable", "experimental", or "latest".`
    
  57.     );
    
  58.     process.exit(1);
    
  59.   }
    
  60. 
    
  61.   if (params.build === null && params.commit === null) {
    
  62.     console.error(
    
  63.       theme.error`Either a --commit or --build param must be specified.`
    
  64.     );
    
  65.     process.exit(1);
    
  66.   }
    
  67. 
    
  68.   try {
    
  69.     if (params.build === null) {
    
  70.       params.build = await logPromise(
    
  71.         getBuildIdForCommit(params.commit, params.allowBrokenCI),
    
  72.         theme`Getting build ID for commit "${params.commit}"`
    
  73.       );
    
  74.     }
    
  75.   } catch (error) {
    
  76.     console.error(theme.error(error));
    
  77.     process.exit(1);
    
  78.   }
    
  79. 
    
  80.   return params;
    
  81. };