Retry with fresh otp if publish fails (#20582)

Currently, if publishing a package fails, the script crashes, and the
user must start it again from the beginning. Usually this happens
because the one-time password has timed out.

With this change, the user will be prompted for a fresh otp, and the
script will resume publishing.
This commit is contained in:
Andrew Clark 2021-01-13 13:54:56 -06:00 committed by GitHub
parent e6ed2bcf42
commit fc07b070a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 2 deletions

View File

@ -48,8 +48,22 @@ const run = async () => {
await confirmVersionAndTags(params);
await validateSkipPackages(params);
await checkNPMPermissions(params);
const otp = await promptForOTP(params);
await publishToNPM(params, otp);
while (true) {
try {
const otp = await promptForOTP(params);
await publishToNPM(params, otp);
break;
} catch (error) {
console.error(error.message);
console.log();
console.log(
theme.error`Publish failed. Enter a fresh otp code to retry.`
);
continue;
}
}
await updateStableVersionNumbers(params);
await printFollowUpInstructions(params);
} catch (error) {