From bd6f047f80e2d194edd762ccdb2fff5540d53ef7 Mon Sep 17 00:00:00 2001 From: Oleg Pimenov Date: Wed, 13 Feb 2019 22:58:19 +0300 Subject: [PATCH] fix(ci): release script --- commitlint.config.js | 1 + tools/release/npm/npm-client.ts | 12 ++++++++++-- tools/release/publish-release.ts | 12 +++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/commitlint.config.js b/commitlint.config.js index 8d291c91f..1598e8e3d 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -9,6 +9,7 @@ module.exports = { 'badge', 'build', 'button', + 'ci', 'cdk', 'card', 'checkbox', diff --git a/tools/release/npm/npm-client.ts b/tools/release/npm/npm-client.ts index a10c7d586..10f9535bd 100644 --- a/tools/release/npm/npm-client.ts +++ b/tools/release/npm/npm-client.ts @@ -21,7 +21,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, @@ -30,7 +30,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, @@ -43,3 +43,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; +} diff --git a/tools/release/publish-release.ts b/tools/release/publish-release.ts index ebfaff2c5..9b0429f62 100644 --- a/tools/release/publish-release.ts +++ b/tools/release/publish-release.ts @@ -9,7 +9,7 @@ import { BaseReleaseTask } from './base-release-task'; 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 { checkReleasePackage } from './release-output/check-packages'; @@ -129,6 +129,12 @@ class PublishReleaseTask extends BaseReleaseTask { console.log(); console.info(chalk.green(chalk.bold(` ✓ Published all packages successfully`))); + + // Always log out of npm after releasing to prevent unintentional changes to + // any packages. + npmLogout(); + console.info(chalk.green(chalk.bold(` ✓ Logged out of npm`))); + console.info(chalk.yellow(` ⚠ Please draft a new release of the version on Github.`)); console.info(chalk.yellow(` ${newReleaseUrl}`)); } @@ -217,7 +223,7 @@ class PublishReleaseTask extends BaseReleaseTask { console.log(chalk.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; @@ -240,7 +246,7 @@ class PublishReleaseTask extends BaseReleaseTask { private publishPackageToNpm(packageName: string, npmDistTag: string) { console.info(chalk.green(` ⭮ Publishing "${packageName}"..`)); - const errorOutput = runNpmPublish(join(this.releaseOutputPath, packageName), npmDistTag); + const errorOutput = npmPublish(join(this.releaseOutputPath, packageName), npmDistTag); if (errorOutput) { console.error(chalk.red(` ✘ An error occurred while publishing "${packageName}".`));