Skip to content
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

Fixes publish script to require NPM tag, use Wombat registry, and correctly read check flags #18323

Merged
merged 2 commits into from
Jul 23, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/registries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/** URL to Wombat NPM registry proxy. */
export const wombat = 'https://wombat-dressing-room.appspot.com';
59 changes: 46 additions & 13 deletions scripts/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import { logging, tags } from '@angular-devkit/core';
import { spawnSync } from 'child_process';
import * as semver from 'semver';
import { packages } from '../lib/packages';
import { wombat } from '../lib/registries';
import build from './build';


export interface PublishArgs {
tag?: string;
tagCheck?: boolean;
branchCheck?: boolean;
versionCheck?: boolean;
registry?: string;
}


function _exec(command: string, args: string[], opts: { cwd?: string }, logger: logging.Logger) {
if (process.platform.startsWith('win')) {
args.unshift('/c', command);
Expand All @@ -42,6 +42,24 @@ function _exec(command: string, args: string[], opts: { cwd?: string }, logger:
}
}

/** Returns whether or not the given tag is valid to be used. */
function _tagCheck(tag: string) {
if (tag === 'latest') {
return; // Valid
}
if (tag === 'next') {
return; // Valid
}
if (/v\d+-lts/.test(tag)) {
return; // Valid
}

throw new Error(tags.oneLine`
--tag should be "latest", "next", or "vX-lts". Use \`--no-tagCheck false\`
to skip this check if necessary.
`);
}


function _branchCheck(args: PublishArgs, logger: logging.Logger) {
logger.info('Checking branch...');
Expand All @@ -52,7 +70,8 @@ function _branchCheck(args: PublishArgs, logger: logging.Logger) {
case 'master':
if (args.tag !== 'next') {
throw new Error(tags.oneLine`
Releasing from master requires a next tag. Use --branchCheck=false to skip this check.
Releasing from master requires a next tag. Use --no-branchCheck to
skip this check.
`);
}
}
Expand All @@ -75,7 +94,7 @@ function _versionCheck(args: PublishArgs, logger: logging.Logger) {
if (betaOrRc && args.tag !== 'next') {
throw new Error(tags.oneLine`
Releasing version ${JSON.stringify(version)} requires a next tag.
Use --versionCheck=false to skip this check.
Use --no-versionCheck to skip this check.
`);
}

Expand All @@ -90,13 +109,33 @@ function _versionCheck(args: PublishArgs, logger: logging.Logger) {
}

export default async function (args: PublishArgs, logger: logging.Logger) {
if (args.branchCheck === undefined || args.branchCheck === true) {
const { tag } = args;
if (!tag) {
// NPM requires that all releases have a tag associated, defaulting to
// `latest`, so there is no way to allow a publish without a tag.
// https://github.com/npm/npm/issues/10625#issuecomment-162106553
throw new Error('--tag is required.');
}

const tagCheck = args.tagCheck !== undefined ? args.tagCheck : true;
if (tagCheck) {
_tagCheck(tag);
}

const branchCheck = args.branchCheck !== undefined ? args.branchCheck : true;
if (branchCheck) {
_branchCheck(args, logger);
}
if (args.versionCheck === undefined || args.versionCheck === true) {

const versionCheck =
args.versionCheck !== undefined ? args.versionCheck : true;
if (versionCheck) {
_versionCheck(args, logger);
}

// If no registry is provided, the wombat proxy should be used.
const registry = args.registry !== undefined ? args.registry : wombat;

logger.info('Building...');
await build({}, logger.createChild('build'));

Expand All @@ -112,13 +151,7 @@ export default async function (args: PublishArgs, logger: logging.Logger) {
.then(() => {
logger.info(name);

const publishArgs = ['publish'];
if (args.tag) {
publishArgs.push('--tag', args.tag);
}
if (args.registry) {
publishArgs.push('--registry', args.registry);
}
const publishArgs = [ 'publish', '--tag', tag, '--registry', registry ];

return _exec('npm', publishArgs, {
cwd: pkg.dist,
Expand Down
6 changes: 4 additions & 2 deletions tests/legacy-cli/e2e/setup/010-local-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ export default async function() {
'admin',
'--',
'publish',
'--versionCheck=false',
'--branchCheck=false',
'--no-versionCheck',
'--no-branchCheck',
'--registry=http://localhost:4873',
];

const pre = prerelease(packages['@angular/cli'].version);
if (pre && pre.length > 0) {
publishArgs.push('--tag', 'next');
} else {
publishArgs.push('--tag', 'latest');
}

await npm(...publishArgs);
Expand Down