diff --git a/scripts/release/publish-commands/confirm-version-and-tags.js b/scripts/release/publish-commands/confirm-version-and-tags.js index bea395fba85cf..6900878da02f6 100644 --- a/scripts/release/publish-commands/confirm-version-and-tags.js +++ b/scripts/release/publish-commands/confirm-version-and-tags.js @@ -8,7 +8,7 @@ const {join} = require('path'); const {confirm} = require('../utils'); const theme = require('../theme'); -const run = async ({cwd, packages, tags}) => { +const run = async ({cwd, packages, tags, ci}) => { clear(); if (tags.length === 0) { @@ -40,7 +40,9 @@ const run = async ({cwd, packages, tags}) => { ); } - await confirm('Do you want to proceed?'); + if (!ci) { + await confirm('Do you want to proceed?'); + } clear(); }; diff --git a/scripts/release/publish-commands/parse-params.js b/scripts/release/publish-commands/parse-params.js index 05194fbe2c07c..03b8be209d549 100644 --- a/scripts/release/publish-commands/parse-params.js +++ b/scripts/release/publish-commands/parse-params.js @@ -26,6 +26,12 @@ const paramDefinitions = [ description: 'Packages to exclude from publishing', defaultValue: [], }, + { + name: 'ci', + type: Boolean, + description: 'Run in automated environment, without interactive prompts.', + defaultValue: false, + }, ]; module.exports = () => { @@ -40,7 +46,7 @@ module.exports = () => { case 'untagged': break; default: - console.error('Unknown tag: "' + params.tag + '"'); + console.error('Unsupported tag: "' + tag + '"'); process.exit(1); break; } diff --git a/scripts/release/publish-commands/publish-to-npm.js b/scripts/release/publish-commands/publish-to-npm.js index 71c347e4cc473..28035b0521073 100644 --- a/scripts/release/publish-commands/publish-to-npm.js +++ b/scripts/release/publish-commands/publish-to-npm.js @@ -8,7 +8,7 @@ const {join} = require('path'); const {confirm, execRead} = require('../utils'); const theme = require('../theme'); -const run = async ({cwd, dry, tags}, packageName, otp) => { +const run = async ({cwd, dry, tags, ci}, packageName, otp) => { const packagePath = join(cwd, 'build/node_modules', packageName); const {version} = readJsonSync(join(packagePath, 'package.json')); @@ -21,42 +21,74 @@ const run = async ({cwd, dry, tags}, packageName, otp) => { console.log( theme`{package ${packageName}} {version ${version}} has already been published.` ); - await confirm('Is this expected?'); + if (!ci) { + await confirm('Is this expected?'); + } } else { console.log(theme`{spinnerSuccess ✓} Publishing {package ${packageName}}`); // Publish the package and tag it. if (!dry) { - await exec(`npm publish --tag=${tags[0]} --otp=${otp}`, { - cwd: packagePath, - }); + if (!ci) { + await exec(`npm publish --tag=${tags[0]} --otp=${otp}`, { + cwd: packagePath, + }); + console.log(theme.command(` cd ${packagePath}`)); + console.log( + theme.command(` npm publish --tag=${tags[0]} --otp=${otp}`) + ); + } else { + await exec(`npm publish --tag=${tags[0]}`, { + cwd: packagePath, + }); + console.log(theme.command(` cd ${packagePath}`)); + console.log(theme.command(` npm publish --tag=${tags[0]}`)); + } } - console.log(theme.command(` cd ${packagePath}`)); - console.log(theme.command(` npm publish --tag=${tags[0]} --otp=${otp}`)); for (let j = 1; j < tags.length; j++) { if (!dry) { - await exec( - `npm dist-tag add ${packageName}@${version} ${tags[j]} --otp=${otp}`, - {cwd: packagePath} - ); + if (!ci) { + await exec( + `npm dist-tag add ${packageName}@${version} ${tags[j]} --otp=${otp}`, + {cwd: packagePath} + ); + console.log( + theme.command( + ` npm dist-tag add ${packageName}@${version} ${tags[j]} --otp=${otp}` + ) + ); + } else { + await exec(`npm dist-tag add ${packageName}@${version} ${tags[j]}`, { + cwd: packagePath, + }); + console.log( + theme.command( + ` npm dist-tag add ${packageName}@${version} ${tags[j]}` + ) + ); + } } - console.log( - theme.command( - ` npm dist-tag add ${packageName}@${version} ${tags[j]} --otp=${otp}` - ) - ); } if (tags.includes('untagged')) { // npm doesn't let us publish without a tag at all, // so for one-off publishes we clean it up ourselves. if (!dry) { - await exec(`npm dist-tag rm ${packageName} untagged --otp=${otp}`); + if (!ci) { + await exec(`npm dist-tag rm ${packageName} untagged --otp=${otp}`); + console.log( + theme.command( + ` npm dist-tag rm ${packageName} untagged --otp=${otp}` + ) + ); + } else { + await exec(`npm dist-tag rm ${packageName} untagged`); + console.log( + theme.command(` npm dist-tag rm ${packageName} untagged`) + ); + } } - console.log( - theme.command(` npm dist-tag rm ${packageName} untagged --otp=${otp}`) - ); } } }; diff --git a/scripts/release/publish.js b/scripts/release/publish.js index f0d2fd76228aa..e1e0e11cbde67 100755 --- a/scripts/release/publish.js +++ b/scripts/release/publish.js @@ -50,28 +50,35 @@ const run = async () => { await validateSkipPackages(params); await checkNPMPermissions(params); - clear(); - let otp = await promptForOTP(params); const packageNames = params.packages; - for (let i = 0; i < packageNames.length; ) { - const packageName = packageNames[i]; - try { - await publishToNPM(params, packageName, otp); - i++; - } catch (error) { - console.error(error.message); - console.log(); - console.log( - theme.error`Publish failed. Enter a fresh otp code to retry.` - ); - otp = await promptForOTP(params); - // Try publishing package again - continue; + + if (params.ci) { + for (let i = 0; i < packageNames.length; i++) { + const packageName = packageNames[i]; + await publishToNPM(params, packageName, null); } + } else { + clear(); + let otp = await promptForOTP(params); + for (let i = 0; i < packageNames.length; ) { + const packageName = packageNames[i]; + try { + await publishToNPM(params, packageName, otp); + i++; + } catch (error) { + console.error(error.message); + console.log(); + console.log( + theme.error`Publish failed. Enter a fresh otp code to retry.` + ); + otp = await promptForOTP(params); + // Try publishing package again + continue; + } + } + await updateStableVersionNumbers(params); + await printFollowUpInstructions(params); } - - await updateStableVersionNumbers(params); - await printFollowUpInstructions(params); } catch (error) { handleError(error); }