Skip to content

Commit

Permalink
[ci] Use yargs to parse args to download-experimental-build
Browse files Browse the repository at this point in the history
ghstack-source-id: 0b222cf61368f1cafdd7b44cdb1a574228cbe403
Pull Request resolved: facebook#30375
  • Loading branch information
poteto committed Jul 18, 2024
1 parent 21be03b commit eed9ca2
Showing 1 changed file with 54 additions and 16 deletions.
70 changes: 54 additions & 16 deletions scripts/release/download-experimental-build-ghaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,66 @@

'use strict';

const {join} = require('path');
const {
addDefaultParamValue,
getPublicPackages,
handleError,
} = require('./utils');
const {join, relative} = require('path');
const {getPublicPackages, handleError} = require('./utils');
const yargs = require('yargs');
const clear = require('clear');
const theme = require('./theme');

const downloadBuildArtifacts = require('./shared-commands/download-build-artifacts');
const parseParams = require('./shared-commands/parse-params');
const printSummary = require('./download-experimental-build-commands/print-summary');
const argv = yargs.wrap(yargs.terminalWidth()).options({
releaseChannel: {
alias: 'r',
describe: 'Download the given release channel.',
requiresArg: true,
type: 'string',
choices: ['experimental', 'stable'],
default: 'experimental',
},
commit: {
alias: 'c',
describe: 'Commit hash to download.',
requiresArg: true,
type: 'string',
},
skipTests: {
requiresArg: false,
type: 'boolean',
default: false,
},
allowBrokenCI: {
requiresArg: false,
type: 'boolean',
default: false,
},
}).argv;

// Inlined from scripts/release/download-experimental-build-commands/print-summary.js
function printSummary(commit) {
const commandPath = relative(
process.env.PWD,
join(__dirname, '../download-experimental-build-ghaction.js')
);

clear();

const message = theme`
{caution An experimental build has been downloaded!}
You can download this build again by running:
{path ${commandPath}} --commit={commit ${commit}}
`;

console.log(message.replace(/\n +/g, '\n').trim());
}

const run = async () => {
try {
addDefaultParamValue('-r', '--releaseChannel', 'experimental');

const params = await parseParams();
params.cwd = join(__dirname, '..', '..');
params.packages = await getPublicPackages(true);
argv.cwd = join(__dirname, '..', '..');
argv.packages = await getPublicPackages(true);

await downloadBuildArtifacts(params);
console.log(argv);

printSummary(params);
printSummary(argv.commit);
} catch (error) {
handleError(error);
}
Expand Down

0 comments on commit eed9ca2

Please sign in to comment.