Skip to content

Commit

Permalink
fix(ci): release script
Browse files Browse the repository at this point in the history
  • Loading branch information
pimenovoleg committed Feb 13, 2019
1 parent bce62ac commit bd6f047
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
'badge',
'build',
'button',
'ci',
'cdk',
'card',
'checkbox',
Expand Down
12 changes: 10 additions & 2 deletions tools/release/npm/npm-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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;
}
12 changes: 9 additions & 3 deletions tools/release/publish-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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}`));
}
Expand Down Expand Up @@ -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;
Expand All @@ -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}".`));
Expand Down

0 comments on commit bd6f047

Please sign in to comment.