Skip to content

build(release-script): npm logout after publishing #15170

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

Merged
merged 1 commit into from
Feb 12, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions tools/release/npm/npm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function isNpmAuthenticated(): boolean {
}

/** Runs "npm login" interactively by piping stdin/stderr/stdout to the current tty. */
export function runInteractiveNpmLogin(): boolean {
export function npmLoginInteractive(): boolean {
return spawnSync('npm', ['login'], {
stdio: 'inherit',
shell: true,
Expand All @@ -29,7 +29,7 @@ export function runInteractiveNpmLogin(): boolean {
}

/** Runs NPM publish within a specified directory */
export function runNpmPublish(packagePath: string, distTag: string): string | null {
export function npmPublish(packagePath: string, distTag: string): string | null {
const result = spawnSync('npm', ['publish', '--access', 'public', '--tag', distTag], {
cwd: packagePath,
shell: true,
Expand All @@ -42,3 +42,11 @@ export function runNpmPublish(packagePath: string, distTag: string): string | nu
return result.stderr.toString();
}
}

/** Log out of npm. */
export function npmLogout(): boolean {
return spawnSync('npm', ['logout'], {
shell: true,
env: npmClientEnvironment,
}).status === 0;
}
17 changes: 14 additions & 3 deletions tools/release/publish-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import {checkReleaseOutput} from './check-release-output';
import {extractReleaseNotes} from './extract-release-notes';
import {GitClient} from './git/git-client';
import {getGithubNewReleaseUrl} from './git/github-urls';
import {isNpmAuthenticated, runInteractiveNpmLogin, runNpmPublish} from './npm/npm-client';
import {
isNpmAuthenticated,
npmLogout,
npmLoginInteractive,
npmPublish,
} from './npm/npm-client';
import {promptForNpmDistTag} from './prompt/npm-dist-tag-prompt';
import {promptForUpstreamRemote} from './prompt/upstream-remote-prompt';
import {releasePackages} from './release-output/release-packages';
Expand Down Expand Up @@ -125,6 +130,12 @@ class PublishReleaseTask extends BaseReleaseTask {

console.log();
console.info(green(bold(` ✓ Published all packages successfully`)));

// Always log out of npm after releasing to prevent unintentional changes to
// any packages.
npmLogout();
console.info(green(bold(` ✓ Logged out of npm`)));

console.info(yellow(` ⚠ Please draft a new release of the version on Github.`));
console.info(yellow(` ${newReleaseUrl}`));
}
Expand Down Expand Up @@ -194,7 +205,7 @@ class PublishReleaseTask extends BaseReleaseTask {
console.log(yellow(` ⚠ NPM is currently not authenticated. Running "npm login"..`));

for (let i = 0; i < MAX_NPM_LOGIN_TRIES; i++) {
if (runInteractiveNpmLogin()) {
if (npmLoginInteractive()) {
// In case the user was able to login properly, we want to exit the loop as we
// don't need to ask for authentication again.
break;
Expand All @@ -217,7 +228,7 @@ class PublishReleaseTask extends BaseReleaseTask {
private publishPackageToNpm(packageName: string, npmDistTag: string) {
console.info(green(` ⭮ Publishing "${packageName}"..`));

const errorOutput = runNpmPublish(join(this.releaseOutputPath, packageName), npmDistTag);
const errorOutput = npmPublish(join(this.releaseOutputPath, packageName), npmDistTag);

if (errorOutput) {
console.error(red(` ✘ An error occurred while publishing "${packageName}".`));
Expand Down