Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --ci option to publish script #20727

Merged
merged 1 commit into from Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions scripts/release/publish-commands/confirm-version-and-tags.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
};
Expand Down
8 changes: 7 additions & 1 deletion scripts/release/publish-commands/parse-params.js
Expand Up @@ -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 = () => {
Expand All @@ -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;
}
Expand Down
72 changes: 52 additions & 20 deletions scripts/release/publish-commands/publish-to-npm.js
Expand Up @@ -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'));

Expand All @@ -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}`)
);
}
}
};
Expand Down
45 changes: 26 additions & 19 deletions scripts/release/publish.js
Expand Up @@ -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);
}
Expand Down