Skip to content

Commit

Permalink
Release script prompts for NPM 2FA code (#12908)
Browse files Browse the repository at this point in the history
* Release script prompts for NPM 2fa code
  • Loading branch information
bvaughn authored May 29, 2018
1 parent 83f76e4 commit 001f9ef
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
1 change: 0 additions & 1 deletion scripts/release/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const run = async () => {
try {
const params = parseBuildParameters();
params.packages = getPublicPackages();

await checkEnvironmentVariables(params);
await validateVersion(params);
await checkUncommittedChanges(params);
Expand Down
1 change: 1 addition & 0 deletions scripts/release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"figlet": "^1.2.0",
"fs-extra": "^4.0.2",
"log-update": "^2.1.0",
"prompt-promise": "^1.0.3",
"request-promise-json": "^1.0.4",
"semver": "^5.4.1"
}
Expand Down
15 changes: 15 additions & 0 deletions scripts/release/publish-commands/get-npm-two-factor-auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node

'use strict';

const chalk = require('chalk');
const logUpdate = require('log-update');
const prompt = require('prompt-promise');

module.exports = async params => {
logUpdate(chalk`{green ✓} Npm two-factor auth code {gray (or blank)}: `);
const otp = await prompt('');
prompt.done();
logUpdate.clear();
return otp.trim() || null;
};
11 changes: 9 additions & 2 deletions scripts/release/publish-commands/publish-to-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {join} = require('path');
const semver = require('semver');
const {execRead, execUnlessDry, logPromise} = require('../utils');

const push = async ({cwd, dry, packages, version, tag}) => {
const push = async ({cwd, dry, otp, packages, version, tag}) => {
const errors = [];
const isPrerelease = semver.prerelease(version);
if (tag === undefined) {
Expand All @@ -19,10 +19,17 @@ const push = async ({cwd, dry, packages, version, tag}) => {
throw new Error('The tag `latest` can only be used for stable versions.');
}

// Pass two factor auth code if provided:
// https://docs.npmjs.com/getting-started/using-two-factor-authentication
const twoFactorAuth = otp != null ? `--otp ${otp}` : '';

const publishProject = async project => {
try {
const path = join(cwd, 'build', 'node_modules', project);
await execUnlessDry(`npm publish --tag ${tag}`, {cwd: path, dry});
await execUnlessDry(`npm publish --tag ${tag} ${twoFactorAuth}`, {
cwd: path,
dry,
});

const packagePath = join(
cwd,
Expand Down
2 changes: 2 additions & 0 deletions scripts/release/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {getPublicPackages} = require('./utils');

const checkBuildStatus = require('./publish-commands/check-build-status');
const commitChangelog = require('./publish-commands/commit-changelog');
const getNpmTwoFactorAuth = require('./publish-commands/get-npm-two-factor-auth');
const parsePublishParams = require('./publish-commands/parse-publish-params');
const printPostPublishSummary = require('./publish-commands/print-post-publish-summary');
const pushGitRemote = require('./publish-commands/push-git-remote');
Expand All @@ -22,6 +23,7 @@ const run = async () => {
await checkBuildStatus(params);
await commitChangelog(params);
await pushGitRemote(params);
params.otp = await getNpmTwoFactorAuth(params);
await publishToNpm(params);
await printPostPublishSummary(params);
} catch (error) {
Expand Down
21 changes: 21 additions & 0 deletions scripts/release/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ jsprim@^1.2.2:
json-schema "0.2.3"
verror "1.10.0"

keypress@~0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/keypress/-/keypress-0.2.1.tgz#1e80454250018dbad4c3fe94497d6e67b6269c77"

lodash.padend@^4.6.1:
version "4.6.1"
resolved "https://registry.yarnpkg.com/lodash.padend/-/lodash.padend-4.6.1.tgz#53ccba047d06e158d311f45da625f4e49e6f166e"
Expand Down Expand Up @@ -368,6 +372,16 @@ mimic-fn@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18"

native-or-another@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/native-or-another/-/native-or-another-2.0.0.tgz#17a567f92beea9cd71acff96a7681a735eca3bff"
dependencies:
native-or-bluebird "^1.1.2"

native-or-bluebird@^1.1.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/native-or-bluebird/-/native-or-bluebird-1.2.0.tgz#39c47bfd7825d1fb9ffad32210ae25daadf101c9"

node-version@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/node-version/-/node-version-1.1.0.tgz#f437d7ba407e65e2c4eaef8887b1718ba523d4f0"
Expand All @@ -390,6 +404,13 @@ promise-polyfill@^6.0.1:
version "6.0.2"
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-6.0.2.tgz#d9c86d3dc4dc2df9016e88946defd69b49b41162"

prompt-promise@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/prompt-promise/-/prompt-promise-1.0.3.tgz#78ce4fcb9a14a108c49174f2d808c440d1bde265"
dependencies:
keypress "~0.2.1"
native-or-another "~2.0.0"

pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
Expand Down

0 comments on commit 001f9ef

Please sign in to comment.